TJKlein commited on
Commit
71f69a9
·
1 Parent(s): d1858c9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +12 -0
README.md CHANGED
@@ -14,6 +14,7 @@ The **miCSE** language model is trained for sentence similarity computation. Tra
14
 
15
  ```shell
16
  from transformers import AutoTokenizer, AutoModel
 
17
 
18
  tokenizer = AutoTokenizer.from_pretrained("sap-ai-research/miCSE")
19
 
@@ -43,6 +44,17 @@ outputs = model(**batch, output_hidden_states=True, return_dict=True)
43
 
44
  embeddings = outputs.last_hidden_state[:,0]
45
 
 
 
 
 
 
 
 
 
 
 
 
46
  ```
47
 
48
 
 
14
 
15
  ```shell
16
  from transformers import AutoTokenizer, AutoModel
17
+ import torch.nn as nn
18
 
19
  tokenizer = AutoTokenizer.from_pretrained("sap-ai-research/miCSE")
20
 
 
44
 
45
  embeddings = outputs.last_hidden_state[:,0]
46
 
47
+ # Define similarity metric, e.g., cosine similarity
48
+
49
+ sim = nn.CosineSimilarity(dim=-1)
50
+
51
+ # Compute similarity between the **first** and the **second** sentence
52
+
53
+ cos_sim = sim(embeddings.unsqueeze(1),
54
+ embeddings.unsqueeze(0))
55
+
56
+ print(f"Distance: {cos_sim[0,1].detach().item()}")
57
+
58
  ```
59
 
60