Views
No views yet
| iflytek | tnews | afqmc | cmnli | ocnli | wsc | csl | |
|---|---|---|---|---|---|---|---|
| BERT | 60.06 | 56.80 | 72.41 | 79.56 | 73.93 | 78.62 | 83.93 |
| RoBERTa | 60.64 | 58.06 | 74.05 | 81.24 | 76.00 | 87.50 | 84.50 |
| RoFormer | 60.91 | 57.54 | 73.52 | 80.92 | 76.07 | 86.84 | 84.63 |
| RoFormerV2* | 60.87 | 56.54 | 72.75 | 80.34 | 75.36 | 80.92 | 84.67 |
| GAU-α | 61.41 | 57.76 | 74.17 | 81.82 | 75.86 | 79.93 | 85.67 |
| RoFormer-pytorch(本仓库代码) | 60.60 | 57.51 | 74.44 | 80.79 | 75.67 | 86.84 | 84.77 |
| RoFormerV2-pytorch(本仓库代码) | 62.87 | 59.03 | 76.20 | 80.85 | 79.73 | 87.82 | 91.87 |
| GAU-α-pytorch(Adafactor) | 61.18 | 57.52 | 73.42 | 80.91 | 75.69 | 80.59 | 85.5 |
| GAU-α-pytorch(AdamW wd0.01 warmup0.1) | 60.68 | 57.95 | 73.08 | 81.02 | 75.36 | 81.25 | 83.93 |
| RoFormerV2-large-pytorch(本仓库代码) | 61.75 | 59.21 | 76.14 | 82.35 | 81.73 | 91.45 | 91.5 |
| Chinesebert-large-pytorch | 61.25 | 58.67 | 74.70 | 82.65 | 79.63 | 87.83 | 84.97 |
| iflytek | tnews | afqmc | cmnli | ocnli | wsc | csl | |
|---|---|---|---|---|---|---|---|
| RoFormer-pytorch(本仓库代码) | 59.54 | 57.34 | 74.46 | 80.23 | 73.67 | 80.69 | 84.57 |
| RoFormerV2-pytorch(本仓库代码) | 63.15 | 58.24 | 75.42 | 80.59 | 74.17 | 83.79 | 83.73 |
| GAU-α-pytorch(Adafactor) | 61.38 | 57.08 | 74.05 | 80.37 | 73.53 | 74.83 | 85.6 |
| GAU-α-pytorch(AdamW wd0.01 warmup0.1) | 60.54 | 57.67 | 72.44 | 80.32 | 72.97 | 76.55 | 84.13 |
| RoFormerV2-large-pytorch(本仓库代码) | 61.85 | 59.13 | 76.38 | 80.97 | 76.23 | 85.86 | 84.33 |
| Chinesebert-large-pytorch | 61.54 | 58.57 | 74.8 | 81.94 | 76.93 | 79.66 | 85.1 |
1class RoFormerClassificationHead(nn.Module):
2 def __init__(self, config):
3 super().__init__()
4 self.dense = nn.Linear(config.hidden_size, config.hidden_size)
5 self.dropout = nn.Dropout(config.hidden_dropout_prob)
6 self.out_proj = nn.Linear(config.hidden_size, config.num_labels)
7
8 self.config = config
9
10 def forward(self, features, **kwargs):
11 x = features[:, 0, :] # take <s> token (equiv. to [CLS])
12 x = self.dropout(x)
13 x = self.dense(x)
14 x = ACT2FN[self.config.hidden_act](x) # 这里是relu
15 x = self.dropout(x)
16 x = self.out_proj(x)
17 return x1import torch
2import tensorflow as tf
3from transformers import BertTokenizer
4from roformer import RoFormerForMaskedLM, TFRoFormerForMaskedLM
5text = "今天[MASK]很好,我[MASK]去公园玩。"
6tokenizer = BertTokenizer.from_pretrained("junnyu/roformer_v2_chinese_char_large")
7pt_model = RoFormerForMaskedLM.from_pretrained("junnyu/roformer_v2_chinese_char_large")
8tf_model = TFRoFormerForMaskedLM.from_pretrained(
9 "junnyu/roformer_v2_chinese_char_base", from_pt=True
10)
11pt_inputs = tokenizer(text, return_tensors="pt")
12tf_inputs = tokenizer(text, return_tensors="tf")
13# pytorch
14with torch.no_grad():
15 pt_outputs = pt_model(**pt_inputs).logits[0]
16pt_outputs_sentence = "pytorch: "
17for i, id in enumerate(tokenizer.encode(text)):
18 if id == tokenizer.mask_token_id:
19 tokens = tokenizer.convert_ids_to_tokens(pt_outputs[i].topk(k=5)[1])
20 pt_outputs_sentence += "[" + "||".join(tokens) + "]"
21 else:
22 pt_outputs_sentence += "".join(
23 tokenizer.convert_ids_to_tokens([id], skip_special_tokens=True)
24 )
25print(pt_outputs_sentence)
26# tf
27tf_outputs = tf_model(**tf_inputs, training=False).logits[0]
28tf_outputs_sentence = "tf: "
29for i, id in enumerate(tokenizer.encode(text)):
30 if id == tokenizer.mask_token_id:
31 tokens = tokenizer.convert_ids_to_tokens(tf.math.top_k(tf_outputs[i], k=5)[1])
32 tf_outputs_sentence += "[" + "||".join(tokens) + "]"
33 else:
34 tf_outputs_sentence += "".join(
35 tokenizer.convert_ids_to_tokens([id], skip_special_tokens=True)
36 )
37print(tf_outputs_sentence)
38# small
39# pytorch: 今天[的||,||是||很||也]很好,我[要||会||是||想||在]去公园玩。
40# tf: 今天[的||,||是||很||也]很好,我[要||会||是||想||在]去公园玩。
41# base
42# pytorch: 今天[我||天||晴||园||玩]很好,我[想||要||会||就||带]去公园玩。
43# tf: 今天[我||天||晴||园||玩]很好,我[想||要||会||就||带]去公园玩。
44# large
45# pytorch: 今天[天||气||我||空||阳]很好,我[又||想||会||就||爱]去公园玩。
46# tf: 今天[天||气||我||空||阳]很好,我[又||想||会||就||爱]去公园玩。1@misc{su2021roformer,
2 title={RoFormer: Enhanced Transformer with Rotary Position Embedding},
3 author={Jianlin Su and Yu Lu and Shengfeng Pan and Bo Wen and Yunfeng Liu},
4 year={2021},
5 eprint={2104.09864},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL}
8}1@techreport{roformerv2,
2 title={RoFormerV2: A Faster and Better RoFormer - ZhuiyiAI},
3 author={Jianlin Su, Shengfeng Pan, Bo Wen, Yunfeng Liu},
4 year={2022},
5 url="https://github.com/ZhuiyiTechnology/roformer-v2",
6}