add roformer chinese small
Browse files- README.md +82 -0
- config.json +18 -0
- pytorch_model.bin +3 -0
- tf_model.h5 +3 -0
- vocab.txt +0 -0
README.md
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: zh
|
3 |
+
tags:
|
4 |
+
- roformer
|
5 |
+
- pytorch
|
6 |
+
- tf2.0
|
7 |
+
inference: false
|
8 |
+
---
|
9 |
+
## 介绍
|
10 |
+
### tf版本
|
11 |
+
https://github.com/ZhuiyiTechnology/roformer
|
12 |
+
|
13 |
+
### pytorch版本+tf2.0版本
|
14 |
+
https://github.com/JunnYu/RoFormer_pytorch
|
15 |
+
|
16 |
+
## 安装
|
17 |
+
```bash
|
18 |
+
pip install roformer
|
19 |
+
或
|
20 |
+
pip install git+https://github.com/JunnYu/RoFormer_pytorch.git
|
21 |
+
```
|
22 |
+
|
23 |
+
## pytorch使用
|
24 |
+
```python
|
25 |
+
import torch
|
26 |
+
from roformer import RoFormerForMaskedLM, RoFormerTokenizer
|
27 |
+
|
28 |
+
text = "今天[MASK]很好,我[MASK]去公园玩。"
|
29 |
+
tokenizer = RoFormerTokenizer.from_pretrained("junnyu/roformer_chinese_small")
|
30 |
+
pt_model = RoFormerForMaskedLM.from_pretrained("junnyu/roformer_chinese_small")
|
31 |
+
pt_inputs = tokenizer(text, return_tensors="pt")
|
32 |
+
with torch.no_grad():
|
33 |
+
pt_outputs = pt_model(**pt_inputs).logits[0]
|
34 |
+
pt_outputs_sentence = "pytorch: "
|
35 |
+
for i, id in enumerate(tokenizer.encode(text)):
|
36 |
+
if id == tokenizer.mask_token_id:
|
37 |
+
tokens = tokenizer.convert_ids_to_tokens(pt_outputs[i].topk(k=5)[1])
|
38 |
+
pt_outputs_sentence += "[" + "||".join(tokens) + "]"
|
39 |
+
else:
|
40 |
+
pt_outputs_sentence += "".join(
|
41 |
+
tokenizer.convert_ids_to_tokens([id], skip_special_tokens=True))
|
42 |
+
print(pt_outputs_sentence)
|
43 |
+
# pytorch: 今天[天气||心情||感觉||环境||下午]很好,我[要||想||就||可以||去]去公园玩。
|
44 |
+
```
|
45 |
+
|
46 |
+
|
47 |
+
## tensorflow2.0使用
|
48 |
+
```python
|
49 |
+
import tensorflow as tf
|
50 |
+
from roformer import RoFormerTokenizer, TFRoFormerForMaskedLM
|
51 |
+
text = "今天[MASK]很好,我[MASK]去公园玩。"
|
52 |
+
tokenizer = RoFormerTokenizer.from_pretrained("junnyu/roformer_chinese_small")
|
53 |
+
tf_model = TFRoFormerForMaskedLM.from_pretrained("junnyu/roformer_chinese_small")
|
54 |
+
tf_inputs = tokenizer(text, return_tensors="tf")
|
55 |
+
tf_outputs = tf_model(**tf_inputs, training=False).logits[0]
|
56 |
+
tf_outputs_sentence = "tf2.0: "
|
57 |
+
for i, id in enumerate(tokenizer.encode(text)):
|
58 |
+
if id == tokenizer.mask_token_id:
|
59 |
+
tokens = tokenizer.convert_ids_to_tokens(
|
60 |
+
tf.math.top_k(tf_outputs[i], k=5)[1])
|
61 |
+
tf_outputs_sentence += "[" + "||".join(tokens) + "]"
|
62 |
+
else:
|
63 |
+
tf_outputs_sentence += "".join(
|
64 |
+
tokenizer.convert_ids_to_tokens([id], skip_special_tokens=True))
|
65 |
+
print(tf_outputs_sentence)
|
66 |
+
# tf2.0 今天[天气||心情||感觉||环境||下午]很好,我[要||想||就||可以||去]去公园玩。
|
67 |
+
```
|
68 |
+
|
69 |
+
## 引用
|
70 |
+
|
71 |
+
Bibtex:
|
72 |
+
|
73 |
+
```tex
|
74 |
+
@misc{su2021roformer,
|
75 |
+
title={RoFormer: Enhanced Transformer with Rotary Position Embedding},
|
76 |
+
author={Jianlin Su and Yu Lu and Shengfeng Pan and Bo Wen and Yunfeng Liu},
|
77 |
+
year={2021},
|
78 |
+
eprint={2104.09864},
|
79 |
+
archivePrefix={arXiv},
|
80 |
+
primaryClass={cs.CL}
|
81 |
+
}
|
82 |
+
```
|
config.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"RoFormerForMaskedLM"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"hidden_act": "gelu",
|
7 |
+
"hidden_dropout_prob": 0.1,
|
8 |
+
"hidden_size": 384,
|
9 |
+
"initializer_range": 0.02,
|
10 |
+
"intermediate_size": 1536,
|
11 |
+
"layer_norm_eps": 1e-12,
|
12 |
+
"model_type": "roformer",
|
13 |
+
"num_attention_heads": 6,
|
14 |
+
"num_hidden_layers": 6,
|
15 |
+
"pad_token_id": 0,
|
16 |
+
"type_vocab_size": 2,
|
17 |
+
"vocab_size": 50000
|
18 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b4a7c6cad49ff8e6a29dba326805f5c498150adcdbb8d10efe01b2feb5439126
|
3 |
+
size 120808404
|
tf_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:423272802837cb1803f2be1abb0830527ac175141b6691da7f7981bfc40f62f8
|
3 |
+
size 197760800
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|