メインコンテンツまでスキップ

人間によるフィードバックのクイックスタート

このクイックスタートでは、エンドユーザーからのフィードバックを収集し、開発者の注釈を追加し、専門家によるレビュー セッションを作成し、そのフィードバックを使用して 生成AI アプリの品質を評価する方法について説明します。

これは、ヒューマンフィードバックライフサイクルの次の手順をカバーしています。

  • MLflow トレースを使用して GenAI アプリをインストルメント化します。
  • エンドユーザーのフィードバックを収集します (この例では、エンドユーザーのフィードバックは SDK を使用してシミュレートされます)。
  • UI を通じて開発者のフィードバックをインタラクティブに追加します。
  • トレースと一緒にフィードバックを表示します。
  • 構造化された専門家によるレビューのためのラベリングセッションを作成します。
  • 専門家のフィードバックを使用して、アプリの品質を評価します。

このページのすべてのコードは、 サンプル ノートブックに含まれています。

前提 条件

  1. MLflow と必要なパッケージをインストールする

    Bash
    pip install --upgrade "mlflow[databricks]>=3.1.0" openai "databricks-connect>=16.1"
  2. MLflow エクスペリメントを作成するには、環境のセットアップに関するクイックスタートに従ってください。

手順 1: 簡単なアプリを作成してトレースする

まず、MLflow トレースで LLM を使用して、単純な GenAI アプリを作成します。

  1. OpenAI クライアントを初期化して、Databricks でホストされている LLM または OpenAI でホストされている LLM に接続します。

MLflow を使用して、Databricks でホストされている LLM に接続する OpenAI クライアントを取得します。利用可能な基盤モデルからモデルを選択します。

Python
import mlflow
from databricks.sdk import WorkspaceClient

# Enable MLflow's autologging to instrument your application with Tracing
mlflow.openai.autolog()

# Set up MLflow tracking to Databricks
mlflow.set_tracking_uri("databricks")
mlflow.set_experiment("/Shared/docs-demo")

# Create an OpenAI client that is connected to Databricks-hosted LLMs
w = WorkspaceClient()
client = w.serving_endpoints.get_open_ai_client()

# Select an LLM
model_name = "databricks-claude-sonnet-4"
  1. チャットボットアプリを定義します。

    Python
    # Create a RAG app with tracing
    @mlflow.trace
    def my_chatbot(user_question: str) -> str:
    # Retrieve relevant context
    context = retrieve_context(user_question)

    # Generate response using LLM with retrieved context
    response = client.chat.completions.create(
    model=model_name, # If using OpenAI directly, use "gpt-4o" or "gpt-3.5-turbo"
    messages=[
    {"role": "system", "content": "You are a helpful assistant. Use the provided context to answer questions."},
    {"role": "user", "content": f"Context: {context}\n\nQuestion: {user_question}"}
    ],
    temperature=0.7,
    max_tokens=150
    )
    return response.choices[0].message.content

    @mlflow.trace(span_type="RETRIEVER")
    def retrieve_context(query: str) -> str:
    # Simulated retrieval - in production, this would search a vector database
    if "mlflow" in query.lower():
    return "MLflow is an open-source platform for managing the end-to-end machine learning lifecycle. It provides tools for experiment tracking, model packaging, and deployment."
    return "General information about machine learning and data science."

    # Run the app to generate a trace
    response = my_chatbot("What is MLflow?")
    print(f"Response: {response}")

    # Get the trace ID for the next step
    trace_id = mlflow.get_last_active_trace_id()
    print(f"Trace ID: {trace_id}")

ステップ 2: エンドユーザーのフィードバックを収集する

ユーザーがアプリを操作するとき、親指を立てる/下向きにするボタンなどの UI 要素を通じてフィードバックを提供できます。このクイックスタートでは、SDK を直接使用して、否定的なフィードバックを提供するエンド ユーザーをシミュレートします。

Python
import mlflow
from mlflow.entities.assessment import AssessmentSource, AssessmentSourceType

# Simulate end-user feedback from your app
# In production, this would be triggered when a user clicks thumbs down in your UI
mlflow.log_feedback(
trace_id=trace_id,
name="user_feedback",
value=False, # False for thumbs down - user is unsatisfied
rationale="Missing details about MLflow's key features like Projects and Model Registry",
source=AssessmentSource(
source_type=AssessmentSourceType.HUMAN,
source_id="enduser_123", # Would be actual user ID in production
),
)

print("End-user feedback recorded!")

# In a real app, you would:
# 1. Return the trace_id with your response to the frontend
# 2. When user clicks thumbs up/down, call your backend API
# 3. Your backend would then call mlflow.log_feedback() with the trace_id

ステップ 3: UI でフィードバックを表示する

MLflow UI を起動して、フィードバック付きのトレースを確認します。

  1. MLflowエクスペリメントに移動します。
  2. [トレース] タブに移動します。
  3. トレースをクリックします。
  4. トレースの詳細ダイアログが表示されます。ダイアログの右側にある [評価 ] の下に、ユーザーが応答を [サムズ] falseマークしたことを示す user_feedback が表示されます。

人間による評価

ステップ 4: UI を使用して開発者の注釈を追加する

開発者は、独自のフィードバックやメモを UI に直接追加することもできます。

  1. [トレース ] タブで、トレースをクリックして開きます。

  2. 任意のスパンをクリックします (トレース レベルのフィードバックのルート スパンを選択します)。

  3. 右側の 「評価」 タブで、「 新しい評価を追加 」をクリックし、次の項目を入力します。

    • タイプ : Feedback または Expectation
    • 名前 : たとえば、"accuracy_score"。
    • : 評価。
    • 根拠 : オプションの説明。
  4. 作成 をクリックします。

ページを更新すると、新しい評価の列が [トレース] テーブルに表示されます。

ステップ 5: 専門家によるレビューのためにトレースを送信する

ステップ 2 のエンドユーザーからの否定的なフィードバックは、潜在的な品質問題を示していますが、本当に問題があるかどうかを確認し、正しい答えを提供できるのは、ドメインの専門家だけです。ラベル付けセッションを作成して、信頼できる専門家のフィードバックを取得します。

Python
import mlflow
from mlflow.genai.label_schemas import create_label_schema, InputCategorical, InputText
from mlflow.genai.labeling import create_labeling_session

# Define what feedback to collect
accuracy_schema = create_label_schema(
name="response_accuracy",
type="feedback",
title="Is the response factually accurate?",
input=InputCategorical(options=["Accurate", "Partially Accurate", "Inaccurate"]),
overwrite=True
)

ideal_response_schema = create_label_schema(
name="expected_response",
type="expectation",
title="What would be the ideal response?",
input=InputText(),
overwrite=True
)

# Create a labeling session
labeling_session = create_labeling_session(
name="quickstart_review",
label_schemas=[accuracy_schema.name, ideal_response_schema.name],
)

# Add your trace to the session
# Get the most recent trace from the current experiment
traces = mlflow.search_traces(
max_results=1 # Gets the most recent trace
)
labeling_session.add_traces(traces)

# Share with reviewers
print(f"Trace sent for review!")
print(f"Share this link with reviewers: {labeling_session.url}")

レビューアプリを使用する

エキスパートのレビュー担当者は、次の操作を実行できるようになりました。

  1. レビューアプリのURLを開きます。
  2. 質問と回答 (エンドユーザーのフィードバックを含む) でトレースを確認します。
  3. 応答が実際に正確かどうかを評価します。
  4. 必要に応じて、 expected_response で正しい答えを入力してください。
  5. 彼らの専門家による評価をグラウンドトゥルースとして提出してください。

次のように、MLflow 3 UI を使用してラベル付けセッションを作成することもできます。

  1. エクスペリメントページで、[ ラベリング] タブをクリックします。
  2. 左側にある 「セッション 」タブと 「スキーマ 」タブを使用して、新しいラベルスキーマを追加し、新しいセッションを作成します。

UI でラベル付けセッションを作成する方法。

ステップ 6: フィードバックを使用してアプリを評価する

専門家からフィードバックを提供したら、その expected_response ラベルを使用して、MLflow の Correctness スコアラーでアプリを評価します。

注記

この例では、評価にトレースを直接使用します。DatabricksMLflowアプリケーションでは、ラベル付きトレースを Evaluation データセットに追加して 、バージョンの追跡とリネージを提供することをお勧めします。評価セットの作成ガイドを参照してください。

Python
import mlflow
from mlflow.genai.scorers import Correctness

# Get traces from the labeling session
labeled_traces = mlflow.search_traces(
run_id=labeling_session.mlflow_run_id, # Labeling Sessions are MLflow Runs
)

# Evaluate your app against expert expectations
eval_results = mlflow.genai.evaluate(
data=labeled_traces,
predict_fn=my_chatbot, # The app we created in Step 1
scorers=[Correctness()] # Compares outputs to expected_response
)

正確性スコアラーは、アプリの出力を専門家が提供する expected_responseと比較し、専門家の期待との整合性に関する定量的なフィードバックを提供します。

人間による評価期待される応答

ノートブックの例

次のノートブックには、このページのすべてのコードが含まれています。

人間によるフィードバックのクイックスタート ノートブック

Open notebook in new tab

次のステップ

これらの推奨アクションとチュートリアルで旅を続けてください。

リファレンスガイド

このクイックスタートで説明されている概念と機能の詳細については、以下を参照してください。