
PyTorch中如何在本地加载Roberta模型:Transformers实战指南
transformers
huggingface/transformers: 是一个基于 Python 的自然语言处理库,它使用了 PostgreSQL 数据库存储数据。适合用于自然语言处理任务的开发和实现,特别是对于需要使用 Python 和 PostgreSQL 数据库的场景。特点是自然语言处理库、Python、PostgreSQL 数据库。
项目地址:https://gitcode.com/gh_mirrors/tra/transformers

·
本地加载roberta-base模型文件,roberta-large同理,
只不过hidden_size从768变为1024,
在该网站下载模型文件:
roberta-base at main (huggingface.co)
所需的有 config.json, merges.txt, pytorch_model.bin(下载后重命名), vocab.json
路径组织结构:
└─model
│ merges.txt
│ vocab.json
│
└─roberta-base
config.json
pytorch_model.bin
此处transformers版本是2.11.0,
不同版本的transformers里import的用法可能不同,所以强调了版本,
可针对自己的版本去看官方文档
from transformers import RobertaTokenizer
vocab_file = 'model/vocab.json'
merges_file = 'model/merges.txt'
tokenizer = RobertaTokenizer(vocab_file, merges_file)
RobertaTokenizer 和 BertTokenizer 处理数据时不一样,
Roberta模型没有token_type_ids,也就是segment_ids
还有 Bert 的数据格式是
- pair of sequences:
[CLS] A [SEP] B [SEP]
Roberta 的则是
- pair of sequences:
<s> A </s></s> B </s>
参见:
RobertaTokenizer中的build_inputs_with_special_tokens
与
BertTokenizer中的build_inputs_with_special_tokens
from transformers.modeling_roberta import RobertaModel
bert = RobertaModel.from_pretrained('model/roberta-base/')




huggingface/transformers: 是一个基于 Python 的自然语言处理库,它使用了 PostgreSQL 数据库存储数据。适合用于自然语言处理任务的开发和实现,特别是对于需要使用 Python 和 PostgreSQL 数据库的场景。特点是自然语言处理库、Python、PostgreSQL 数据库。
最近提交(Master分支:6 个月前 )
8eaae6be
* Added Support for Custom Quantization
* Update code
* code reformatted
* Updated Changes
* Updated Changes
---------
Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com> 22 天前
07182b2e
Flatten the expected slice tensor 22 天前
更多推荐
所有评论(0)