Similarity Functions

Available functions:

  • edit_distance_score(text1, text2): Calculate the edit distance score between two texts.

  • bleu_score(reference, candidate): Calculate the BLEU score between a reference sentence and a candidate sentence.

  • jaccard_similarity_score(text1, text2): Calculate Jaccard similarity between two texts.

  • sorensen_dice_coefficient(text1, text2): Calculate the Sorensen-Dice coefficient between two texts.

  • cosine_similarity_score(text1, text2): Calculate the cosine similarity between two texts.

  • mean_squared_error(image1, image2): Calculate the mean squared error (MSE) between two images.

  • psnr(image1, image2): Calculate the peak signal-to-noise ratio (PSNR) between two images.


Edit distance score

Calculate the edit distance score between two texts.

Parameters:
- `text1` (str): The first text.
- `text2` (str): The second text.

Returns:
- `int`: The edit distance score.

BLEU Score

Calculate the BLEU score between a reference sentence and a candidate sentence.

Parameters:
- `reference` (str): The reference sentence.
- `candidate` (str): The candidate sentence.

Returns:
- `float`: The BLEU score.

Jaccard Similarity Score

Jaccard similarity is a measure of similarity between two sets. In the context of text comparison, it calculates the similarity between the sets of words in two texts.

Parameters:
- `text1` (str): The first text for comparison.
- `text2` (str): The second text for comparison.

Returns:
- `float`: Jaccard similarity score between the two texts. The score ranges
from 0 (no similarity) to 1 (complete similarity).

Sorensen-Dice Coefficient

The Sorensen-Dice coefficient is a statistic used for comparing the similarity of two samples.

Parameters:
- `text1` (str): The first text for comparison.
- `text2` (str): The second text for comparison.

Returns:
- `float`: The Sorensen-Dice coefficient between the two texts.

Cosine Similarity Score

Cosine similarity is a measure of similarity between two non-zero vectors of an inner product space that measures the cosine of the angle between them.

Parameters:
- `text1` (str): The first text for comparison.
- `text2` (str): The second text for comparison.

Returns:
- `float`: The cosine similarity score between the two texts.

Mean Squared Error

MSE is a measure of the average squared difference between the estimated values and the actual value.

Parameters:
- `image1` (PIL.Image.Image): The first image for comparison.
- `image2` (PIL.Image.Image): The second image for comparison.

Returns:
- `float`: The mean squared error between the two images.

PSNR

PSNR is the ratio between the maximum possible power of a signal and the power of corrupting noise that affects the fidelity of its representation.

Parameters:
- `image1` (PIL.Image.Image): The first image for comparison.
- `image2` (PIL.Image.Image): The second image for comparison.

Returns:
- `float`: The peak signal-to-noise ratio between the two images.

Last updated

Was this helpful?