Download analysis/common/_voice_synth_alignment.py from sciminds/same-words-different-judgements: direct link, hf CLI and curl.
- Browser
- Download file 3.15 kB
-
https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/analysis/common/_voice_synth_alignment.py
- Command line
-
hf download hf://datasets/sciminds/same-words-different-judgements/analysis/common/_voice_synth_alignment.py
-
curl -L -o _voice_synth_alignment.py https://huggingface.co/datasets/sciminds/same-words-different-judgements/resolve/main/analysis/common/_voice_synth_alignment.py
3.15 kB
| """Synthetic-rating alignment per TTS voice (Table 12). | |
| python analysis/06_voice_study/06_synth_alignment.py | |
| For each (voice, synthetic rater): per-clip mean synthetic rating against | |
| per-clip mean human rating, over the 60 clips of the 30 voice-study prompts. | |
| Pearson r, Spearman rho, MAE, and mean signed difference (synthetic − human; | |
| positive = synthetic rater above human). | |
| Human means come from the analyzed rater set (attention-check exclusions | |
| applied): the new voice arms from long_voice_normalized.csv, the af_heart | |
| baseline from the main study's long_audio_table_normalized.csv restricted to | |
| the same 30 prompts. Synthetic means average the 10 draws per clip; the | |
| baseline draws are the main study's runs (data/main_study/synth_long_audio_*), the | |
| new voice arms the re-rendered runs in data/voice_study/synth/. | |
| """ | |
| from __future__ import annotations | |
| from pathlib import Path | |
| import pandas as pd | |
| from scipy import stats | |
| ROOT = Path(__file__).resolve().parent.parent.parent | |
| VOICE_DATA = ROOT / "data/voice_study" | |
| CONTEXT_DATA = ROOT / "data/audio_context_study" | |
| DERIVED = ROOT / "results/06_voice_study" | |
| SD = ROOT / "data/main_study" | |
| MODELS = ["gpt4o", "gemini_36_flash", "qwen35_omni_flash"] | |
| ARMS = ["kokoro_am_michael", "chatterbox", "qwen3tts_serena"] | |
| def clip_means(df: pd.DataFrame) -> pd.Series: | |
| return df.groupby("AudioClip")["Rating"].mean() | |
| def align(h: pd.Series, s: pd.Series) -> dict | None: | |
| m = pd.concat([h.rename("h"), s.rename("s")], axis=1).dropna() | |
| if len(m) < 3: | |
| return None | |
| return dict(clips=len(m), | |
| r=stats.pearsonr(m.h, m.s)[0], | |
| rho=stats.spearmanr(m.h, m.s)[0], | |
| mae=(m.s - m.h).abs().mean(), | |
| signed=(m.s - m.h).mean()) | |
| def main() -> None: | |
| prompts = set(pd.read_csv(ROOT / "stimuli/voice_study/prompts.csv")["PromptID"]) | |
| human = {} | |
| voice = pd.read_csv(VOICE_DATA / "long_voice_normalized.csv") | |
| for arm, g in voice.groupby("Arm"): | |
| human[arm] = clip_means(g) | |
| base = pd.read_csv(SD / "long_audio_table_normalized.csv") | |
| base = base[~base["IsAttentionCheck"].astype(bool)] | |
| base = base[base["PromptID"].isin(prompts)] | |
| human["kokoro_af_heart (baseline)"] = clip_means(base) | |
| rows = [] | |
| for voice_name, h in human.items(): | |
| for model in MODELS: | |
| if "baseline" in voice_name: | |
| path = SD / f"synth_long_audio_table_{model}.csv" | |
| else: | |
| path = (VOICE_DATA / "synth" / | |
| f"synth_long_audio_table_{voice_name}_{model}.csv") | |
| if not path.exists(): | |
| continue | |
| s = pd.read_csv(path) | |
| s = s[s["PromptID"].astype(str).isin(prompts)] | |
| res = align(h, clip_means(s)) | |
| if res: | |
| rows.append(dict(voice=voice_name, rater=model, **res)) | |
| out = pd.DataFrame(rows) | |
| print(out.to_string(index=False, float_format=lambda v: f"{v:.3f}")) | |
| out.to_csv(DERIVED / "synth_alignment_by_voice.csv", index=False) | |
| print(f"\n -> results/06_voice_study/synth_alignment_by_voice.csv") | |
| if __name__ == "__main__": | |
| main() | |