matthiastl's picture
Smart Turn v3.2 fine-tuned for phone lines: ONNX and PyTorch weights, with tests and scripts
6daf493
|
Raw History Blame Contribute Delete
4.82 kB
# Scripts
The working copies of the code that produced the files and numbers in this repository. They are
here as a record and to let you retrain or re-test; using the model needs none of them.
Run them from this folder. They use the `inworld-sava` package (Apache-2.0) for audio loading and
the mel filterbank, and `bench.py` and `calls.py` can also score SAVA models.
```bash
uv venv --python 3.12
uv pip install inworld-sava onnx onnxruntime onnxscript pytest pyarrow scikit-learn scipy soundfile safetensors
# Pipecat's Smart Turn v3.2: the starting point and the comparison.
hf download pipecat-ai/smart-turn-v3 smart-turn-v3.2-gpu.onnx --local-dir data/smartturn
.venv/bin/python -I -m pytest test_smartturn.py test_channels.py
# Fine-tune: 9 training files, one more held out to choose the checkpoint (5 GB in all).
hf download pipecat-ai/smart-turn-data-v3.2-train --repo-type dataset \
--include "data/train-0000[0-9]-of-00083.parquet" --local-dir data/pipecat-train
.venv/bin/python -I finetune_smartturn.py --onnx data/smartturn/smart-turn-v3.2-gpu.onnx \
--train data/pipecat-train/data/train-0000[0-8]-of-00083.parquet \
--validation data/pipecat-train/data/train-00009-of-00083.parquet \
--validation-clips 1000 --out runs/smartturn-phone-1
# Export the chosen checkpoint.
.venv/bin/python -I smartturn.py runs/smartturn-phone-1/best.safetensors build/smart-turn-telephony.onnx
# Score both models on pipecat's test set, clean and through both lines, then compare clip for clip.
hf download pipecat-ai/smart-turn-data-v3.2-test --repo-type dataset --local-dir data/pipecat
.venv/bin/python -I bench.py pipecat --root data/pipecat --out results/smartturn \
--smart-turn data/smartturn/smart-turn-v3.2-gpu.onnx --conditions clean phone gsm
.venv/bin/python -I bench.py pipecat --root data/pipecat --out results/smartturn-phone-1 \
--smart-turn build/smart-turn-telephony.onnx --conditions clean phone gsm
.venv/bin/python -I compare.py results/smartturn-phone-1 results/smartturn --pairs smart_turn_telephony:smart_turn
.venv/bin/python -I compare_pairs.py real --results results/smartturn-phone-1 results/smartturn \
--system smart_turn_telephony --baseline smart_turn --out results/real-recordings.json
# Real calls: the pause test. The dataset is gated: accept its terms on its page first.
hf download talkbank/callhome eng/data-00000-of-00005.parquet --repo-type dataset --local-dir data/callhome
.venv/bin/python -I calls.py score --data data/callhome/eng/data-00000-of-00005.parquet --no-original \
--smart-turn data/smartturn/smart-turn-v3.2-gpu.onnx --out results/callhome-smartturn
.venv/bin/python -I calls.py score --data data/callhome/eng/data-00000-of-00005.parquet --no-original \
--smart-turn build/smart-turn-telephony.onnx --out results/callhome-smartturn-phone-1
.venv/bin/python -I compare_pairs.py pauses --calls results/callhome-smartturn-phone-1 \
--baseline-calls results/callhome-smartturn --system smart_turn_telephony --baseline smart_turn \
--out results/real-calls-pauses.json
```
| Script | What it does |
|---|---|
| `smartturn.py` | Smart Turn v3 in plain PyTorch: loads the weights from pipecat's ONNX file or from safetensors, computes the input features, exports to ONNX |
| `finetune_smartturn.py` | trains a copy to answer on phone-line audio as the original answers on clean audio; no labels |
| `channels.py` | the simulated phone lines: the random family used in training, and the fixed `phone` and `gsm` lines used in tests |
| `telephony.py` | the `phone` line: 8 kHz, 300-3400 Hz, G.711 mu-law |
| `bench.py` | `bench.py pipecat --smart-turn FILE` scores a Smart Turn ONNX file on pipecat's test set the way pipecat's inference code runs it, on any of the lines |
| `compare.py` | joins `bench.py` results by clip and prints accuracies and paired differences with bootstrap intervals |
| `compare_pairs.py` | the paired numbers on the real recordings only, and the paired real-call pause test |
| `calls.py` | scores models on real phone calls (CallHome English) at pauses where the other person or the same person speaks next |
| `test_smartturn.py` | checks the rebuild and the export against pipecat's file |
| `test_channels.py` | checks the simulated lines keep the audio's length and timing |
| `check_release.py` | scans a folder, model files included, for the local machine's paths and user name before it is published |
The run behind this repository was started under `taskpolicy -b` with
`PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.15 PYTORCH_MPS_LOW_WATERMARK_RATIO=0.1`, to share the machine.
Those change speed, not results. Pipecat's own scores were made by the same `bench.py` code in two
earlier runs (wideband and landline, then GSM); re-scoring a sample with the current code gives
the same values.