Upload README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: zh
|
| 3 |
+
widget:
|
| 4 |
+
- text: "江苏警方通报特斯拉冲进店铺"
|
| 5 |
+
|
| 6 |
+
---
|
| 7 |
+
|
| 8 |
+
# Chinese RoBERTa-Base Model for NER
|
| 9 |
+
|
| 10 |
+
## Model description
|
| 11 |
+
|
| 12 |
+
The model is used for named entity recognition. You can download the model either from the [UER-py Modelzoo page](https://github.com/dbiir/UER-py/wiki/Modelzoo) (in UER-py format), or via HuggingFace from the link [roberta-base-finetuned-cluener2020-chinese](https://huggingface.co/uer/roberta-base-finetuned-cluener2020-chinese).
|
| 13 |
+
|
| 14 |
+
## How to use
|
| 15 |
+
|
| 16 |
+
You can use this model directly with a pipeline for token classification :
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
>>> from transformers import AutoModelForTokenClassification,AutoTokenizer,pipeline
|
| 20 |
+
>>> model = AutoModelForTokenClassification.from_pretrained('uer/roberta-base-finetuned-cluener2020-chinese')
|
| 21 |
+
>>> tokenizer = AutoTokenizer.from_pretrained('uer/roberta-base-finetuned-cluener2020-chinese')
|
| 22 |
+
>>> ner = pipeline('ner', model=model, tokenizer=tokenizer)
|
| 23 |
+
>>> ner("江苏警方通报特斯拉冲进店铺")
|
| 24 |
+
[
|
| 25 |
+
{'word': '江', 'score': 0.49153077602386475, 'entity': 'B-address', 'index': 1, 'start': 0, 'end': 1},
|
| 26 |
+
{'word': '苏', 'score': 0.6319217681884766, 'entity': 'I-address', 'index': 2, 'start': 1, 'end': 2},
|
| 27 |
+
{'word': '特', 'score': 0.5912262797355652, 'entity': 'B-company', 'index': 7, 'start': 6, 'end': 7},
|
| 28 |
+
{'word': '斯', 'score': 0.69145667552948, 'entity': 'I-company', 'index': 8, 'start': 7, 'end': 8},
|
| 29 |
+
{'word': '拉', 'score': 0.7054660320281982, 'entity': 'I-company', 'index': 9, 'start': 8, 'end': 9}
|
| 30 |
+
]
|
| 31 |
+
```
|
| 32 |
+
|
| 33 |
+
## Training data
|
| 34 |
+
|
| 35 |
+
[CLUENER2020](https://github.com/CLUEbenchmark/CLUENER2020) is used as training data. We only use the train set of the dataset.
|
| 36 |
+
|
| 37 |
+
## Training procedure
|
| 38 |
+
|
| 39 |
+
The model is fine-tuned by [UER-py](https://github.com/dbiir/UER-py/) on [Tencent Cloud](https://cloud.tencent.com/). We fine-tune five epochs with a sequence length of 512 on the basis of the pre-trained model [chinese_roberta_L-12_H-768](https://huggingface.co/uer/chinese_roberta_L-12_H-768). At the end of each epoch, the model is saved when the best performance on development set is achieved.
|
| 40 |
+
|
| 41 |
+
```
|
| 42 |
+
python3 run_ner.py --pretrained_model_path models/cluecorpussmall_roberta_base_seq512_model.bin-250000 \
|
| 43 |
+
--vocab_path models/google_zh_vocab.txt \
|
| 44 |
+
--train_path datasets/cluener2020/train.tsv \
|
| 45 |
+
--dev_path datasets/cluener2020/dev.tsv \
|
| 46 |
+
--label2id_path datasets/cluener2020/label2id.json \
|
| 47 |
+
--output_model_path models/cluener2020_ner_model.bin \
|
| 48 |
+
--learning_rate 3e-5 --epochs_num 5 --batch_size 32 --seq_length 512
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Finally, we convert the pre-trained model into Huggingface's format:
|
| 52 |
+
|
| 53 |
+
```
|
| 54 |
+
python3 scripts/convert_bert_token_classification_from_uer_to_huggingface.py --input_model_path models/cluener2020_ner_model.bin \
|
| 55 |
+
--output_model_path pytorch_model.bin \
|
| 56 |
+
--layers_num 12
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
### BibTeX entry and citation info
|
| 60 |
+
|
| 61 |
+
```
|
| 62 |
+
@article{devlin2018bert,
|
| 63 |
+
title={BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding},
|
| 64 |
+
author={Devlin, Jacob and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},
|
| 65 |
+
journal={arXiv preprint arXiv:1810.04805},
|
| 66 |
+
year={2018}
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
@article{liu2019roberta,
|
| 70 |
+
title={Roberta: A robustly optimized bert pretraining approach},
|
| 71 |
+
author={Liu, Yinhan and Ott, Myle and Goyal, Naman and Du, Jingfei and Joshi, Mandar and Chen, Danqi and Levy, Omer and Lewis, Mike and Zettlemoyer, Luke and Stoyanov, Veselin},
|
| 72 |
+
journal={arXiv preprint arXiv:1907.11692},
|
| 73 |
+
year={2019}
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
@article{xu2020cluener2020,
|
| 77 |
+
title={CLUENER2020: Fine-grained Name Entity Recognition for Chinese},
|
| 78 |
+
author={Xu, Liang and Dong, Qianqian and Yu, Cong and Tian, Yin and Liu, Weitang and Li, Lu and Zhang, Xuanwei},
|
| 79 |
+
journal={arXiv preprint arXiv:2001.04351},
|
| 80 |
+
year={2020}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
@article{zhao2019uer,
|
| 84 |
+
title={UER: An Open-Source Toolkit for Pre-training Models},
|
| 85 |
+
author={Zhao, Zhe and Chen, Hui and Zhang, Jinbin and Zhao, Xin and Liu, Tao and Lu, Wei and Chen, Xi and Deng, Haotang and Ju, Qi and Du, Xiaoyong},
|
| 86 |
+
journal={EMNLP-IJCNLP 2019},
|
| 87 |
+
pages={241},
|
| 88 |
+
year={2019}
|
| 89 |
+
}
|
| 90 |
+
```
|