Multimodal Evaluation: Images, Audio, and PDF

Run Future AGI's built-in image, audio, and PDF eval metrics from the SDK or the dashboard.

📝
TL;DR

Score image captions, detect AI-generated images, evaluate audio quality and TTS accuracy, and verify OCR output against source PDFs using built-in multimodal eval metrics.

Open in ColabGitHub
TimeDifficultyPackage
10 minIntermediateai-evaluation
Prerequisites

Install

pip install ai-evaluation
export FI_API_KEY="your-api-key"
export FI_SECRET_KEY="your-secret-key"

Tutorial

Set up the Evaluator

import os
from fi.evals import Evaluator

evaluator = Evaluator(
    fi_api_key=os.environ["FI_API_KEY"],
    fi_secret_key=os.environ["FI_SECRET_KEY"],
)

You should see no output. evaluator is ready to score any of the templates below.

Detect caption hallucination

Check whether a caption accurately describes an image. Pass the image as a URL (or base64) and the caption as text.

result = evaluator.evaluate(
    eval_templates="caption_hallucination",
    inputs={
        "image": "https://raw.githubusercontent.com/future-agi/cookbooks/main/ecom_agent/observe/generated_products/nike_air_max_sneakers.png",
        "caption": "A pair of white sneakers with a wavy sole design.",
    },
    model_name="turing_small",
)

eval_result = result.eval_results[0]
print(f"Passed: {eval_result.output}")
print(f"Reason: {eval_result.reason}")

You should see a passing verdict and a reason confirming the caption matches the sneaker image. Now try a caption that describes something else entirely:

result = evaluator.evaluate(
    eval_templates="caption_hallucination",
    inputs={
        "image": "https://raw.githubusercontent.com/future-agi/cookbooks/main/ecom_agent/observe/generated_products/nike_air_max_sneakers.png",
        "caption": "A red leather handbag with gold buckles on a wooden table.",
    },
    model_name="turing_small",
)

eval_result = result.eval_results[0]
print(f"Passed: {eval_result.output}")
print(f"Reason: {eval_result.reason}")

This time the verdict flips to failing. The reason explains what the caption claims that the image doesn’t show.

Detect AI-generated images

Score whether an image was generated by AI or is a real photograph.

result = evaluator.evaluate(
    eval_templates="synthetic_image_evaluator",
    inputs={
        "image": "https://raw.githubusercontent.com/future-agi/cookbooks/main/ecom_agent/observe/generated_products/nike_air_max_sneakers.png",
    },
    model_name="turing_small",
)

eval_result = result.eval_results[0]
print(f"Score:  {eval_result.output}")
print(f"Reason: {eval_result.reason}")

You should see a numeric score plus a reason describing the visual cues the model used.

Evaluate audio quality

Get a Mean Opinion Score (MOS) assessment of audio quality. Pass the audio file as a URL or base64.

Warning

audio_quality and ocr_evaluation require model_name="turing_large". Calling either with a smaller model returns an unsupported-model error.

result = evaluator.evaluate(
    eval_templates="audio_quality",
    inputs={
        "input_audio": "https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.flac",
    },
    model_name="turing_large",
)

eval_result = result.eval_results[0]
print(f"Score:  {eval_result.output}")
print(f"Reason: {eval_result.reason}")

You should see a MOS-style score and a reason noting artifacts like noise or clipping, if any.

Evaluate text-to-speech accuracy

Check whether a TTS audio output accurately reflects the original text, including pronunciation, emphasis, and tone.

result = evaluator.evaluate(
    eval_templates="TTS_accuracy",
    inputs={
        "text": "Welcome to Future AGI. Our platform helps you evaluate and optimize AI applications.",
        "generated_audio": "https://storage.googleapis.com/cloud-samples-data/speech/brooklyn_bridge.flac",
    },
    model_name="turing_large",
)

eval_result = result.eval_results[0]
print(f"Score:  {eval_result.output}")
print(f"Reason: {eval_result.reason}")

You should see a score and a reason comparing the spoken audio against the source text.

Evaluate OCR output against a PDF

Score how accurately OCR-extracted content matches the source PDF document. Substitute input_pdf with a publicly reachable URL to your own PDF, and json_content with the fields you expect the OCR pass to have extracted from it.

result = evaluator.evaluate(
    eval_templates="ocr_evaluation",
    inputs={
        "input_pdf": "https://your-public-url.example.com/your-document.pdf",
        "json_content": '{"invoice_number": "INV-2024-001", "total": "$1,250.00", "date": "2024-03-15"}',
    },
    model_name="turing_large",
)

eval_result = result.eval_results[0]
print(f"Score:  {eval_result.output}")
print(f"Reason: {eval_result.reason}")

You should see a score and a reason listing which fields matched or diverged from the PDF, based on the document and fields you supplied.

Run multimodal evals from the dashboard

You can also run these evals directly from the Future AGI platform without writing any code.

  1. Go to Datasets and create or open a dataset
  2. Add columns for your multimodal inputs, for example an image column with image URLs, or an audio column with audio URLs
  3. Click Add Evaluation and select a multimodal eval, for example caption_hallucination or audio_quality
  4. Map the eval’s required keys to your dataset columns, for example image to your image column and caption to your caption column
  5. Choose a Turing model and click Run
  6. View scores alongside each row in the dataset

This is the same approach shown in the Dataset SDK cookbook, but with multimodal columns instead of text-only.

Troubleshooting

SymptomCauseFix
Evaluator() raises a missing-credentials errorFI_API_KEY or FI_SECRET_KEY isn’t exported before the script runsExport both keys, or pass fi_api_key/fi_secret_key directly to Evaluator()
audio_quality or ocr_evaluation returns an unsupported-model errorCalled with model_name="turing_small" instead of turing_largeUse model_name="turing_large" for these evals
caption_hallucination or synthetic_image_evaluator comes back empty or errorsThe image URL isn’t publicly reachable, for example a private bucket or an expired signed URLUse a publicly accessible URL, or pass the image as base64
ocr_evaluation scores low even on a correct extractionjson_content isn’t valid JSON, for example a trailing comma or an unescaped quoteValidate the string with json.loads() before passing it in
TTS_accuracy or audio_quality times out on a long clipThe input audio runs several minutes and the evaluation model processes it in fullTrim the clip to the relevant segment before scoring
result.eval_results[0] is NoneThat row failed to evaluate, usually a bad input URL or an unsupported file typeCheck the entry for None before reading .output or .reason, and re-check the input for that row

Next up

Ready to score plain text next? See Running Your First Eval for text evals and LLM-as-Judge.

Was this page helpful?

Questions & Discussion