|
--- |
|
metrics: |
|
- perplexity |
|
pipeline_tag: fill-mask |
|
library_name: transformers |
|
base_model: |
|
- Jihuai/bert-ancient-chinese |
|
--- |
|
Use the model |
|
```python |
|
|
|
from transformers import BertTokenizer, BertForMaskedLM |
|
import torch |
|
|
|
# Load the tokenizer |
|
tokenizer = BertTokenizer.from_pretrained('btqkhai/SinoNomBERT') |
|
# Load the model |
|
model = BertForMaskedLM.from_pretrained('btqkhai/SinoNomBERT') |
|
|
|
text = '大 [MASK] 百 官 其 𢮿 花 供 饌 皆 用 新 禮' |
|
|
|
inputs = tokenizer(text, return_tensors="pt") |
|
mask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1] |
|
# Ground Truth: 宴 |
|
logits = model(**inputs).logits |
|
mask_token_logits = logits[0, mask_token_index, :] |
|
|
|
print("Predicted word:", tokenizer.decode(mask_token_logits[0].argmax())) |
|
``` |