当前位置:网站首页>How transformers Roberta adds tokens
How transformers Roberta adds tokens
2022-06-25 02:33:00 【Vincy_ King】
1. Premise
Recently, with roberta The model needs to be added special tokens, But every time it runs GPU There will be a mistake ( There is also a pile of block)
And in the CPU An error will be reported if the error occurs 
I searched a lot of information on the Internet , It is said that if special tokens Or modified vocab.txt, You need to add model.resize_token_embeddings(len(tokenizer)), Otherwise, the dimension will be wrong , But it's not clear where to add it , It was just added to dataset Where to deal with , But it's still wrong .
2. Specific operation
Let's show it first roberta Folder 
added_tokens.json Put what needs to be added tokens
{
"[CH-2]": 21133, "[CH-0]": 21131, "[CH-3]": 21134, "[CH-6]": 21137, "[CH-9]": 21140, "[CH-4]": 21135, "[CH-1]": 21132, "[CH-8]": 21139, "”": 21129, "</s>": 21130, "“": 21128, "[CH-5]": 21136, "[CH-7]": 21138}
special_tokens_map.json Special tokens
{
"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
tokenizer_config.json discharge tokenizer Some configurations of
{
"do_lower_case": true, "do_basic_tokenize": true, "never_split": null, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "special_tokens_map_file": "special_tokens_map.json", "name_or_path": "chinese-roberta-wwm-ext", "use_fast": true, "tokenizer_file": "tokenizer.json", "tokenizer_class": "BertTokenizer"}
stay bert Add... To the model code self.bert.resize_token_embeddings(len(self.tokenizer))
class Model(nn.Module):
def __init__(self, config):
super(Model, self).__init__()
self.bert = BertModel.from_pretrained(config['bert_path'])
self.tokenizer = BertTokenizer.from_pretrained(config['bert_path'])
# self.tokenizer.add_tokens(self.new_tokens, special_tokens=True)
self.bert.resize_token_embeddings(len(self.tokenizer))
for param in self.bert.parameters():
param.requires_grad = True
So it's done ~
边栏推荐
- 1-6搭建Win7虚拟机环境
- 消息称一加将很快更新TWS耳塞、智能手表和手环产品线
- Four characteristics of actual attack and defense drill
- E - average and median
- 【第26天】给定 n 个元素的升序数组nums,求实现一个函数在nums中寻找target的下标 | 初识二分查找
- internship:svn的使用
- 当他们在私域里,掌握了分寸感
- Uncaught Error: [About] is not a <Route> component. All component children of <Routes> must be a <Ro
- Intranet learning notes (5)
- 当人们用互联网式的思维和视角来看待产业互联网的时候,其实已陷入到了死胡同
猜你喜欢
![[STL source code analysis] configurator (to be supplemented)](/img/87/0ed1895e9cdb5327411c0c9cb0197f.png)
[STL source code analysis] configurator (to be supplemented)

Is it out of reach to enter Ali as a tester? Here may be the answer you want

高数 | 精通中值定理 解题套路汇总

左手梦想 右手责任 广汽本田不光关注销量 还有儿童安全

Rod and Schwartz cooperated with ZhongGuanCun pan Lianyuan Institute to carry out 6G technology research and early verification

记一次beego通过go get命令后找不到bee.exe的坑

Once beego failed to find bee after passing the go get command Exe's pit

Please run IDA with elevated permissons for local debugging.

Yarn: unable to load file c:\users\xxx\appdata\roaming\npm\yarn PS1 because running scripts is prohibited on this system

UnityShader入门精要——表面着色器
随机推荐
ERROR日志格式与注意点
Kaggle 专利匹配比赛赛后总结
高速缓存Cache详解(西电考研向)
Post competition summary of kaggle patent matching competition
leecode学习笔记-机器人走到终点的最短路径
文件系统 -- 磁盘基础知识和FAT32文件系统详细介绍
File system - basic knowledge of disk and detailed introduction to FAT32 file system
E - Average and Median(二分)
PE文件基础结构梳理
Processon producer process (customized)
Can automate - 10k, can automate - 20K, do you understand automated testing?
Resolution of cross reference in IDA
Smartctl opens the device and encounters permission denied problem troubleshooting process record
[i.mx6ul] u-boot migration (VI) network driver modification lan8720a
【STL源码剖析】配置器(待补充)
入坑机器学习:一,绪论
把 Oracle 数据库从 Windows 系统迁移到 Linux Oracle Rac 集群环境(4)—— 修改 oracle11g rac 集群的 scanIP
psql 列转行
PE file infrastructure sorting
当他们在私域里,掌握了分寸感