文字列評価
ここでは、人間が作成した正解の回答と比較することで、最終出力を本格的に評価してみましょう。この文字列比較評価には、LangSmithのLangChainStringEvaluator クラスを使用します。
文字列評価用のprompt_templateはすでに以下のとおり用意されています。
You are an expert professor specialized in grading students' answers to questions.
You are grading the following question:{query}
Here is the real answer:{answer}
You are grading the following predicted answer:{result}
Respond with CORRECT or INCORRECT:
Grade:
RAGチェーンからの出力はpredicted_answerに、人間の回答はref_answerに格納されています。
必要なクラスはすべてインポート済みです。
この演習はコースの一部です
LangChainで学ぶ検索拡張生成(RAG)
演習の手順
- 用意されている
eval_llmとprompt_templateを使って、LangSmithのQA文字列評価ツールを作成してください。 - RAGの出力である
predicted_answerを、queryに対する人間の回答であるref_answerと比較して評価してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Create the QA string evaluator
qa_evaluator = ____(
"____",
config={
"llm": ____,
"prompt": ____
}
)
query = "How does RAG improve question answering with LLMs?"
# Evaluate the RAG output by evaluating strings
score = qa_evaluator.evaluator.____(
prediction=____,
reference=____,
input=____
)
print(f"Score: {score}")