Datasets:
File size: 6,500 Bytes
df7317f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #!/usr/bin/env bash
# add_system.sh: score one more TTS system on Nanori with the frozen judges and the official rule R2, and place it next
# to the published systems (same items, judges, rule and bootstrap seeds).
#
# bash scripts/add_system.sh --key KEY --label LABEL (--wav-dir DIR | --fish-model MODEL [--voice VOICE_ID] [--language LANG])
# [--dataset-dir DIR] [--work-dir DIR] [--toolkit JOYO_DIR] [--ctc-dir DIR] [--max-usd USD]
# [--gemini-raw FILE]... [--kw PATH]... [--ctc PATH]... [--clip-prefix PREFIX] [--reference KEY]
#
# --key, --label system key (part of the bootstrap seed of its pairs) and display name
# --wav-dir your clips, one per item, as DIR/<subset>/<item_id>.wav (16-bit PCM, any rate)
# --fish-model synthesize with the Fish Audio TTS API instead (model id sent in the `model` header; key from
# FISH_API_KEY, never logged); --voice defaults to the leaderboard voice (stock voice Kyoko)
# --dataset-dir local copy of the repository root, with the item tables, known_wrong/ and results/
# (default: the folder that holds eval/)
# --work-dir where the runs go (default: runs); outputs in WORK/KEY/
# --toolkit Joyo-Kanji-Yomi-Benchmark checkout at 6a79976c (needed by the kana-whisper judge)
# --ctc-dir folder with the CTC model files (default: downloaded by id + revision + sha256)
# --max-usd cap of the Gemini judge spend (default 45; one system costs about 35-39 USD at K = 3)
# --gemini-raw / --kw / --ctc
# judge outputs you already have for these clips (repeatable); a judge whose outputs are given is
# not run, so with all three the script makes no API call and downloads no model
# --clip-prefix clip ids are PREFIX__<subset>__<item_id> (default: KEY); set it to reuse judge outputs that were
# made under another name
# --reference system the new pairs are taken against (default: s21pro)
#
# Steps: synthesize (or take the WAVs) -> manifest -> judge-gemini (K = 3, OpenRouter -> Vertex, OPENROUTER_API_KEY)
# -> judge-kw (CPU fp32) -> judge-ctc (CPU fp32) -> combine (R2) -> score KEY together with the published per-item
# verdicts of results/per_item/ (pairs: every published pair + KEY - reference). Outputs: WORK/KEY/verdicts.jsonl,
# WORK/KEY/score/{leaderboard.json, LEADERBOARD.md, RESULTS_FULL.md}; the published systems' numbers in that output
# are checked against results/leaderboard.json. Commands: $NANORI_EVAL (default nanori-eval), $PYTHON (default python3).
set -euo pipefail
usage() { sed -n '2,30p' "$0" | sed 's/^# \{0,1\}//'; }
die() { echo "add_system: $*" >&2; exit 2; }
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NE="${NANORI_EVAL:-nanori-eval}"
PY="${PYTHON:-python3}"
HELP="$HERE/add_system_helpers.py"
KEY="" LABEL="" WAVDIR="" FISH_MODEL="" VOICE="" LANG="" DSET="$(cd "$HERE/../.." && pwd)" WORK="runs" TK="" CTCDIR=""
MAXUSD=45 PREFIX="" REF="s21pro"
GEM=() KWR=() CTCR=()
while [ $# -gt 0 ]; do
case "$1" in
--key) KEY="$2"; shift 2 ;;
--label) LABEL="$2"; shift 2 ;;
--wav-dir) WAVDIR="$2"; shift 2 ;;
--fish-model) FISH_MODEL="$2"; shift 2 ;;
--voice) VOICE="$2"; shift 2 ;;
--language) LANG="$2"; shift 2 ;;
--dataset-dir) DSET="$2"; shift 2 ;;
--work-dir) WORK="$2"; shift 2 ;;
--toolkit) TK="$2"; shift 2 ;;
--ctc-dir) CTCDIR="$2"; shift 2 ;;
--max-usd) MAXUSD="$2"; shift 2 ;;
--gemini-raw) GEM+=("$2"); shift 2 ;;
--kw) KWR+=("$2"); shift 2 ;;
--ctc) CTCR+=("$2"); shift 2 ;;
--clip-prefix) PREFIX="$2"; shift 2 ;;
--reference) REF="$2"; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) die "unknown option $1 (see --help)" ;;
esac; done
[ -n "$KEY" ] && [ -n "$LABEL" ] || die "--key and --label are required"
[[ "$KEY" =~ ^[a-z0-9_]+$ ]] || die "--key: lower-case letters, digits and _ only"
if { [ -n "$WAVDIR" ] && [ -n "$FISH_MODEL" ]; } || { [ -z "$WAVDIR" ] && [ -z "$FISH_MODEL" ]; }; then
die "give exactly one of --wav-dir and --fish-model"; fi
[ -d "$DSET/known_wrong" ] && [ -f "$DSET/results/leaderboard.json" ] \
|| die "--dataset-dir must be the repository root (known_wrong/ and results/ next to the item tables)"
[ ${#KWR[@]} -gt 0 ] || [ -n "$TK" ] || die "the kana-whisper judge needs --toolkit (or pass --kw outputs)"
PREFIX="${PREFIX:-$KEY}"
W="$WORK/$KEY"
mkdir -p "$W"
W="$(cd "$W" && pwd)"
SRC=(--data "$DSET") # the item source option of every nanori-eval command
# 1. audio
if [ -n "$FISH_MODEL" ]; then
VA=(); [ -n "$VOICE" ] && VA+=(--voice "$VOICE")
[ -n "$LANG" ] && VA+=(--language "$LANG")
"$NE" synth "${SRC[@]}" --adapter fish --model "$FISH_MODEL" "${VA[@]}" --system "$PREFIX" --out "$W/audio" \
--max-chars 30000
WAVDIR="$W/audio"
fi # end of the synthesis step
# 2. manifest (clip ids PREFIX__<subset>__<item_id>)
"$NE" manifest "${SRC[@]}" --audio-dir "$WAVDIR" --system "$PREFIX" --out "$W/manifest.jsonl"
MAN="$W/manifest.jsonl"
echo "add_system: $(wc -l < "$MAN") clips in the manifest"
# 3. judges (skipped when their outputs are given)
if [ ${#GEM[@]} -eq 0 ]; then
"$NE" judge-gemini "${SRC[@]}" --manifest "$MAN" --run-dir "$W/gemini" --max-usd "$MAXUSD"
GEM=("$W/gemini/raw.jsonl")
fi # Gemini judge step
if [ ${#KWR[@]} -eq 0 ]; then
"$NE" judge-kw "${SRC[@]}" --manifest "$MAN" --run-dir "$W/kw" --toolkit "$TK"
KWR=("$W/kw/kw.jsonl")
fi # kana-whisper judge step
if [ ${#CTCR[@]} -eq 0 ]; then
CA=(); [ -n "$CTCDIR" ] && CA=(--ctc-dir "$CTCDIR")
"$NE" judge-ctc "${SRC[@]}" --manifest "$MAN" --run-dir "$W/ctc" "${CA[@]}"
CTCR=("$W/ctc")
fi # kana CTC judge step
# 4. combine with the official rule R2
"$NE" combine "${SRC[@]}" --manifest "$MAN" --gemini-raw "${GEM[@]}" --kw "${KWR[@]}" --ctc "${CTCR[@]}" \
--out "$W/verdicts.jsonl" > "$W/combine.log"
"$PY" -I "$HELP" summary "$W/verdicts.jsonl.summary.json"
# 5. the published per-item verdicts as combine rows, then score everything together
"$PY" -I "$HELP" published "$DSET/results" "$W/published" "$KEY" "$REF" > "$W/score_args.txt"
mapfile -t SA < "$W/score_args.txt"
"$NE" score "${SRC[@]}" "${SA[@]}" --system "$KEY:$LABEL=$W/verdicts.jsonl" --reference "$REF" \
--out-dir "$W/score" > /dev/null
# 6. the published numbers must be unchanged by the addition
"$PY" -I "$HELP" check "$DSET/results/leaderboard.json" "$W/score/leaderboard.json" "$KEY"
echo "add_system: wrote $W/verdicts.jsonl and $W/score/"
|