Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AGE-287] Add semantic similarity evaluator #1742

Closed
mmabrouk opened this issue Jun 2, 2024 · 0 comments
Closed

[AGE-287] Add semantic similarity evaluator #1742

mmabrouk opened this issue Jun 2, 2024 · 0 comments
Labels
enhancement New feature or request feature Medium priority Created by Linear-GitHub Sync python Pull requests that update Python code
Milestone

Comments

@mmabrouk
Copy link
Member

mmabrouk commented Jun 2, 2024

Issue from user:

I would like to add semantic similarity as an evaluator. Here is a candidate code

| from sentence_transformers import SentenceTransformer
from sentence_transformers.util import pytorch_cos_sim
def semantic_similarity(row: pandas.core.series.Series, expected: str, response_column_name: str = "response") -> float:
if len(expected) == 1:
logging.warn("Expected should be a list of strings." + "You may have passed in a single string")

doc1 = expected
doc2 = row[response_column_name]
model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
embedding_1 = model.encode(doc1, convert_to_tensor=True)
embedding_2 = model.encode(doc2, convert_to_tensor=True)

return pytorch_cos_sim(embedding_1, embedding_2).item()

Notes: We can have this implemented to use the huggingface API if the API key is not provided and run it locally in case it is not.

From SyncLinear.com | AGE-287

@mmabrouk mmabrouk added feature Medium priority Created by Linear-GitHub Sync labels Jun 2, 2024
@dosubot dosubot bot added enhancement New feature or request python Pull requests that update Python code labels Jun 2, 2024
@mmabrouk mmabrouk modified the milestones: v.52, Evaluation v2 WIP Jul 3, 2024
@mmabrouk mmabrouk modified the milestones: Evaluation v2 WIP, v.55 Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature Medium priority Created by Linear-GitHub Sync python Pull requests that update Python code
Projects
None yet
Development

No branches or pull requests

1 participant