Update README.md
Browse files
README.md
CHANGED
|
@@ -13,13 +13,11 @@ from transformers import BertTokenizer
|
|
| 13 |
from transformers import BertModel
|
| 14 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 15 |
|
| 16 |
-
|
| 17 |
# model
|
| 18 |
simcse_sup_path = "hellonlp/simcse-roberta-base-zh"
|
| 19 |
tokenizer = BertTokenizer.from_pretrained(simcse_sup_path)
|
| 20 |
MODEL = BertModel.from_pretrained(simcse_sup_path)
|
| 21 |
|
| 22 |
-
|
| 23 |
def get_vector_simcse(sentence):
|
| 24 |
"""
|
| 25 |
预测simcse的语义向量。
|
|
@@ -28,7 +26,6 @@ def get_vector_simcse(sentence):
|
|
| 28 |
output = MODEL(input_ids)
|
| 29 |
return output.last_hidden_state[:, 0].squeeze(0)
|
| 30 |
|
| 31 |
-
|
| 32 |
embeddings = get_vector_simcse("武汉是一个美丽的城市。")
|
| 33 |
print(embeddings.shape)
|
| 34 |
#torch.Size([768])
|
|
|
|
| 13 |
from transformers import BertModel
|
| 14 |
from sklearn.metrics.pairwise import cosine_similarity
|
| 15 |
|
|
|
|
| 16 |
# model
|
| 17 |
simcse_sup_path = "hellonlp/simcse-roberta-base-zh"
|
| 18 |
tokenizer = BertTokenizer.from_pretrained(simcse_sup_path)
|
| 19 |
MODEL = BertModel.from_pretrained(simcse_sup_path)
|
| 20 |
|
|
|
|
| 21 |
def get_vector_simcse(sentence):
|
| 22 |
"""
|
| 23 |
预测simcse的语义向量。
|
|
|
|
| 26 |
output = MODEL(input_ids)
|
| 27 |
return output.last_hidden_state[:, 0].squeeze(0)
|
| 28 |
|
|
|
|
| 29 |
embeddings = get_vector_simcse("武汉是一个美丽的城市。")
|
| 30 |
print(embeddings.shape)
|
| 31 |
#torch.Size([768])
|