transformers: RAG model card code not working in Colab
Environment info
transformersversion: 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
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:
- Open a new colab notebook
- !pip install transformers
- 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)
@sgugger Confirmed.
give the expected behaviour. Thank you!
Install both
faiss-cpuandfaiss-gpuwhile using GPU runtime in Colab solves the issue.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.