Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit 04b9f59

Browse files
Add SentenceSimilarity Utilities
* FindBestSimilarityScoreValue * FindBestSimilarityScoreIndex
1 parent ca51849 commit 04b9f59

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace HuggingFace.API {
2+
public class SentenceSimilarity {
3+
/// <summary>
4+
/// Find the best similiarity score
5+
/// </summary>
6+
/// <param name="similarityScores">An array of similarity scores between each context phrase and the sentence.</param>
7+
/// <returns>The index of the maximum similarity score.</returns>
8+
public float FindBestSimilarityScoreValue(float[] similarityScores)
9+
{
10+
float maxScore = scores.Max();
11+
return maxScore
12+
}
13+
14+
/// <summary>
15+
/// Finds the index of the maximum similarity score in the given array of similarity scores.
16+
/// </summary>
17+
/// <param name="similarityScores">An array of similarity scores representing the similarity between each context phrase and the sentence.</param>
18+
/// <returns>The index of the maximum similarity score in the array.</returns>
19+
public float FindBestSimilarityScoreIndex(float[] similarityScores)
20+
{
21+
float maxScore = FindBestSimilarityScoreValue(similarityScores)
22+
float maxScore = similarityScores.ToList().IndexOf(maxScore);
23+
24+
return maxScore
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)