huggingface / transfer-learning-conv-ai

🦄 State-of-the-Art Conversational AI with Transfer Learning
MIT License
1.74k stars 430 forks source link

TypeError: tuple indices must be integers or slices, not tuple when running interact.py #98

Closed alyonavyshnevska closed 3 years ago

alyonavyshnevska commented 3 years ago

I followed the steps to install all the requirements, and ran the interact.py script to download the pre-trained model from S3.

below is the error message:

INFO:./interact.py:Selected personality: i'm 29 years old. i enjoy hiking and riding my bicycle. i'm a night owl. i live in a suburb of boston.
>>> great to meet you. Do you like hiking?
Traceback (most recent call last):
  File "./interact.py", line 154, in <module>
    run()
  File "./interact.py", line 146, in run
    out_ids = sample_sequence(personality, history, tokenizer, model, args)
  File "./interact.py", line 72, in sample_sequence
    logits = logits[0, -1, :] / args.temperature
  File "/opt/miniconda3/envs/tutorialHuggingFace/lib/python3.8/site-packages/transformers/file_utils.py", line 1447, in __getitem__
    return self.to_tuple()[k]
TypeError: tuple indices must be integers or slices, not tuple

python version: 3.8

JohnnyC08 commented 3 years ago

I just ran into this. This is because we're using an updated version of transformers. The fix is actually really simple. In interact.py in the sample_sequence method change: logits = model(input_ids, token_type_ids=token_type_ids) to logits = model(input_ids, token_type_ids=token_type_ids).logits

alyonavyshnevska commented 3 years ago

@JohnnyC08 thank you, that was it! Now the script works for me