【踩坑】RuntimeError: index out of range: Tried to access index 30522 out of table with 30521 rows.

向右看齐 2022-12-09 03:30 182阅读 0赞

huggingface-torch-bert

使用huggingface下载torch版本的bert-base-chinese预训练模型,格式如上图。

  1. indexed_tokens = self.tokenizer.convert_tokens_to_ids(token)

在这里把token转成id,但是由于下载的vocab名称是”bert-base-chinese-vocab.txt”,默认读取的vocab名称是“vocab.txt”。应当将其改名为vocab.txt

bert-base-chinese

踩坑


下载的模型自带英文的vocab.txt,我不知道要改名,或者把他的删除。
导致读取的英文vocab,然而config的vocab size是中文的vocab size,由此报错越界

发表评论

表情:
评论列表 (有 0 条评论,182人围观)

还没有评论,来说两句吧...

相关阅读

    相关 String index out of range: -1

          前两天报字符串越界,查找中发现,应该是取某一个字符的位置时,出错了,原来使用lastIndexOf时要取得这个字符在被查找的字符串里没有。 解决方法,在取位置之前