始める無料で始める

文字列評価

専門家が作成した解答と最終出力を比較して、本格的に評価してみましょう。ここでは 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 で学ぶ Retrieval Augmented Generation (RAG)

コースを見る

演習の手順

  • 提供された eval_llmprompt_template を使って、LangSmith の QA 文字列評価器を作成します。
  • query に対する専門家の解答(ref_answer)と比較して、RAG の出力である predicted_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}")
コードを編集して実行