模型:
facebook/rag-sequence-nq
这是 Patrick Lewis、Ethan Perez、Aleksandara Piktus等人的论文" Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks "中的RAG-Sequence模型。
该模型是一个uncased模型,意味着大写字母仅被转换为小写字母。
该模型由question_encoder、retriever和generator构成。retriever从链接在上方的wiki_dpr train数据集中提取相关段落。question_encoder和retriever基于facebook/dpr-question_encoder-single-nq-base和facebook/bart-large,在wiki_dpr QA数据集上进行了联合微调,实现了端到端训练。
注意:在下面的使用示例中,仅使用了wiki_dpr的虚拟检索器,因为完整的遗留索引需要超过75 GB的RAM。该模型可以回答任何事实性问题,方法如下:
from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration tokenizer = RagTokenizer.from_pretrained("facebook/rag-sequence-nq") retriever = RagRetriever.from_pretrained("facebook/rag-sequence-nq", index_name="exact", use_dummy_dataset=True) model = RagSequenceForGeneration.from_pretrained("facebook/rag-sequence-nq", retriever=retriever) input_dict = tokenizer.prepare_seq2seq_batch("how many countries are in europe", return_tensors="pt") generated = model.generate(input_ids=input_dict["input_ids"]) print(tokenizer.batch_decode(generated, skip_special_tokens=True)[0]) # should give 54 => google says either 44 or 51