当前位置:网站首页>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虚拟机环境
- NPM package publishing tutorial
- F - Spices(线性基)
- Pit entry machine learning: I. Introduction
- Application of TSDB in civil aircraft industry
- Of the seven levels of software testers, it is said that only 1% can achieve level 7
- 算力服务网络:一场多元融合的系统革命
- Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (2) -- convert database to cluster mode
- Jetson nano from introduction to practice (cases: opencv configuration, face detection, QR code detection)
- Folding screen will become an important weapon for domestic mobile phones to share the apple market
猜你喜欢
Please run IDA with elevated permissons for local debugging.
文件系统 -- 磁盘基础知识和FAT32文件系统详细介绍
消息称一加将很快更新TWS耳塞、智能手表和手环产品线
入坑机器学习:一,绪论
探索C语言程序奥秘——C语言程序编译与预处理
Intranet learning notes (5)
背了八股文,六月赢麻了……
The role of software security testing, how to find a software security testing company to issue a report?
QT package the EXE file to solve the problem that "the program input point \u zdapvj cannot be located in the dynamic link library qt5cored.dll"
Redis
随机推荐
Mall project pc--- product details page
Planification du réseau | [quatre couches de réseau] points de connaissance et exemples
Migrate Oracle database from windows system to Linux Oracle RAC cluster environment (1) -- migrate data to node 1
高速缓存Cache详解(西电考研向)
internship:svn的使用
Computing service network: a systematic revolution of multi integration
The role of software security testing, how to find a software security testing company to issue a report?
qt打包exe文件,解决“无法定位程序输入点_ZdaPvj于动态链接库Qt5Cored.dll”
Intranet learning notes (5)
File system - basic knowledge of disk and detailed introduction to FAT32 file system
Four characteristics of actual attack and defense drill
Experience of epidemic prevention and control, home office and online teaching | community essay solicitation
Squid 代理服务器之 ACL 访问控制
How can Huatai Securities open an account to achieve one in ten thousand? Are securities accounts safe and reliable
Of the seven levels of software testers, it is said that only 1% can achieve level 7
It is said that Yijia will soon update the product line of TWS earplugs, smart watches and bracelets
Pit entry machine learning: I. Introduction
Intranet learning notes (7)
Kaggle 专利匹配比赛金牌方案赛后总结
When they are in private, they have a sense of propriety