iioSnail commited on
Commit
350968a
1 Parent(s): 61b75d3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +65 -0
README.md CHANGED
@@ -1,3 +1,68 @@
1
  ---
2
  license: afl-3.0
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: afl-3.0
3
+ language:
4
+ - zh
5
+ tags:
6
+ - bert
7
+ - chinesebert
8
+ - MLM
9
+ pipeline_tag: fill-mask
10
  ---
11
+
12
+ # ChineseBERT-large
13
+
14
+ 本项目是将ChineseBERT进行了加工,可供使用者直接使用HuggingFace API进行调用,无需再进行多余的代码配置。
15
+
16
+ 原论文地址:
17
+ **[ChineseBERT: Chinese Pretraining Enhanced by Glyph and Pinyin Information](https://arxiv.org/abs/2106.16038)**
18
+ *Zijun Sun, Xiaoya Li, Xiaofei Sun, Yuxian Meng, Xiang Ao, Qing He, Fei Wu and Jiwei Li*
19
+
20
+ 原项目地址:
21
+ [ChineseBERT github link](https://github.com/ShannonAI/ChineseBert)
22
+
23
+ 原模型地址:
24
+ [ShannonAI/ChineseBERT-base](https://huggingface.co/ShannonAI/ChineseBERT-base) (该模型无法直接使用HuggingFace API调用)
25
+
26
+ # 本项目使用方法
27
+
28
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/iioSnail/ChineseBert/blob/main/demo/ChineseBERT-Demo.ipynb)
29
+
30
+ 1. 安装pypinyin
31
+
32
+ ```
33
+ pip install pypinyin
34
+ ```
35
+
36
+ 2. 使用AutoClass加载tokenizer和model
37
+
38
+ ```python
39
+ from transformers import AutoTokenizer, AutoModel
40
+
41
+ tokenizer = AutoTokenizer.from_pretrained("iioSnail/ChineseBERT-large", trust_remote_code=True)
42
+ model = AutoModel.from_pretrained("iioSnail/ChineseBERT-large", trust_remote_code=True)
43
+ ```
44
+
45
+ 3. 之后与普通BERT使用方法一致
46
+
47
+ ```python
48
+ inputs = tokenizer(["我 喜 [MASK] 猫"], return_tensors='pt')
49
+ logits = model(**inputs).logits
50
+
51
+ print(tokenizer.decode(logits.argmax(-1)[0, 1:-1]))
52
+ ```
53
+
54
+ 输出:
55
+
56
+ ```
57
+ tokenizer.decode(logits.argmax(-1)[0, 1:-1])
58
+ ```
59
+
60
+ # 常见问题
61
+
62
+ 1. 网络问题,例如:`Connection Error`
63
+
64
+ 解决方案:将模型下载到本地使用。批量下载方案可参考该[博客](https://blog.csdn.net/zhaohongfei_358/article/details/126222999)
65
+
66
+ 2. 将模型下载到本地使用时出现报错:`ModuleNotFoundError: No module named 'transformers_modules.iioSnail/ChineseBERT-large'`
67
+
68
+ 解决方案:将 `iioSnail/ChineseBERT-large` 改为 `iioSnail\ChineseBERT-large`