Machine learning model training with adversarial learning and triplet loss regularization
A method, computer system, and a computer program product for training a machine learning model are provided. A first set of labelled training data from a source domain is obtained. A second set of labelled training data from a target domain is obtained. A number of labelled samples of the first set is greater than a number of labelled samples of the second set. The first machine learning model is trained with the first set and the second set and with a discriminator so that the discriminator is unable to distinguish whether a sample is from the first set or from the second set. The first machine learning model is trained with triplet loss regularization using the first set and the second set.
1 . A method comprising:
obtaining a first set of labelled training data from a source domain;
obtaining a second set of labelled training data from a target domain, a number of labelled samples of the first set being greater than a number of labelled samples of the second set;
training a first machine learning model with the first set and the second set and with a discriminator so that the discriminator is unable to distinguish whether a sample, represented by an embedding produced via the first machine learning model in response to receiving the sample, is from the first set or from the second set;
training the first machine learning model with triplet loss regularization using the first set and the second set; and
training a classifier of the first machine learning model using classification loss from the first set and the second set;
wherein the training of the first machine learning model with the discriminator and with the triplet loss regularization occurs iteratively in multiple epochs based on refining of a sample pool of the first set and the second set so that a first epoch of the multiple epochs is performed with a first version of the sample pool and a second epoch of the multiple epochs is performed with a second version of the sample pool, the second version being modified compared to the first version, wherein the sample pool comprises triplet sets of a respective anchor sample, a respective positive sample, and a respective negative sample, and the refining occurs by evaluating relevancy of the triplet sets in a latent common embedding space between the first set and the second set.
2 . The method of claim 1 , wherein the respective anchor sample and the respective positive sample together form a respective matching pair for a respective one of the triplet sets, wherein the respective anchor sample and the respective negative sample together form a respective non-matching pair for the respective one of the triplet sets, and
wherein the refining further comprises comparing a first distance between the matching pair to a second distance between the non-matching pair to determine a triplet function value.
3 . The method of claim 2 , wherein the refining further comprises discarding a first triplet of the triplet sets for the iterative training in response to the triplet function value for the first triplet not exceeding a threshold value.
4 . The method of claim 1 , further comprising:
updating a first generator encoder of the first machine learning model based on:
domain loss from the training of the discriminator,
distance loss from the training with the triplet loss regularization, and
the classification loss;
wherein the trained first machine learning model for use in an inference phase comprises the updated first generator encoder and the trained classifier.
5 . The method of claim 4 , further comprising performing classification with the trained first machine learning model via:
inputting a new sample into the updated first generator encoder so that the updated first generator encoder generates an embedding in an embedding space and
inputting the embedding into the trained classifier so that the trained classifier produces a class prediction.
6 . The method of claim 1 , wherein a first generator encoder of the first machine learning model is updated based on:
domain loss from the training with the discriminator,
distance loss from the training with the triplet loss regularization, and
the classification loss.
7 . The method of claim 6 , further comprising updating a second generator encoder based on:
the domain loss from the training with the discriminator, and
the classification loss;
wherein the first generator encoder and the second generator encoder are used for the training with the discriminator and for the training of the classifier.
8 . The method of claim 7 , further comprising:
comparing at least one of a shape and a dimension of the labelled training data of the second set to a corresponding at least one of a shape and a dimension of the labelled training data of the first set; and
initializing weights of the first generator encoder based on the comparing.
9 . The method of claim 8 , wherein via the comparison the at least one of the shape and the dimension of the labelled training data of the second set passes a similarity threshold with the corresponding at least one of a shape and a dimension of the labelled training data of the first set; and
wherein the initialization comprises weights of the second generator encoder being implemented as the weights for the first generator encoder.
10 . The method of claim 8 , wherein via the comparison the at least one of the shape and the dimension of the labelled training data of the second set fails a similarity threshold with the corresponding at least one of a shape and a dimension of the labelled training data of the first set; and
wherein the initialization comprises randomly initializing the weights of the first generator encoder.
11 . The method of claim 1 , wherein the triplet loss regularization comprises penalization in response to samples from the second set being mapped at a distance greater than a distance threshold from samples from the first set and from the second set having same class labels as the samples from the second set.
12 . The method of claim 1 , wherein the triplet loss regularization comprises penalization in response to samples from the second set being mapped at a distance less than a distance threshold from samples from the first set and from the second set having different class labels as the samples from the second set.
13 . The method of claim 1 , wherein the triplet loss regularization comprises:
penalization in response to samples from the second set being mapped at a first distance greater than a first distance threshold from samples from the first set and from the second set having same class labels as the samples from the second set and
penalization in response to samples from the second set being mapped at a second distance less than a second distance threshold from samples from the first set and from the second set having different class labels as the samples from the second set.
14 . The method of claim 1 , wherein the source domain is of a first type and the target domain is of a second type different than the first type.
15 . The method of claim 1 , further comprising re-calculating distances for all triplet groups of the sample pool in response to a change amount of the sample pool exceeding or equaling a pre-determined threshold, wherein the change amount refers to a percentage of overall samples that are discarded from the sample pool due to being less relevant to the target domain, and wherein the re-calculating of the distances adjusts a shape of embeddings in the latent common embedding space.
16 . The method of claim 1 , wherein a first group of the triplet sets comprises respective anchor samples from the second set and respective positive or negative samples from the first set.
17 . The method of claim 16 , wherein a second group of the triplet sets comprises respective anchor samples from the second set and respective additional samples from the second set, and wherein the first group includes more of the triplet sets than the second group does.
18 . The method of claim 1 , wherein a first group of the triplet sets comprises respective anchor samples from the second set and respective positive and negative samples from the first set.
19 . A computer system comprising:
one or more processors,
one or more computer-readable storage media, and
program instructions stored on at least one of the one or more computer-readable storage media for execution by at least one of the one or more processors to cause the computer system to:
obtain a first set of labelled training data from a source domain;
obtain a second set of labelled training data from a target domain, a number of labelled samples of the first set being greater than a number of labelled samples of the second set;
train a first machine learning model with the first set and the second set and with a discriminator so that the discriminator is unable to distinguish whether a sample, represented by an embedding produced via the first machine learning model in response to receiving the sample, is from the first set or from the second set;
train the first machine learning model with triplet loss regularization using the first set and the second set; and
train a classifier of the first machine learning model using classification loss from the first set and the second set;
wherein the training of the first machine learning model with the discriminator and with the triplet loss regularization occurs iteratively in multiple epochs based on refining of a sample pool of the first set and the second set so that a first epoch of the multiple epochs is performed with a first version of the sample pool and a second epoch of the multiple epochs is performed with a second version of the sample pool, the second version being modified compared to the first version, wherein the sample pool comprises triplet sets of a respective anchor sample, a respective positive sample, and a respective negative sample, and the refining occurs by evaluating relevancy of the triplet sets in a latent common embedding space between the first set and the second set.
20 . A computer program product comprising:
a computer-readable storage medium; and
program instructions stored on the computer-readable storage medium, wherein the program instructions are executable by a processor to cause the processor to:
obtain a first set of labelled training data from a source domain;
obtain a second set of labelled training data from a target domain, a number of labelled samples of the first set being greater than a number of labelled samples of the second set;
train a first machine learning model with the first set and the second set and with a discriminator so that the discriminator is unable to distinguish whether a sample, represented by an embedding produced via the first machine learning model in response to receiving the sample, is from the first set or from the second set;
train the first machine learning model with triplet loss regularization using the first set and the second set; and
training a classifier of the first machine learning model using classification loss from the first set and the second set;
wherein the training of the first machine learning model with the discriminator and with the triplet loss regularization occurs iteratively in multiple epochs based on refining of a sample pool of the first set and the second set so that a first epoch of the multiple epochs is performed with a first version of the sample pool and a second epoch of the multiple epochs is performed with a second version of the sample pool, the second version being modified compared to the first version, wherein the sample pool comprises triplet sets of a respective anchor sample, a respective positive sample, and a respective negative sample, and the refining occurs by evaluating relevancy of the triplet sets in a latent common embedding space between the first set and the second set.