finetuner.tuner.paddle.miner module#

class finetuner.tuner.paddle.miner.SiameseMiner(*args, **kwds)[source]#

Bases: finetuner.tuner.miner.base.BaseClassMiner[paddle.Tensor]

mine(labels, distances)[source]#

Generate all possible pairs.

Parameters
  • labels (Tensor) – A 1D tensor of item labels (classes)

  • distances (Tensor) – A tensor matrix of pairwise distance between each two item embeddings

Return type

Tuple[Tensor, Tensor, Tensor]

Returns

three 1D tensors, first one holding integers of first element of pair, second of the second element of pair, and third one the label (0 or 1) for the pair for each pair

class finetuner.tuner.paddle.miner.SiameseEasyHardMiner(pos_strategy='hard', neg_strategy='hard')[source]#

Bases: finetuner.tuner.miner.base.BaseClassMiner[paddle.Tensor]

Miner implements easy-hard mining for tuples in siamese training. The following strategies are available.

Pos. Strategy: - ‘hard’: Returns hardest positive (furthest) sample per anchor - ‘semihard’: Returns the hardest positive sample per anchor, such

that it is closer than the selected negative

  • ‘easy’: Returns the easiest positive sample per anchor

  • ‘all’: Returns all positive samples

Neg. Strategy: - ‘hard’: Returns hardest negative (closest) sample per anchor - ‘semihard’: Returns the hardest negative sample per anchor, such

that it is further than the selected negative

  • ‘easy’: Returns the easiest negative sample per anchor

  • ‘all’: Returns all negative samples

Not allowed: - pos. and neg. strategy cannot be set to ‘semihard’ simultaneously - When pos. or neg. strategy is set to ‘semihard’ the other cannot be

set to ‘all’

Parameters
  • pos_strategy (str) – Strategy for selecting positive samples

  • neg_strategy (str) – Strategy for selecting negative samples

mine(labels, distances)[source]#

Generate all possible pairs.

Parameters
  • labels (Tensor) – A 1D tensor of item labels (classes)

  • distances (Tensor) – A tensor matrix of pairwise distance between each two item embeddings

Return type

Tuple[Tensor, Tensor, Tensor]

Returns

three 1D tensors, first one holding integers of first element of pair, second of the second element of pair, and third one the label (0 or 1) for the pair for each pair

class finetuner.tuner.paddle.miner.TripletMiner(*args, **kwds)[source]#

Bases: finetuner.tuner.miner.base.BaseClassMiner[paddle.Tensor]

mine(labels, distances)[source]#

Generate all possible triplets.

Parameters
  • labels (Tensor) – A 1D tensor of item labels (classes)

  • distances (Tensor) – A tensor matrix of pairwise distance between each two item embeddings

Return type

Tuple[Tensor, Tensor, Tensor]

Returns

three 1D tensors, holding the anchor index, positive index and negative index of each triplet, respectively

class finetuner.tuner.paddle.miner.TripletEasyHardMiner(pos_strategy='hard', neg_strategy='hard')[source]#

Bases: finetuner.tuner.miner.base.BaseClassMiner[paddle.Tensor]

Miner implements easy-hard mining for triplets during training with triplet loss. The following strategies are available.

Pos. Strategy: - ‘hard’: Returns hardest positive (furthest) sample per anchor - ‘semihard’: Returns the hardest positive sample per anchor, such

that it is closer than the selected negative

  • ‘easy’: Returns the easiest positive sample per anchor

  • ‘all’: Returns all positive samples

Neg. Strategy: - ‘hard’: Returns hardest negative (closest) sample per anchor - ‘semihard’: Returns the hardest negative sample per anchor, such

that it is further than the selected negative

  • ‘easy’: Returns the easiest negative sample per anchor

  • ‘all’: Returns all negative samples

Not allowed: - pos. and neg. strategy cannot be set to ‘semihard’ simultaneously - When pos. or neg. strategy is set to ‘semihard’ the other cannot be

set to ‘all’

Parameters
  • pos_strategy (str) – Strategy for selecting positive samples

  • neg_strategy (str) – Strategy for selecting negative samples

mine(labels, distances)[source]#

Generate all possible triplets.

Parameters
  • labels (Tensor) – A 1D tensor of item labels (classes)

  • distances (Tensor) – A tensor matrix of pairwise distance between each two item embeddings

Return type

Tuple[Tensor, Tensor, Tensor]

Returns

three 1D tensors, holding the anchor index, positive index and negative index of each triplet, respectively

class finetuner.tuner.paddle.miner.SiameseSessionMiner(*args, **kwds)[source]#

Bases: finetuner.tuner.miner.base.BaseSessionMiner[paddle.Tensor]

mine(labels, distances)[source]#

Generate all possible pairs for each session.

Parameters
  • labels (Tuple[Tensor, Tensor]) – A tuple of 1D tensors, denotind the items’ session and match type (0 for anchor, 1 for postive match and -1 for negative match), respectively

  • distances (Tensor) – A tensor matrix of pairwise distance between each two item embeddings

Return type

Tuple[Tensor, Tensor, Tensor]

Returns

three numpy arrays, first one holding integers of first element of pair, second of the second element of pair, and third one the label (0 or 1) for the pair for each pair

class finetuner.tuner.paddle.miner.TripletSessionMiner(*args, **kwds)[source]#

Bases: finetuner.tuner.miner.base.BaseSessionMiner[paddle.Tensor]

mine(labels, distances)[source]#

Generate all possible triplets for each session.

Parameters
  • labels (Tuple[Tensor, Tensor]) – A tuple of 1D tensors, denotind the items’ session and match type (0 for anchor, 1 for postive match and -1 for negative match), respectively

  • distances (Tensor) – A tensor matrix of pairwise distance between each two item embeddings

Return type

Tuple[Tensor, Tensor, Tensor]

Returns

three numpy arrays, holding the anchor index, positive index and negative index of each triplet, respectively