transformers: RAG model card code not working in Colab

Environment info

  • transformers version: 3.3.1
  • Platform: Linux-4.19.112±x86_64-with-Ubuntu-18.04-bionic
  • Python version: 3.6.9
  • PyTorch version (GPU?): 1.6.0+cu101 (True)
  • Tensorflow version (GPU?): 2.3.0 (True)
  • Using GPU in script?: Yes
  • Using distributed or parallel set-up in script?: No

Who can help

@julien-c @VictorSanh

Information

Model I am using RAG

The problem arises when using:

  • the official example scripts: (give details below)

To reproduce

Steps to reproduce the behavior:

  1. Open a new colab notebook
  2. !pip install transformers
  3. execute the RAG model example code

tokenizer = RagTokenizer.from_pretrained("facebook/rag-token-nq")
retriever = RagRetriever.from_pretrained("facebook/rag-token-nq", index_name="exact", use_dummy_dataset=True)
model = RagTokenForGeneration.from_pretrained("facebook/rag-token-nq", retriever=retriever)

input_dict = tokenizer.prepare_seq2seq_batch("who holds the record in 100m freestyle", return_tensors="pt") 

generated = model.generate(input_ids=input_dict["input_ids"]) 
print(tokenizer.batch_decode(generated, skip_special_tokens=True)[0]) 

error traceback

NameError                                 Traceback (most recent call last)

<ipython-input-5-fcc46db034ee> in <module>()
      2 
      3 tokenizer = RagTokenizer.from_pretrained("facebook/rag-token-nq")
----> 4 retriever = RagRetriever.from_pretrained("facebook/rag-token-nq", index_name="exact", use_dummy_dataset=True)
      5 model = RagTokenForGeneration.from_pretrained("facebook/rag-token-nq", retriever=retriever)
      6 

2 frames

/usr/local/lib/python3.6/dist-packages/transformers/retrieval_rag.py in __init__(self, dataset_name, dataset_split, index_name, vector_size, index_path, use_dummy_dataset)
    218 
    219         logger.info("Loading passages from {}".format(self.dataset_name))
--> 220         self.dataset = load_dataset(
    221             self.dataset_name, with_index=False, split=self.dataset_split, dummy=self.use_dummy_dataset
    222         )

NameError: name 'load_dataset' is not defined

Expected behavior

I would expect the model card example to be output:

should give michael phelps => sounds reasonable

or something to this effect.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

@sgugger Confirmed.

!pip install transformers
!pip install datasets
!pip install faiss

give the expected behaviour. Thank you!

Install both faiss-cpu and faiss-gpu while using GPU runtime in Colab solves the issue.

Install both faiss-cpu and faiss-gpu while using GPU runtime in Colab solves the issue.

Unluckily it still doesn’t work. image

Error message is still the same: image

Mine works fine so no idea what happened on yours lol. I’ll leave my Colab notebook here: https://colab.research.google.com/drive/1xnTBsOZxG5hJJppz5ozbpdGxGx7MnDXw?usp=sharing

Working on having some clear error message for the next users in #7537 😃 Thanks for flagging the problem!

I think I found why while fixing the error message. This also needs the faiss library: ! pip install faiss.