-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from thunlp/dev
- Loading branch information
Showing
1 changed file
with
3 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |