fibber.metrics.similarity.glove_similarity_metric module¶
This metric computes the cosine similarity between two sentences. The sentence embedding is the sum of GloVe word embeddings.
-
class
fibber.metrics.similarity.glove_similarity_metric.
GloVeSimilarityMetric
(**kwargs)[source]¶ Bases:
fibber.metrics.metric_base.MetricBase
This metric computes the cosine similarity between two sentences.
Initialize, load Glove embeddings.
-
fibber.metrics.similarity.glove_similarity_metric.
compute_emb
(emb_table, tok_to_id, x)[source]¶ Compute the sum of word embeddings for a sentence.
- Parameters
emb_table (np.array) – the glove embedding table.
tok_to_id (dict) – a dict mapping strs to ints.
x (str) – text.
- Returns
the sum of word embedding.
- Return type
(np.array)
-
fibber.metrics.similarity.glove_similarity_metric.
compute_emb_sim
(emb_table, tok_to_id, x, y)[source]¶ Compute the cosine similarity between two sentences. The sentence embedding is the sum of word embeddings.
- Parameters
emb_table (np.array) – the glove embedding table.
tok_to_id (dict) – a dict mapping strs to ints.
x (str) – text.
y (str) – text.
- Returns
the cosine similarity.
- Return type
(float)