在开始之前,我还是打算再次扼要的介绍一下 RAG。
在 Meta 的官方 Blog 上有如许一段话:
Building a model that researches and contextualizes is more challenging, but it’s essential for future advancements. We recently made substantial progress in this realm with our Retrieval Augmented Generation (RAG) architecture, an end-to-end differentiable model that combines an information retrieval component (Facebook AI’s dense-passage retrieval system) with a seq2seq generator (our Bidirectional and Auto-Regressive Transformers BART model). RAG can be fine-tuned on knowledge-intensive downstream tasks to achieve state-of-the-art results compared with even the largest pretrained seq2seq language models. And unlike these pretrained models, RAG’s internal knowledge can be easily altered or even supplemented on the fly, enabling researchers and engineers to control what RAG knows and doesn’t know without wasting time or compute power retraining the entire model.
这段话重要讲述了一个新的模子架构,也就是 RAG (检索增强生成) 的紧张性和上风。可以概括为以下几点:
corpus_of_documents = [ "Take a leisurely walk in the park and enjoy the fresh air.", "Visit a local museum and discover something new.", "Attend a live music concert and feel the rhythm.", "Go for a hike and admire the natural scenery.", "Have a picnic with friends and share some laughs.", "Explore a new cuisine by dining at an ethnic restaurant.", "Take a yoga class and stretch your body and mind.", "Join a local sports league and enjoy some friendly competition.", "Attend a workshop or lecture on a topic you're interested in.", "Visit an amusement park and ride the roller coasters." ]
由于我们选择了一个非常简单的相似性度量方法来学习,所以会带来一些题目。
它没有语义概念,只是简单地看两个文档中有哪些词,然后举行对比。
也就是说,只要我们提供的用户输入里包含这些词,那么我们就会得到雷同的结果,因为那就是最接近的文档。
比如,我将用户输入换成了 user_input = "I don't like to hike"。
relevant_document = return_response(user_input, corpus_of_documents) full_response = [] prompt = """ You are a bot that makes recommendations for activities. You answer in very short sentences and do not include extra information. This is the recommended activity: {relevant_document} The user input is: {user_input} Compile a recommendation to the user based on the recommended activity and the user input. """