ShomyLiu / pytorch_bert_elmo_example

A text classification example with Bert/ELMo/GloVe in pytorch
http://shomy.top/2019/01/01/elmo-1/
90 stars 13 forks source link

感谢您分享的模型代码,当我复现您的代码时,在emb_method=“bert”时,报了错? #9

Open YeNiTing opened 4 years ago

YeNiTing commented 4 years ago

错误为:; Traceback (most recent call last): File "main.py", line 108, in fire.Fire() File "D:\software\Anaconda3\envs\ynt2\lib\site-packages\fire\core.py", line 138, in Fire component_trace = _Fire(component, args, parsed_flag_args, context, name) File "D:\software\Anaconda3\envs\ynt2\lib\site-packages\fire\core.py", line 468, in _Fire target=component.name) File "D:\software\Anaconda3\envs\ynt2\lib\site-packages\fire\core.py", line 672, in _CallAndUpdateTrace component = fn(*varargs, *kwargs) File "main.py", line 69, in train output = model(x) File "D:\software\Anaconda3\envs\ynt2\lib\site-packages\torch\nn\modules\module.py", line 550, in call result = self.forward(input, **kwargs) File "C:\Users\YNT\Desktop\重要文件夹\数据集\EMLo相关\pytorch_bert_elmo_example-master\model.py", line 40, in forward word_embs = self.get_bert(x) File "C:\Users\YNT\Desktop\重要文件夹\数据集\EMLo相关\pytorch_bert_elmo_example-master\model.py", line 90, in get_bert ids = self.tokenizer(sentence_lists, padding=True, return_tensors="pt") TypeError: 'BertTokenizer' object is not callable

可是发现您代码里并不存在BertTokenizer对象?

ShomyLiu commented 4 years ago

你好, 这个应该是版本问题。 Tokenizer这几次更新,导致API变化。 tokenizer定义在上面: https://github.com/ShomyLiu/pytorch_bert_elmo_example/blob/master/model.py#L49

YeNiTing commented 4 years ago

请问您transformers的版本为多少?

ShomyLiu commented 4 years ago

tokenizers 0.8.1rc1 transformers 3.0.2

YeNiTing commented 4 years ago

感谢!