Update README.md
Browse files
README.md
CHANGED
@@ -16,13 +16,24 @@ https://github.com/JunnYu/RoFormer_pytorch
|
|
16 |
git clone https://github.com/JunnYu/RoFormer_pytorch
|
17 |
cd RoFormer_pytorch
|
18 |
import torch
|
19 |
-
from model import
|
|
|
|
|
20 |
tokenizer = RoFormerTokenizer.from_pretrained("junnyu/roformer_chinese_base")
|
21 |
-
model =
|
22 |
inputs = tokenizer(text, return_tensors="pt")
|
23 |
with torch.no_grad():
|
24 |
-
outputs = model(**inputs).
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
```
|
27 |
## 引用
|
28 |
|
|
|
16 |
git clone https://github.com/JunnYu/RoFormer_pytorch
|
17 |
cd RoFormer_pytorch
|
18 |
import torch
|
19 |
+
from model import RoFormerForMaskedLM, RoFormerTokenizer
|
20 |
+
|
21 |
+
text = "今天[MASK]很好,我[MASK]去公园玩。"
|
22 |
tokenizer = RoFormerTokenizer.from_pretrained("junnyu/roformer_chinese_base")
|
23 |
+
model = RoFormerForMaskedLM.from_pretrained("junnyu/roformer_chinese_base")
|
24 |
inputs = tokenizer(text, return_tensors="pt")
|
25 |
with torch.no_grad():
|
26 |
+
outputs = model(**inputs).logits[0]
|
27 |
+
outputs_sentence = ""
|
28 |
+
for i, id in enumerate(tokenizer.encode(text)):
|
29 |
+
if id == tokenizer.mask_token_id:
|
30 |
+
tokens = tokenizer.convert_ids_to_tokens(outputs[i].topk(k=5)[1])
|
31 |
+
outputs_sentence += "[" + "||".join(tokens) + "]"
|
32 |
+
else:
|
33 |
+
outputs_sentence += "".join(
|
34 |
+
tokenizer.convert_ids_to_tokens([id], skip_special_tokens=True))
|
35 |
+
print(outputs_sentence)
|
36 |
+
# 今天[天气||天||心情||阳光||空气]很好,我[想||要||打算||准备||喜欢]去公园玩。
|
37 |
```
|
38 |
## 引用
|
39 |
|