Downloads · 30 days
67
5% of all-time downloads
qixun/bert-chinese-poem
bert-chinese-poem is a fill-mask model from qixun. Use it when you need the model to fill a missing word. It is set up for transformers. The card lists the license as gpl-3.0.
适用于中国古典诗歌的bert模型,在搜韵开源的语料上以16的batchsize训练了110万步左右,loss稳定低于1。
Downloads · 30 days
67
5% of all-time downloads
All-time downloads
1.5K
Public
Parameters
96M
384 MB on disk
Likes
3
Public
Click a slice to open those files.
.safetensors384 MB · 100%
From the Hugging Face model README
适用于中国古典诗歌的bert模型,在搜韵开源的语料上以16的batch_size训练了110万步左右,loss稳定低于1。
使用方法如下:
from transformers import BertTokenizer, BertForMaskedLM
import torch
# 加载分词器
tokenizer = BertTokenizer.from_pretrained("qixun/bert-chinese-poem")
# 加载模型
model = BertForMaskedLM.from_pretrained("qixun/bert-chinese-poem")
# 输入文本
text = "宵凉百念集孤[MASK],暗雨鸣廊睡未能。生计坐怜秋一叶,归程冥想浪千层。寒心国事浑难料,堆眼官资信可憎。此去梦中应不忘,顺承门内近觚棱。"
# 分词
inputs = tokenizer(text, return_tensors="pt")
# 模型推理
with torch.no_grad():
outputs = model(**inputs)
# 获取[MASK]标记的位置
mask_token_index = torch.where(inputs["input_ids"] == tokenizer.mask_token_id)[1]
# 获取预测的token_id
predicted_token_id = outputs.logits[0, mask_token_index].argmax(axis=-1).item()
# 获取预测的词
predicted_token = tokenizer.decode([predicted_token_id])
print(f"预测的词是:{predicted_token}")