Update README.md
Browse files
README.md
CHANGED
@@ -6,3 +6,24 @@ library_name: transformers
|
|
6 |
base_model:
|
7 |
- Jihuai/bert-ancient-chinese
|
8 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
base_model:
|
7 |
- Jihuai/bert-ancient-chinese
|
8 |
---
|
9 |
+
Use the model
|
10 |
+
```python
|
11 |
+
|
12 |
+
from transformers import BertTokenizer, BertForMaskedLM
|
13 |
+
import torch
|
14 |
+
|
15 |
+
# Load the tokenizer
|
16 |
+
tokenizer = BertTokenizer.from_pretrained('btqkhai/SinoNomBERT')
|
17 |
+
# Load the model
|
18 |
+
model = BertForMaskedLM.from_pretrained('btqkhai/SinoNomBERT')
|
19 |
+
|
20 |
+
text = '大 [MASK] 百 官 其 𢮿 花 供 饌 皆 用 新 禮'
|
21 |
+
|
22 |
+
inputs = tokenizer(text, return_tensors="pt", add_special_tokens=True)
|
23 |
+
mask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]
|
24 |
+
# Ground Truth: 宴
|
25 |
+
logits = model(**inputs).logits
|
26 |
+
mask_token_logits = logits[0, mask_token_index, :]
|
27 |
+
|
28 |
+
print("Predicted word:", tokenizer.decode(mask_token_logits[0].argmax()))
|
29 |
+
```
|