本地加载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/')

GitHub 加速计划 / tra / transformers
130.24 K
25.88 K
下载
huggingface/transformers: 是一个基于 Python 的自然语言处理库,它使用了 PostgreSQL 数据库存储数据。适合用于自然语言处理任务的开发和实现,特别是对于需要使用 Python 和 PostgreSQL 数据库的场景。特点是自然语言处理库、Python、PostgreSQL 数据库。
最近提交(Master分支:1 个月前 )
2e24ee4d * fix return type * update to union * fix gate_logits typing * fix num_experts type * fix typing * run fix-copies * add doc for top_k * run fix-copies * empty commit to trigger CI 15 小时前
d3821c4a * Make audio classification pipeline spec-compliant and add test * Check that test actually running in CI * Try a different pipeline for the CI * Move the test so it gets triggered * Move it again, this time into task_tests! * make fixup * indentation fix * comment * Move everything from testing_utils to test_pipeline_mixin * Add output testing too * revert small diff with main * make fixup * Clarify comment * Update tests/pipelines/test_pipelines_audio_classification.py Co-authored-by: Lucain <lucainp@gmail.com> * Update tests/test_pipeline_mixin.py Co-authored-by: Lucain <lucainp@gmail.com> * Rename function and js_args -> hub_args * Cleanup the spec recursion * Check keys for all outputs --------- Co-authored-by: Lucain <lucainp@gmail.com> 15 小时前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐