Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download tests/test_duplex.py from treble-technologies/ffasr: direct link, hf CLI and curl.
- Browser
- Download file 2.92 kB
-
https://huggingface.co/spaces/treble-technologies/ffasr/resolve/main/tests/test_duplex.py
- Command line
-
hf download hf://spaces/treble-technologies/ffasr/tests/test_duplex.py
-
curl -L -o test_duplex.py https://huggingface.co/spaces/treble-technologies/ffasr/resolve/main/tests/test_duplex.py
2.92 kB
| """Full-duplex board: interaction error math, ranking per condition, presets, charts.""" | |
| import pandas as pd | |
| import pytest | |
| import duplex_analytics | |
| import duplex_demo | |
| import duplex_results as dx | |
| from duplex_config import CONDITION_KEYS, metric_column | |
| def _row(model_id: str, **metrics: float) -> dict: | |
| """Row with the same value in both conditions for each given metric.""" | |
| row = {"model_id": model_id, "architecture": "End-to-end"} | |
| for metric, v in metrics.items(): | |
| for cond in CONDITION_KEYS: | |
| row[metric_column(metric, cond)] = str(v) | |
| return row | |
| _PERFECT = dict(pause_tor=0.0, turn_tor=1.0, bargein_tor=1.0, false_bargein=0.0, echo_stop=0.0) | |
| def test_interaction_error_inverts_success_rates(): | |
| assert dx.interaction_error(_row("a", **_PERFECT)) == 0.0 | |
| # Missing half the turn ends and half the barge-ins: (0.5 + 0.5) / 5 behaviours. | |
| half = dict(_PERFECT, turn_tor=0.5, bargein_tor=0.5) | |
| assert dx.interaction_error(_row("b", **half)) == pytest.approx(0.2) | |
| def test_missing_behaviour_ranks_last_without_a_rank(): | |
| partial = _row("someone/partial", pause_tor=0.0, turn_tor=1.0) | |
| frame = dx.build_table([partial, _row("good/agent", **dict(_PERFECT, pause_tor=0.5)), _row("best/agent", **_PERFECT)]) | |
| models = list(frame[dx.MODEL_COL]) | |
| assert "best/agent" in models[0] and "good/agent" in models[1] and "partial" in models[2] | |
| assert list(frame[dx.RANK_COL])[:2] == [1, 2] | |
| assert pd.isna(frame[dx.RANK_COL].iloc[2]) | |
| assert frame[dx.ERROR_COL].iloc[1] == 10.0 | |
| def test_ranking_follows_the_condition_view(): | |
| rows = duplex_demo.demo_rows() | |
| far = [r["model_id"] for r, _ in dx.ranked(rows, "farfield")] | |
| glasses = [r["model_id"] for r, _ in dx.ranked(rows, "glasses")] | |
| assert len(far) == len(rows) and sorted(far) == sorted(glasses) | |
| assert far != glasses | |
| def test_presets_pick_column_groups(): | |
| rows = duplex_demo.demo_rows() | |
| summary = dx.build_table(rows, preset=dx.PRESET_SUMMARY) | |
| behaviours = dx.build_table(rows, preset=dx.PRESET_BEHAVIORS) | |
| assert dx.DELTA_COL in summary.columns and dx.JSD_COL not in summary.columns | |
| assert set(dx.BEHAVIOR_COLS.values()) <= set(behaviours.columns) | |
| assert set(dx.build_table(rows, preset=dx.PRESET_ALL).columns) >= set(summary.columns) | set(behaviours.columns) | |
| def test_demo_rows_are_flagged(): | |
| assert dx.has_demo_rows(duplex_demo.demo_rows()) | |
| assert not dx.has_demo_rows([_row("someone/real", **_PERFECT)]) | |
| def test_every_chart_renders_with_and_without_data(): | |
| rows = duplex_demo.demo_rows() | |
| for view in ("all", "farfield", "glasses"): | |
| figs = duplex_analytics.all_figures(rows, view, 5, None) | |
| assert len(figs) == 7 | |
| picked = [rows[0]["model_id"], rows[3]["model_id"]] | |
| assert len(duplex_analytics.all_figures(rows, "all", 10, picked)) == 7 | |
| assert len(duplex_analytics.all_figures([], "all", 10, None)) == 7 | |