Notebooks
A
Arize AI
Evaluate Human Vs Ai Classifications

Evaluate Human Vs Ai Classifications

agentsllmsLlamaIndexarize-phoenixopenaitutorialsevalsllmopsai-monitoringaiengineeringprompt-engineeringdatasetsllm-evalai-observabilityllm-evaluationsmolagentslegacyanthropiclangchain

Open In Colab

phoenix logo
Docs | GitHub | Community

Human/GroundTruth Versus AI Evals

Arize provides tooling to evaluate LLM applications, including tools to determine whether AI answers match Human Groundtruth answers. In many Q&A systems its important to test the AI answer results as compared to Human answers prior to deployment. These help assess how often the answers are correctly generated by the AI system.

The purpose of this notebook is:

  • to evaluate the performance of an LLM-assisted Evals for AI vs Human answers
  • to provide an experimental framework for users to iterate and improve on the default classification template.

Install Dependencies and Import Libraries

[ ]
[3]
Matplotlib is building the font cache; this may take a moment.
/Users/jasonlopatecki/vs_projects/retr3/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm

Download the Dataset

We've crafted a dataset of common questions and answers about the Arize platform.

[4]

Vizualization of Prompts/Templates Evals in Phoenix (Optional Section)

Visualization of Evals is not required but can be helpful to see the actual calls to the LLM. The link below starts the Phoenix UI/server and is a link to Phoenix running locally

[ ]
🌍 To view the Phoenix app in your browser, visit http://localhost:6006/
📖 For more information on how to use Phoenix, check out https://arize.com/docs/phoenix

Human vs AI Template

View the default template used to evaluate the AI answers.

[6]

You are comparing a human ground truth answer from an expert to an answer from an AI model.
Your goal is to determine if the AI answer correctly matches, in substance, the human answer.
    [BEGIN DATA]
    ************
    [Question]: {question}
    ************
    [Human Ground Truth Answer]: {correct_answer}
    ************
    [AI Answer]: {ai_generated_answer}
    ************
    [END DATA]
Compare the AI answer to the human ground truth answer, if the AI correctly answers the question,
then the AI answer is "correct". If the AI answer is longer but contains the main idea of the
Human answer please answer "correct". If the AI answer diverges or does not contain the main
idea of the human answer, please answer "incorrect".

The template variables are:

  • question: the question asked by a user
  • correct_answer: human labeled correct answer
  • ai_answer: AI generated answer

Configure the LLM

Configure your OpenAI API key.

[7]

LLM Evals:Human Groundtruth vs AI GPT-4

Run Human vs AI Eval against a subset of the data. Instantiate the LLM and set parameters.

[8]
The `model_name` field is deprecated. Use `model` instead.                 This will be removed in a future release.
[9]
"Hello! I'm working perfectly. How can I assist you today?"

Classifications with explanations

When evaluating a dataset for relevance, it can be useful to know why the LLM classified an AI answer as relevant or irrelevant. The following code block runs llm_classify with explanations turned on so that we can inspect why the LLM made the classification it did. There is speed tradeoff since more tokens is being generated but it can be highly informative when troubleshooting.

[10]
llm_classify |██████████| 119/119 (100.0%) | ⏳ 00:24<00:00 |  4.77it/s

Evaluate Classifications

Evaluate the predictions against human-labeled ground-truth relevance labels.

[11]
              precision    recall  f1-score   support

     correct       0.93      0.72      0.81        78
   incorrect       0.61      0.92      0.73        39

   micro avg       0.77      0.79      0.78       117
   macro avg       0.77      0.82      0.77       117
weighted avg       0.83      0.79      0.79       117

<Axes: title={'center': 'Confusion Matrix (Normalized)'}, xlabel='Predicted Classes', ylabel='Actual Classes'>
Output

LLM Evals: Human Groundtruth vs AI Classifications GPT-3.5 Turbo

Run against a subset of the data using GPT-3.5. GPT-3.5 can significantly speed up the classification process. However there are tradeoffs as we will see below.

[12]
The `model_name` field is deprecated. Use `model` instead.                 This will be removed in a future release.
[13]
llm_classify |██████████| 119/119 (100.0%) | ⏳ 00:21<00:00 |  5.45it/s
[14]
[15]
[16]
              precision    recall  f1-score   support

     correct       0.72      0.81      0.76        78
   incorrect       0.48      0.38      0.43        39

   micro avg       0.66      0.67      0.66       117
   macro avg       0.60      0.60      0.59       117
weighted avg       0.64      0.67      0.65       117

<Axes: title={'center': 'Confusion Matrix (Normalized)'}, xlabel='Predicted Classes', ylabel='Actual Classes'>
Output

Preview: Running with GPT-4 Turbo

[17]
The `model_name` field is deprecated. Use `model` instead.                 This will be removed in a future release.
llm_classify |██████████| 119/119 (100.0%) | ⏳ 00:18<00:00 |  6.30it/s
[18]
              precision    recall  f1-score   support

     correct       0.87      0.69      0.77        78
   incorrect       0.56      0.82      0.67        39

   micro avg       0.72      0.74      0.73       117
   macro avg       0.72      0.76      0.72       117
weighted avg       0.77      0.74      0.74       117

<Axes: title={'center': 'Confusion Matrix (Normalized)'}, xlabel='Predicted Classes', ylabel='Actual Classes'>
Output