what is prompt
时间: 2023-11-10 20:23:37 浏览: 43
A prompt is a message, question, or task given to someone to elicit a response or action. In computing, a prompt is a symbol or message displayed on a screen to indicate that the system is waiting for input from the user. A writing prompt is a sentence or phrase given to inspire creative or analytical writing.
相关问题
what is system prompt
In the context of AI language models such as GPT-3, a system prompt is the initial input or context provided to the model to generate a response or continuation. The system prompt can include one or more sentences that serve as a starting point for the model to generate text that follows a similar style and tone as the prompt. It can also include specific instructions or constraints for the model to follow while generating the text. The quality and relevance of the generated text heavily depend on the quality and relevance of the system prompt provided to the model.
prompt+rag
根据提供的引用内容,可以得知prompt+RAG的流程如下:
1. 首先,使用Retriever部分在知识库中检索出top-k个匹配的文档zi。
2. 然后,将query和k个文档拼接起来作为QA的prompt,送入seq2seq模型。
3. seq2seq模型生成回复y。
4. 如果需要进行Re-rank,可以使用LLM来rerank,给LLM写好prompt即可。
下面是一个简单的示例代码,演示如何使用prompt+RAG:
```python
from transformers import RagTokenizer, RagRetriever, RagSequenceForGeneration
# 初始化tokenizer、retriever和seq2seq模型
tokenizer = RagTokenizer.from_pretrained('facebook/rag-token-base')
retriever = RagRetriever.from_pretrained('facebook/rag-token-base', index_name='exact', use_dummy_dataset=True)
model = RagSequenceForGeneration.from_pretrained('facebook/rag-token-base')
# 设置query和context
query = "What is the capital of France?"
context = "France is a country located in Western Europe. Paris, the capital city of France, is known for its romantic ambiance and iconic landmarks such as the Eiffel Tower."
# 使用Retriever部分检索top-k个匹配的文档
retrieved_docs = retriever(query)
# 将query和k个文档拼接起来作为QA的prompt
input_dict = tokenizer.prepare_seq2seq_batch(query, retrieved_docs[:2], return_tensors='pt')
generated = model.generate(input_ids=input_dict['input_ids'], attention_mask=input_dict['attention_mask'])
# 输出生成的回复
generated_text = tokenizer.batch_decode(generated, skip_special_tokens=True)[0]
print(generated_text)
```