moonshine-tiny-tr / README.md
ekremcet's picture
Make README standalone for ekremcet/moonshine-tiny-tr
37d2954 verified
|
Raw History Blame Contribute Delete
5.03 kB
---
language:
- tr
license: mit
base_model: UsefulSensors/moonshine-tiny
library_name: transformers
pipeline_tag: automatic-speech-recognition
tags:
- automatic-speech-recognition
- speech
- turkish
- moonshine
- onnx
- transformers.js
- webgpu
- wasm
- edge
- browser
---
# Moonshine Tiny TR (`ekremcet/moonshine-tiny-tr`)
A compact, browser-ready **Turkish Automatic Speech Recognition (ASR)** model built on the **Moonshine** encoder-decoder architecture (`MoonshineForConditionalGeneration`), distilled and optimized specifically for punctuated, capitalized Turkish speech.
- **20.0M parameters** (`d_model=288`, 6 encoder / 6 decoder layers, 8 attention heads)
- **`21.45 MB` total INT8 ONNX** (`8.05 MB` encoder + `13.40 MB` merged decoder) — runs **40×–90× faster than real time on CPU** (`RTF = 0.011–0.025`) and natively in the browser via [`@huggingface/transformers`](https://huggingface.co/docs/transformers.js) (WebGPU & WASM)
- **Variable-length raw 16 kHz audio input** (no fixed 30-second Whisper padding overhead)
- **Custom 8,192-vocab Turkish BPE tokenizer** (`1.9×–2.15×` fewer tokens per Turkish sentence than English Moonshine, with full support for `ç ğ ı İ ö ş ü`, apostrophes, and punctuation)
- **Full PyTorch + ONNX distribution:** Works out of the box with both Python `transformers` (`model.safetensors`) and browser/edge `Transformers.js` (`onnx/`)
## Benchmark Results (Sealed Turkish Test Sets)
Evaluated across four held-out Turkish benchmarks (`0` utterance overlap with training data). **Normalized WER/CER** applies Turkish-aware lowercasing (`İ→i`, `I→ı`) and strips punctuation; **Raw WER/CER** preserves exact capitalization, apostrophes, and punctuation.
| Sealed Test Split | Clips | Beam-4 Norm WER | Beam-4 Norm CER | Greedy Norm WER | Greedy Norm CER | Beam-4 Raw WER |
|---|---:|---:|---:|---:|---:|---:|
| **FLEURS-TR test** | 743 | **17.66%** | **5.20%** | 20.39% | 6.13% | 25.83% |
| **Common Voice 27 TR test** | 833 | **16.68%** | **4.76%** | 20.72% | 6.34% | 22.40% |
| **MediaSpeech-TR test** *(TV broadcast)* | 251 | **19.63%** | **6.70%** | 22.86% | 8.00% | 20.48% |
| **ISSAI Turkish test** | 796 | **18.65%** | **6.14%** | 22.13% | 7.61% | 18.85% |
- **CPU INT8 ONNX speed:** `~90–200 ms` end-to-end on an `8.16 s` Turkish clip (`RTF = 0.011–0.025`, 40×–90× real time).
- **Exact parity:** FP32 ONNX matches PyTorch greedy decoding token-for-token.
## Usage in the Browser (`@huggingface/transformers`)
```js
import { pipeline } from "@huggingface/transformers";
const transcriber = await pipeline(
"automatic-speech-recognition",
"ekremcet/moonshine-tiny-tr",
{
dtype: {
encoder_model: "q8",
decoder_model_merged: "q8",
},
device: "wasm", // or "webgpu"
}
);
// audio: Float32Array at 16 kHz mono (or audio URL)
const output = await transcriber(audio);
console.log(output.text);
```
## Usage in Python (`transformers`)
```python
import soundfile as sf
import torch
from transformers import MoonshineForConditionalGeneration, PreTrainedTokenizerFast
MODEL_ID = "ekremcet/moonshine-tiny-tr"
tokenizer = PreTrainedTokenizerFast.from_pretrained(MODEL_ID)
model = MoonshineForConditionalGeneration.from_pretrained(MODEL_ID).eval()
wav, sr = sf.read("sample_16k.wav", dtype="float32")
if wav.ndim > 1:
wav = wav.mean(axis=-1)
with torch.no_grad():
ids = model.generate(
input_values=torch.from_numpy(wav).unsqueeze(0),
max_new_tokens=180,
num_beams=4,
repetition_penalty=1.05,
no_repeat_ngram_size=5,
)
print(tokenizer.decode(ids[0], skip_special_tokens=True))
```
## Model Files
- `onnx/encoder_model_quantized.onnx` / `onnx/encoder_model_int8.onnx` (`8.05 MB`) — INT8/UINT8 quantized raw-waveform encoder
- `onnx/decoder_model_merged_quantized.onnx` / `onnx/decoder_model_merged_int8.onnx` (`13.40 MB`) — INT8/UINT8 quantized merged KV-cache decoder
- `onnx/encoder_model.onnx` (`31 MB`) & `onnx/decoder_model_merged.onnx` (`49 MB`) — FP32 ONNX weights
- `model.safetensors` (`77 MB`) — FP32 PyTorch weights
## Training & Distillation Summary
- **Initialization:** Pretrained acoustic front-end (`conv1`–`conv3` + 6 encoder layers) and 6 decoder transformer blocks transferred from `UsefulSensors/moonshine-tiny`, paired with a newly trained 8,192-vocab Turkish BPE tokenizer (`max_position_embeddings=512`).
- **Data & Distillation:** Trained on a balanced real-first corpus of open and synthetic Turkish speech (`Common Voice 27 TR`, `YODAS2 TR`, `Khan Academy TR`, `FLEURS-TR train`, `Alania CC-BY`, synthetic Turkish digits/names, plus agreement-gated Whisper-Large teacher-distilled punctuation labels on `ISSAI` and `MediaSpeech` train splits) with speed perturbation (`0.9×–1.1×`), narrowband 8 kHz microphone/codec simulation, background noise mixing (SNR 6–28 dB), gain jitter, and waveform time-masking, finalized via multi-checkpoint weight averaging.
- **License:** MIT (matching `UsefulSensors/moonshine-tiny`).