Skip to content

Commit

Permalink
create and update emnedding generater file
Browse files Browse the repository at this point in the history
  • Loading branch information
surafeldev committed Dec 14, 2024
1 parent c1803a5 commit d662228
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions relevance-scoring/embeddings/embedding_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity

# Load the pre-trained model
model = SentenceTransformer('all-MiniLM-L6-v2')

def generate_embedding(text):
"""
Generate embedding for a given text using the pre-trained model.
"""
return model.encode(text)

def calculate_similarity(embedding1, embedding2):
"""
Calculate cosine similarity between two embeddings.
"""
return cosine_similarity([embedding1], [embedding2])[0][0]

if __name__ == "__main__":
# Example texts
text1 = "a UI with red lines on the side showing a spacing issue"
text2 = "an issue with layout spacing in the UI"

# Generate embeddings
emb1 = generate_embedding(text1)
emb2 = generate_embedding(text2)

# Calculate similarity
similarity = calculate_similarity(emb1, emb2)

# Print the similarity score
print(f"Similarity: {similarity:.2f}")

0 comments on commit d662228

Please sign in to comment.