Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions prompting/rewards/web_retrieval.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
from collections import defaultdict
from functools import lru_cache
from urllib.parse import urlparse

import numpy as np
Expand Down Expand Up @@ -83,6 +84,7 @@ class WebsiteResult(BaseModel):


class WebRetrievalRewardModel(RelevanceRewardModel):
@lru_cache(maxsize=1000)
def _cosine_similarity(self, content1: str, content2: str) -> float:
"""Calculate the cosine similarity between sentence embeddings of the reference and completions."""
reference_emb_flatten = self.embedding_model.encode(content1, to_numpy=True).flatten()
Expand Down
Loading