Skip to content

Commit

Permalink
Merge pull request #209 from thunlp/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanchao-Qi authored Jun 3, 2021
2 parents 88ed847 + 078d9ac commit 57b34ae
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions OpenAttack/metric/sim_cos.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from sentence_transformers import SentenceTransformer, util

class Sim_Cos():
def __init__(self):
from sentence_transformers import SentenceTransformer
from ..data_manager import DataManager
self.model = SentenceTransformer(DataManager.load("AttackAssist.SentenceTransformer"), device='cuda')
def __call__(self, sen1, sen2):

from sentence_transformers import util
emb1,emb2 = self.model.encode([sen1,sen2],show_progress_bar=False)
cos_sim = util.pytorch_cos_sim(emb1, emb2)
return cos_sim.cpu().numpy()[0][0]

0 comments on commit 57b34ae

Please sign in to comment.