microsoft / ContextualSP

Multiple paper open-source codes of the Microsoft Research Asia DKI group
MIT License
374 stars 62 forks source link

关于`python predict.py`的问题~ #24

Closed cingtiye closed 2 years ago

cingtiye commented 2 years ago

您好! 感谢作者的开源! 我在执行python install -r requirement.txt之后执行 cd src && python predict.py之后出现错误~ 似乎是模型"../pretrained_weights/multi_bert.tar.gz"并没有加载进去~

非常期待能得到您的回复~ 祝您五一快乐~

Model name 'bert-base-chinese' was not found in model name list (bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased, bert-base-multilingual-uncased, bert-base-multilingual-cased, bert-base-chinese). We assumed 'https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-chinese.tar.gz' was a path or url but couldn't find any file associated to this path or url.
Traceback (most recent call last):
  File "predict.py", line 28, in <module>
    manager = PredictManager("../pretrained_weights/multi_bert.tar.gz")
  File "predict.py", line 12, in __init__
    archive = load_archive(archive_file)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/models/archival.py", line 230, in load_archive
    cuda_device=cuda_device)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/models/model.py", line 327, in load
    return cls.by_name(model_type)._load(config, serialization_dir, weights_file, cuda_device)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/models/model.py", line 265, in _load
    model = Model.from_params(vocab=vocab, params=model_params)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/common/from_params.py", line 365, in from_params
    return subclass.from_params(params=params, **extras)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/common/from_params.py", line 386, in from_params
    kwargs = create_kwargs(cls, params, **extras)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/common/from_params.py", line 133, in create_kwargs
    kwargs[name] = construct_arg(cls, name, annotation, param.default, params, **extras)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/common/from_params.py", line 229, in construct_arg
    return annotation.from_params(params=subparams, **subextras)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/common/from_params.py", line 365, in from_params
    return subclass.from_params(params=params, **extras)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/modules/text_field_embedders/basic_text_field_embedder.py", line 168, in from_params
    token_embedders[key] = TokenEmbedder.from_params(vocab=vocab, params=embedder_params)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/common/from_params.py", line 365, in from_params
    return subclass.from_params(params=params, **extras)
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/common/from_params.py", line 388, in from_params
    return cls(**kwargs)  # type: ignore
  File "/home/cingti/anaconda3/envs/cpu-py36/lib/python3.6/site-packages/allennlp/modules/token_embedders/bert_token_embedder.py", line 272, in __init__
    for param in model.parameters():
AttributeError: 'NoneType' object has no attribute 'parameters'
cingtiye commented 2 years ago

我发现要这样写才行~

from predictor import RewritePredictor
from data_reader import RewriteDatasetReader
from model import UnifiedFollowUp

from allennlp.models.archival import load_archive
from allennlp.predictors.predictor import Predictor

而且还需要下载bert模型~

SivilTaram commented 2 years ago

@cingtiye 感谢反馈!是指原始的import顺序会报错是吗?

cingtiye commented 2 years ago

请问你再运行这个predict.py时会自动下载bert模型吗?而且我发现这个是运行一次下载一次~懵了

cingtiye commented 2 years ago

@SivilTaram 这个.tar.gz里面好像没有词表~所以会报错~和顺序似乎没有关系~

SivilTaram commented 2 years ago

@cingtiye 下载bert模型这个有点忘了,理论上下载一次是可能的,但一直下载不太可能 O.O

cingtiye commented 2 years ago

请问你知道下载保存本地的地址在哪里吗?或者程序什么地方可以修改下载保存后的地址~

SivilTaram commented 2 years ago

@cingtiye 这个可能要看一下huggingface transformers的使用文档

SivilTaram commented 2 years ago

@SivilTaram 这个.tar.gz里面好像没有词表~所以会报错~和顺序似乎没有关系~

奇怪,我来检查一下

SivilTaram commented 2 years ago

@cingtiye hello,凭借我模糊的记忆,我记得bert模型在allennlp中是不需要指定vocabulary的哈,因为bert的词表是固定的。能否请您检查一下allennlp的版本是否为0.9.0?以及,在虚拟环境中是否同时安装了pretrained-pytorch-transformerstransformers两个库?

cingtiye commented 2 years ago

没有安装 pretrained-pytorch-transformers 但是好像没有这个库~

image

SivilTaram commented 2 years ago

@cingtiye 不好意思,应该是这个 pytorch-pretrained-bert,这个库是 transformers 库的前身。

cingtiye commented 2 years ago

@cingtiye hello,凭借我模糊的记忆,我记得bert模型在allennlp中是不需要指定vocabulary的哈,因为bert的词表是固定的。能否请您检查一下allennlp的版本是否为0.9.0?以及,在虚拟环境中是否同时安装了pretrained-pytorch-transformerstransformers两个库?

还是会下载~你可以看一下这个代码,你的和我的是一样的吗?这句话应该就是去下载模型~

from allennlp.modules.token_embedders import bert_token_embedder  # 这个函数里面第270行

image

SivilTaram commented 2 years ago

@cingtiye 这个代码应该是一样的,我怀疑可能是pytorch-pretrained-bert的bug,但我之前没有注意过? 因为这个库已经迁移到一个全新的库了,您可以试着升级一下 allennlp,看看能否在更高版本下解决这个bug。

cingtiye commented 2 years ago

可以了,没有升级allennlp,强制修改了原来allennlp里面的代码,我评估一下模型,看看改的对不对~稍等~

cingtiye commented 2 years ago

我发现用Multi_bert的模型去跑Rewrite的dev.txt和用Rewrite_bert去跑Multi的test.txt效果都非常不好~模型泛化性是不是不太好~

SivilTaram commented 2 years ago

@cingtiye 可能模型的选择有点过拟合,也有可能是因为数据集的分布不同。有相关的论文曾经探讨过这个问题,可以参考论文 https://arxiv.org/abs/2012.14535

image

可以看到我们的方法 RUNRewrite 数据集上训练后,在Restoration (即本文的 Multi)数据集上的 BLEU4 有65.7

cingtiye commented 2 years ago

好的~多谢指导~祝你五一假期愉快~

SivilTaram commented 2 years ago

@cingtiye 不客气,有问题欢迎继续提问!( 科研狗没有五一

Tesla-jiang commented 7 months ago

可以了,没有升级allennlp,强制修改了原来allennlp里面的代码,我评估一下模型,看看改的对不对~稍等~

你好,可以咨询下你修改了哪部分么,我这边将 data_reader.py 里的 pretrain_model_name 修改为本地地址后,会报错 AttributeError: 'NoneType' object has no attribute 'vocab',不知道你有没有遇到过