Skip to content

edsnlp.pipes.trainable.layers.metric

Metric [source]

Bases: Module

Metric layer, used for computing similarities between two sets of vectors. A typical use case is to compute the similarity between a set of query vectors (input embeddings) and a set of concept vectors (output embeddings).

Parameters

PARAMETER DESCRIPTION
in_features

Size of the input embeddings

TYPE: int

out_features

Size of the output embeddings

TYPE: int

num_groups

Number of groups for the output embeddings, that can be used to filter out certain concepts that are not relevant for a given query (e.g. do not compare a drug with concepts for diseases)

TYPE: int DEFAULT: 0

metric

Whether to compute the cosine similarity between the input and output embeddings or the dot product.

TYPE: Literal['cosine', 'dot'] DEFAULT: 'cosine'

rescale

Rescale the output cosine similarities by a constant factor.

TYPE: Optional[float] DEFAULT: None