-
Notifications
You must be signed in to change notification settings - Fork 21
Always run entity fidelity #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JosephMarinier
wants to merge
3
commits into
main
Choose a base branch
from
joseph/always-run-entity-fidelity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # TTS Fidelity | ||
|
|
||
| > **Diagnostic Metric**: If the agent's spoken audio doesn't match what it intended to say, the user receives incorrect information regardless of how good the text reasoning was. | ||
|
|
||
| ## Overview | ||
|
|
||
| Audio-based metric that evaluates whether the assistant's **spoken audio** accurately represents the intended text, using Gemini for multimodal analysis. This metric evaluates the speech output regardless of how it was produced — whether by a separate TTS engine or generated directly by an audio-native model. Specifically, it checks that all words from the intended text are present (no missing words), no extra words were added (no insertions), words are spoken correctly (no substitutions), and key entities are accurately conveyed (dates, names, numbers, codes, addresses). | ||
|
|
||
| > [!NOTE] | ||
| > By default, this diagnostic metric is excluded. Enable it explicitly with `--metrics tts_fidelity` (or include it in a comma-separated `--metrics` list). | ||
|
|
||
| ### Capabilities Measured | ||
|
|
||
| - **Speech Synthesis**: Measures whether the TTS engine (cascade) or the model's direct audio generation (audio-native) accurately produces the intended text as spoken audio. | ||
|
|
||
| ## How It Works | ||
|
|
||
| ### Evaluation Method | ||
|
|
||
| - **Type**: Audio Judge (multimodal LLM with audio input) | ||
| - **Model**: Gemini 3 Flash | ||
| - **Granularity**: Per-turn (each assistant turn evaluated independently) | ||
|
|
||
| ### Input Data | ||
|
|
||
| Uses the following MetricContext fields: | ||
| - `audio_assistant_path`: Path to assistant-only audio file | ||
| - `intended_assistant_turns`: What the assistant intended to say | ||
|
|
||
| ### Evaluation Methodology | ||
|
|
||
| The judge compares intended text against spoken audio, focusing on: | ||
|
|
||
| - **TTS-critical entities**: Names, dates, times, codes, dollar amounts, flight numbers — these are the highest-priority items | ||
| - **Error types**: Missing words, added words, wrong words, entity errors | ||
|
|
||
| **Special handling:** | ||
| - Minor pronunciation variations that don't change meaning are acceptable | ||
| - Filler words (um, uh) that don't affect core content are ignored | ||
| - Interruption tags (e.g., `[likely cut off by user]`, `[assistant interrupts]`) are non-spoken metadata in the intended text — words in regions flagged by these tags as likely not spoken are not penalized | ||
| - Missing words at END of LAST turn only are not penalized (audio cutoff) | ||
|
|
||
| ### Scoring | ||
|
|
||
| - **Scale**: 0-1 (binary per turn) | ||
| - 1: High Fidelity — audio accurately says all words from intended text | ||
| - 0: Low Fidelity — missing, added, or wrong words detected | ||
| - **Normalization**: Already 0-1 scale | ||
| - **Aggregation**: Mean across all assistant turns | ||
|
|
||
| ## Example Output | ||
|
|
||
| ```json | ||
| { | ||
| "name": "tts_fidelity", | ||
| "score": 0.875, | ||
| "normalized_score": 0.875, | ||
| "details": { | ||
| "aggregation": "mean", | ||
| "num_turns": 7, | ||
| "num_evaluated": 7, | ||
| "per_turn_ratings": {"0": 1, "1": 1, "2": 1, "3": 0, "4": 1, "5": 1, "6": 1}, | ||
| "per_turn_explanations": { | ||
| "3": "Missing word: intended 'flight SW102' but audio said 'flight SW12'. Key entity error." | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Related Metrics | ||
|
|
||
| - [user_speech_fidelity.md](user_speech_fidelity.md) - Same metric for the user simulator side | ||
| - [faithfulness.md](faithfulness.md) - Faithfulness for the text layer: evaluates whether the assistant's responses are grounded in instructions, policies, and tool results | ||
| - [speakability.md](speakability.md) - Checks if text is voice-friendly (upstream concern) | ||
|
|
||
| ## Implementation Details | ||
|
|
||
| - **File**: `src/eva/metrics/diagnostic/tts_fidelity.py` | ||
| - **Class**: `TTSFidelityMetric` | ||
| - **Base Class**: `SpeechFidelityBaseMetric` → `AudioJudgeMetric` | ||
| - **Prompt**: `configs/prompts/judge.yaml` under `judge.tts_fidelity` | ||
| - **Configuration**: `audio_judge_model` (default: Gemini 3 Flash), `aggregation` (default: "mean") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,11 @@ | ||
| """Task completion metrics - measuring whether the agent accomplished the user's goal.""" | ||
|
|
||
| from . import agent_speech_fidelity # noqa | ||
| from . import agent_speech_fidelity_s2s # noqa | ||
| from . import faithfulness # noqa | ||
| from . import speech_fidelity # noqa | ||
| from . import task_completion # noqa | ||
|
|
||
| __all__ = [ | ||
| "agent_speech_fidelity", | ||
| "agent_speech_fidelity_s2s", | ||
| "faithfulness", | ||
| "speech_fidelity", | ||
| "task_completion", | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| """Agent speech fidelity metric for S2S models — entity-focused evaluation. | ||
| """Agent speech fidelity metric — entity-focused, pipeline-agnostic evaluation. | ||
|
|
||
| For S2S (speech-to-speech) models, there is no intended text to compare against. | ||
| Instead, this metric verifies that key entities spoken by the agent (from tool | ||
| Because S2S (speech-to-speech) models expose no intended text to compare against, | ||
| this metric instead verifies that key entities spoken by the agent (from tool | ||
| responses and user utterances) are accurate by sending a redacted conversation | ||
| trace alongside the agent audio to Gemini. | ||
| """ | ||
|
|
@@ -10,13 +10,15 @@ | |
| from typing import Any | ||
|
|
||
| from eva.metrics.base import MetricContext | ||
| from eva.metrics.registry import register_metric | ||
| from eva.metrics.speech_fidelity_base import SpeechFidelityBaseMetric | ||
| from eva.metrics.utils import aggregate_per_turn_scores, normalize_rating, resolve_turn_id | ||
| from eva.models.results import MetricScore | ||
|
|
||
|
|
||
| class AgentSpeechFidelityS2SMetric(SpeechFidelityBaseMetric): | ||
| """Audio-based entity fidelity metric for S2S agent speech. | ||
| @register_metric | ||
| class SpeechFidelityMetric(SpeechFidelityBaseMetric): | ||
| """Audio-based entity fidelity metric for agent speech. | ||
|
|
||
| Evaluates whether key entities (from tool responses and user utterances) are | ||
| spoken correctly by the agent, without requiring intended text. | ||
|
|
@@ -25,8 +27,8 @@ class AgentSpeechFidelityS2SMetric(SpeechFidelityBaseMetric): | |
| """ | ||
|
|
||
| name = "agent_speech_fidelity" | ||
| version = "v0.2" | ||
| description = "Audio-based evaluation of agent entity fidelity for S2S models" | ||
| version = "v0.4" | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In |
||
| description = "Audio-based evaluation of agent entity fidelity" | ||
| category = "accuracy" | ||
| role = "assistant" | ||
| rating_scale = (0, 1) | ||
|
|
@@ -63,7 +65,6 @@ async def compute(self, context: MetricContext) -> MetricScore: | |
| audio_b64 = self.encode_audio_segment(audio_segment) | ||
|
|
||
| prompt = self.get_judge_prompt( | ||
| prompt_key="s2s_user_prompt", | ||
| conversation_trace_formatted=trace_formatted, | ||
| expected_language=context.language_display_name, | ||
| ) | ||
|
|
@@ -145,7 +146,6 @@ async def compute(self, context: MetricContext) -> MetricScore: | |
| avg_rating = sum(valid_ratings) / len(valid_ratings) if valid_ratings else None | ||
|
|
||
| details: dict[str, Any] = { | ||
| "variant": "s2s", | ||
| "aggregation": self.aggregation, | ||
| "num_turns": num_turns, | ||
| "num_evaluated": len(valid_ratings), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.