Huggin Face对话错误:错误:参数模型:无效选择:“models/”(从“openaigpt”、“gpt2”中选择)

2024-03-28 18:43:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图复制本回购协议的结果:

https://github.com/huggingface/transfer-learning-conv-ai

为此,我遵循的基本示例并非基于docker:

git clone https://github.com/huggingface/transfer-learning-conv-ai
cd transfer-learning-conv-ai
pip install -r requirements.txt
python -m spacy download en

然后我尝试:

python3 interact.py --model models/

我得到了这个错误:

  np_resource = np.dtype([("resource", np.ubyte, 1)])
usage: interact.py [-h] [--dataset_path DATASET_PATH]
                   [--dataset_cache DATASET_CACHE] [--model {openai-gpt,gpt2}]
                   [--model_checkpoint MODEL_CHECKPOINT]
                   [--max_history MAX_HISTORY] [--device DEVICE] [--no_sample]
                   [--max_length MAX_LENGTH] [--min_length MIN_LENGTH]
                   [--seed SEED] [--temperature TEMPERATURE] [--top_k TOP_K]
                   [--top_p TOP_P]
interact.py: error: argument --model: invalid choice: 'models/' (choose from 'openai-gpt', 'gpt2')

我注意到的第一件事是没有任何“models”目录,因此我创建了一个目录,并再次尝试,得到了相同的错误

我尝试的第二件事是下载它指定的回购协议中的模型:

We make a pretrained and fine-tuned model available on our S3 here

我试着从这个链接:

wget https://s3.amazonaws.com/models.huggingface.co/transfer-learning-chatbot/finetuned_chatbot_gpt.tar.gz

并解压缩主目录和模型目录中的文件,然后重试

这是我第三次尝试,但还是犯了同样的错误

这是我的工作目录的当前结构:

Dockerfile   config.json                   interact.py              pytorch_model.bin       train.py
LICENCE      convai_evaluation.py          merges.txt               requirements.txt        utils.py
README.md    example_entry.py              model_training_args.bin  special_tokens.txt      vocab.json
__pycache__  finetuned_chatbot_gpt.tar.gz  models                   test_special_tokens.py

编辑

试过kimbo的建议:

python3 interact.py --model gpt2

我现在得到这个错误:

 File "interact.py", line 154, in <module>
    run()
  File "interact.py", line 114, in run
    raise ValueError("Interacting with GPT2 requires passing a finetuned model_checkpoint")
ValueError: Interacting with GPT2 requires passing a finetuned model_checkpoint

还尝试了运行:

python3 interact.py

因此,我没有得到任何错误,它似乎被困在这一点上:

INFO:/home/lramirez/transfer-learning-conv-ai/utils.py:Download dataset from https://s3.amazonaws.com/datasets.huggingface.co/personachat/personachat_self_original.json
INFO:/home/lramirez/transfer-learning-conv-ai/utils.py:Tokenize and encode the dataset

我已经在那里呆了大约30分钟了


Tags: pyhttpstxtcommodelmodels错误dataset
2条回答

新更新

标记化数据集需要花费很长时间,因为它标记化了整个数据集,这是一个200 MB的JSON文件

为了加快速度,只需加载部分数据集

打开utils.py并更改tokenize函数:

def tokenize(obj):
    if isinstance(obj, str):
        return tokenizer.convert_tokens_to_ids(tokenizer.tokenize(obj))
    if isinstance(obj, dict):
        return dict((n, tokenize(o)) for n, o in obj.items())
    limit = 100  # <- this is the number of items in the dataset to load
    return list(tokenize(o) for o in obj[:limit])  # <- change it here

这将只加载数据集中的前100个项


旧答案

当我不确定如何使用python脚本(或者从命令行运行的任何东西)时,我通常会尝试一些方法来解决它

  • python script.py -hpython script.py help。这通常会打印出脚本期望的参数以及如何运行它的解释
  • 如果它是您安装的可执行命令,我总是尝试man <executable>。在这种情况下可能不起作用,因为您刚刚从GitHub克隆了repo,没有安装任何东西
  • 如果我仍然不明白如何使用脚本,因为上面的方法不起作用,我会上网查找一些文档(Github自述、wiki、readthedocs等)
  • 如果文档记录不好,我只看源代码。有时我会直接跳到这一部分,因为对于较小的东西,它通常更快

在本例中,我在Github上阅读了自述文件,但没有告诉我太多,所以我看了interact.py。如果您从第139行(https://github.com/huggingface/transfer-learning-conv-ai/blob/master/interact.py#L139)开始查看,它们似乎处于while循环中,等待您输入要馈送到模型的内容

/end更新

本部分:

(choose from 'openai-gpt', 'gpt2')

应该告诉你所有你需要知道的

试着跑步

python3 interact.py  model gpt2

python3 interact.py  model openai-gpt

这个错误是因为HuggingFace在ConvAI数据集上没有一个GPT2的微调模型,他们只是为GPT做的

if args.model == 'gpt2':
            raise ValueError("Interacting with GPT2 requires passing a finetuned model_checkpoint")

您可以在interact.py文件中找到这部分代码,因此如果您想在gpt2上使用它,您需要自己对其进行微调。我现在只是在努力解决这个问题

相关问题 更多 >