ebes.losses package

Submodules

ebes.losses.base module

class ebes.losses.base.ModelLoss(*args, **kwargs)

Bases: Module

forward(preds, _)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

ebes.losses.contrastive module

class ebes.losses.contrastive.ContrastiveLoss(margin, pair_selector)

Bases: Module

Contrastive loss

“Signature verification using a siamese time delay neural network”, NIPS 1993 https://papers.nips.cc/paper/769-signature-verification-using-a-siamese-time-delay-neural-network.pdf

forward(embeddings, target)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class ebes.losses.contrastive.HardNegativePairSelector(neg_count=1)

Bases: PairSelector

Generates all possible possitive pairs given labels and

neg_count hardest negative example for each example

get_pairs(embeddings, labels)
Return type:

tuple[Tensor, Tensor]

class ebes.losses.contrastive.InfoNCELoss(temperature, pair_selector, angular_margin=0.0)

Bases: Module

InfoNCE Loss https://arxiv.org/abs/1807.03748

forward(embeddings, target)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class ebes.losses.contrastive.PairSelector

Bases: ABC

Strategy to sample positive and negative embedding pairs.

abstract get_pairs(embeddings, labels)
Return type:

tuple[Tensor, Tensor]

ebes.losses.contrastive.outer_pairwise_distance(a, b=None)
Compute pairwise_distance of Tensors

A (size(A) = n x d, where n - rows count, d - vector size) and B (size(A) = m x d, where m - rows count, d - vector size)

return matrix C (size n x m), such as

C_ij = distance(i-th row matrix A, j-th row matrix B)

if only one Tensor was given, computer pairwise distance to itself (B = A)

ebes.losses.multi_label module

class ebes.losses.multi_label.MultiLabelBinaryCrossEntropyLoss

Bases: Module

forward(logits, target)

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

ebes.losses.neural_hawkes module

class ebes.losses.neural_hawkes.NHLoss(*args, **kwargs)

Bases: Module

forward(nh_return, _)

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Module contents