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

Normalizing the Final Similarity Score to reduce it between 0 and 1 #374

Open
AshutoshSabic opened this issue Oct 25, 2024 · 0 comments
Open

Comments

@AshutoshSabic
Copy link

Objective: Bring the final similarity score between 0 and 1 so that I can set a threshold such that 'score'>=threshold means the document is relevant.

As per my understanding, the final score that we get is the summation of the maximum cosine similarity scores for each query token against the document tokens. So, dividing the final score by number of query tokens should give a normalized score (b/w 0 and 1).

But that's not correct. After dividing the final score by number of query tokens, I am getting >1 score for some queries.

This is how I am loading the tokenizer to get the number of tokens from query:
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("path to model directory")

from ragatouille import RAGPretrainedModel
RAG = RAGPretrainedModel.from_pretrained("path to model directory")

index=RAG.from_index("path to index")

text="query"
normalized_score=index.search(text)[0]['score']/len(tokenizer.tokenize(text)

normalized_score is >1 for some of the queries.

I would greatly appreciate any help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant