Skip to content

Commit

Permalink
support voyage ai
Browse files Browse the repository at this point in the history
  • Loading branch information
lwaekfjlk committed Nov 26, 2024
1 parent 8b3569f commit 276e63b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions research_bench/eval.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import re
from typing import Dict, List

import voyageai
import nltk
import numpy as np
import voyageai
from bert_score import score
from litellm import embedding
from nltk.translate.bleu_score import SmoothingFunction, sentence_bleu
Expand Down Expand Up @@ -99,13 +99,18 @@ def compute_openai_embedding_similarity(reference: str, hypothesis: str) -> floa
except Exception as e:
print(f'Error computing embedding similarity: {e}')
return 0.0



def compute_voyageai_embedding_similarity(reference: str, hypothesis: str) -> float:
vo = voyageai.Client()
try:
response_ref = vo.embed(model='voyage-3', texts=[reference], input_type='document')
response_hyp = vo.embed(model='voyage-3', texts=[hypothesis], input_type='document')

response_ref = vo.embed(
model='voyage-3', texts=[reference], input_type='document'
)
response_hyp = vo.embed(
model='voyage-3', texts=[hypothesis], input_type='document'
)

embedding_ref = response_ref.embeddings[0]
embedding_hyp = response_hyp.embeddings[0]

Expand Down Expand Up @@ -176,6 +181,7 @@ def compute_openai_embedding_similarity_per_question(
print(f'Error computing embedding similarity per question: {e}')
return [0.0] * len(questions)


def compute_voyageai_embedding_similarity_per_question(
reference: str, hypothesis: str
) -> List[float]:
Expand Down Expand Up @@ -248,12 +254,14 @@ def compute_review_metrics(reference: str, generation: str) -> Dict[str, float]:
rouge_l = compute_rouge_l(reference, generation)
bert_score = compute_bertscore(reference, generation)
gpt_metric = compute_review_gpt_metric(reference, generation)
embedding_similarity = compute_embedding_similarity(reference, generation)
openai_sim = compute_openai_embedding_similarity(reference, generation)
voyageai_sim = compute_voyageai_embedding_similarity(reference, generation)

return {
'bleu': bleu,
'rouge_l': rouge_l,
'gpt_metric_score': gpt_metric,
'bert_score': bert_score,
'embedding_similarity': embedding_similarity,
'openai_sim': openai_sim,
'voyageai_sim': voyageai_sim,
}

0 comments on commit 276e63b

Please sign in to comment.