用例(User Case)
问答生成(QA Generation)

LangChain

QA生成 QA Generation #

这个教程展示了如何使用QAGenerationChain来对特定文档提出问题-答案对。

这一点很重要, 因为很多时候你可能没有数据来评估你的问答系统,所以这是一种廉价而轻量级的方法来生成它!

from langchain.document_loaders import TextLoader
 
loader = TextLoader("../../modules/state_of_the_union.txt")
 
doc = loader.load()[0]
 
from langchain.chat_models import ChatOpenAI
from langchain.chains import QAGenerationChain
chain = QAGenerationChain.from_llm(ChatOpenAI(temperature = 0))
 
qa = chain.run(doc.page_content)
 
qa[1]
 
{'question': 'What is the U.S. Department of Justice doing to combat the crimes of Russian oligarchs?',
 'answer': 'The U.S. Department of Justice is assembling a dedicated task force to go after the crimes of Russian oligarchs.'}