Update README.md
Browse files
README.md
CHANGED
@@ -57,6 +57,7 @@ tokenizer = AutoTokenizer.from_pretrained('IDEA-CCNL/Erlangshen-SimCSE-110M-Chin
|
|
57 |
### 使用示例 Usage Examples
|
58 |
|
59 |
```python
|
|
|
60 |
from sklearn.metrics.pairwise import cosine_similarity
|
61 |
|
62 |
texta = '今天天气真不错,我们去散步吧!'
|
@@ -71,8 +72,10 @@ outputs_b = model(**inputs_b ,output_hidden_states=True)
|
|
71 |
textb_embedding = outputs_b.hidden_states[-1][:,0,:].squeeze()
|
72 |
|
73 |
# if you use cuda, the text_embedding should be textb_embedding.cpu().numpy()
|
74 |
-
|
75 |
-
|
|
|
|
|
76 |
```
|
77 |
|
78 |
## 引用 Citation
|
|
|
57 |
### 使用示例 Usage Examples
|
58 |
|
59 |
```python
|
60 |
+
import torch
|
61 |
from sklearn.metrics.pairwise import cosine_similarity
|
62 |
|
63 |
texta = '今天天气真不错,我们去散步吧!'
|
|
|
72 |
textb_embedding = outputs_b.hidden_states[-1][:,0,:].squeeze()
|
73 |
|
74 |
# if you use cuda, the text_embedding should be textb_embedding.cpu().numpy()
|
75 |
+
# 或者用torch.no_grad():
|
76 |
+
with torch.no_grad():
|
77 |
+
silimarity_soce = cosine_similarity(texta_embedding.reshape(1,-1),textb_embedding .reshape(1,-1))[0][0]
|
78 |
+
print(silimarity_soce)
|
79 |
```
|
80 |
|
81 |
## 引用 Citation
|