Update README.md
Browse files
README.md
CHANGED
|
@@ -1,199 +1,291 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
library_name: transformers
|
| 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 |
-
- **Paper [optional]:** [More Information Needed]
|
| 34 |
-
- **Demo [optional]:** [More Information Needed]
|
| 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 |
-
|
| 120 |
|
| 121 |
-
|
| 122 |
|
| 123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
|
| 125 |
-
|
| 126 |
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
|
| 131 |
-
###
|
| 132 |
|
|
|
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
-
|
| 140 |
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
| 142 |
|
| 143 |
-
|
| 144 |
|
| 145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
#### Software
|
| 168 |
-
|
| 169 |
-
[More Information Needed]
|
| 170 |
-
|
| 171 |
-
## Citation [optional]
|
| 172 |
-
|
| 173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
| 174 |
-
|
| 175 |
-
**BibTeX:**
|
| 176 |
-
|
| 177 |
-
[More Information Needed]
|
| 178 |
-
|
| 179 |
-
**APA:**
|
| 180 |
-
|
| 181 |
-
[More Information Needed]
|
| 182 |
-
|
| 183 |
-
## Glossary [optional]
|
| 184 |
-
|
| 185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
-
|
| 187 |
-
[More Information Needed]
|
| 188 |
-
|
| 189 |
-
## More Information [optional]
|
| 190 |
-
|
| 191 |
-
[More Information Needed]
|
| 192 |
-
|
| 193 |
-
## Model Card Authors [optional]
|
| 194 |
-
|
| 195 |
-
[More Information Needed]
|
| 196 |
-
|
| 197 |
-
## Model Card Contact
|
| 198 |
-
|
| 199 |
-
[More Information Needed]
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model:
|
| 3 |
+
- Qwen/Qwen3-4B-Instruct-2507
|
| 4 |
library_name: transformers
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
tags:
|
| 7 |
+
- audio
|
| 8 |
+
- speech
|
| 9 |
+
- audio-codec
|
| 10 |
+
- neural-audio-codec
|
| 11 |
+
- spoken-language-modeling
|
| 12 |
+
- codec-superb
|
| 13 |
+
- qwen3
|
| 14 |
+
datasets:
|
| 15 |
+
- librispeech_asr
|
| 16 |
+
metrics:
|
| 17 |
+
- perplexity
|
| 18 |
+
- pesq
|
| 19 |
+
- stoi
|
| 20 |
---
|
| 21 |
|
| 22 |
+
# LLM-Codec
|
| 23 |
|
| 24 |
+
LLM-Codec is a neural audio codec checkpoint trained to produce discrete audio
|
| 25 |
+
tokens that are both reconstructable and easier for autoregressive language
|
| 26 |
+
models to predict.
|
| 27 |
|
| 28 |
+
Model: https://huggingface.co/voidful/llm-codec
|
| 29 |
|
| 30 |
+
Code: https://github.com/voidful/llm-codec
|
| 31 |
|
| 32 |
+
Usage reference: https://github.com/voidful/Codec-SUPERB
|
| 33 |
|
| 34 |
+
## Model Description
|
| 35 |
|
| 36 |
+
Most neural audio codecs are trained for waveform reconstruction. Spoken
|
| 37 |
+
language models, however, consume codec tokens with a next-token prediction
|
| 38 |
+
objective. This mismatch can make acoustically valid variation appear as token
|
| 39 |
+
uncertainty to the language model.
|
| 40 |
|
| 41 |
+
LLM-Codec adapts a codec with language-model-facing objectives while keeping the
|
| 42 |
+
deployed codec interface unchanged. The model is trained with:
|
| 43 |
|
| 44 |
+
- Future Token Prediction (FTP): Medusa-style heads predict future audio tokens
|
| 45 |
+
from frozen-LLM hidden states.
|
| 46 |
+
- Semantic Alignment (SA): audio-induced hidden states are aligned with paired
|
| 47 |
+
text hidden states inside a frozen LLM.
|
| 48 |
+
- Differentiable Gumbel bridge: hard Gumbel-Softmax keeps discrete forward
|
| 49 |
+
tokens while enabling gradients to flow to the codec encoder.
|
| 50 |
+
- Reconstruction losses: mel, multi-scale mel, multi-resolution STFT, complex
|
| 51 |
+
STFT, VQ, GAN, and feature matching losses.
|
| 52 |
|
| 53 |
+
The deployed codec does not require the auxiliary FTP heads.
|
| 54 |
|
| 55 |
+
## Intended Use
|
| 56 |
|
| 57 |
+
This model is intended for research and development in:
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
- audio tokenization for spoken language modeling
|
| 60 |
+
- codec reconstruction experiments
|
| 61 |
+
- token-level speech LM training
|
| 62 |
+
- Codec-SUPERB style codec evaluation
|
| 63 |
+
- speech token analysis and ablation studies
|
| 64 |
|
| 65 |
+
It is not a full text-to-speech system by itself. For speech generation, use the
|
| 66 |
+
codec as the tokenizer/decoder inside a separate speech language modeling
|
| 67 |
+
pipeline.
|
| 68 |
|
| 69 |
+
## Out-of-Scope Use
|
| 70 |
|
| 71 |
+
Do not use this model for:
|
| 72 |
|
| 73 |
+
- impersonation or unauthorized voice cloning
|
| 74 |
+
- surveillance or speaker tracking without consent
|
| 75 |
+
- high-stakes speaker, language, or identity decisions
|
| 76 |
+
- generating deceptive audio content
|
| 77 |
|
| 78 |
+
## Installation
|
| 79 |
|
| 80 |
+
The easiest inference path is through the Codec-SUPERB `SoundCodec` interface.
|
| 81 |
|
| 82 |
+
```bash
|
| 83 |
+
git clone https://github.com/voidful/Codec-SUPERB.git
|
| 84 |
+
cd Codec-SUPERB
|
| 85 |
+
pip install -r requirements.txt
|
| 86 |
+
export PYTHONPATH=$PWD:$PYTHONPATH
|
| 87 |
+
```
|
| 88 |
|
| 89 |
+
If your environment supports editable installs, this is also convenient:
|
| 90 |
|
| 91 |
+
```bash
|
| 92 |
+
pip install -e .
|
| 93 |
+
```
|
| 94 |
|
| 95 |
+
## Quick Start
|
| 96 |
|
| 97 |
+
Load LLM-Codec through the Codec-SUPERB codec registry:
|
| 98 |
|
| 99 |
+
```python
|
| 100 |
+
from SoundCodec import codec
|
| 101 |
|
| 102 |
+
print(codec.list_codec())
|
| 103 |
+
model = codec.load_codec("llmcodec")
|
| 104 |
+
```
|
| 105 |
|
| 106 |
+
Encode and reconstruct one audio file:
|
| 107 |
|
| 108 |
+
```python
|
| 109 |
+
from SoundCodec import codec
|
| 110 |
+
import torchaudio
|
| 111 |
+
import soundfile as sf
|
| 112 |
|
| 113 |
+
model = codec.load_codec("llmcodec")
|
| 114 |
|
| 115 |
+
waveform, sample_rate = torchaudio.load("sample_audio.wav")
|
| 116 |
+
data_item = {
|
| 117 |
+
"audio": {
|
| 118 |
+
"array": waveform.numpy()[0],
|
| 119 |
+
"sampling_rate": sample_rate,
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
|
| 123 |
+
units = model.extract_unit(data_item).unit
|
| 124 |
+
print("Unit shape:", units.shape)
|
| 125 |
|
| 126 |
+
result = model.synth(data_item, local_save=False)
|
| 127 |
+
reconstructed = result["audio"]["array"]
|
| 128 |
+
reconstructed_sr = result["audio"].get("sampling_rate", sample_rate)
|
| 129 |
|
| 130 |
+
sf.write("reconstructed.wav", reconstructed, reconstructed_sr)
|
| 131 |
+
```
|
| 132 |
|
| 133 |
+
## Batch Usage
|
| 134 |
|
| 135 |
+
Codec-SUPERB also provides batch APIs:
|
| 136 |
|
| 137 |
+
```python
|
| 138 |
+
from SoundCodec import codec
|
| 139 |
+
import torchaudio
|
| 140 |
|
| 141 |
+
model = codec.load_codec("llmcodec")
|
| 142 |
|
| 143 |
+
audio_files = ["audio1.wav", "audio2.wav", "audio3.wav"]
|
| 144 |
+
data_list = []
|
| 145 |
|
| 146 |
+
for path in audio_files:
|
| 147 |
+
waveform, sample_rate = torchaudio.load(path)
|
| 148 |
+
data_list.append({
|
| 149 |
+
"id": path,
|
| 150 |
+
"audio": {
|
| 151 |
+
"array": waveform.numpy()[0],
|
| 152 |
+
"sampling_rate": sample_rate,
|
| 153 |
+
},
|
| 154 |
+
})
|
| 155 |
|
| 156 |
+
batch_units = model.batch_extract_unit(data_list)
|
| 157 |
+
batch_audio = model.batch_decode_unit(batch_units)
|
| 158 |
|
| 159 |
+
results = model.batch_synth(data_list, local_save=False)
|
| 160 |
+
for item in results:
|
| 161 |
+
print(item["unit"].shape, item["audio"]["array"].shape)
|
| 162 |
+
```
|
| 163 |
|
| 164 |
+
For better throughput, group audio samples with similar lengths before batching.
|
| 165 |
|
| 166 |
+
## Codec-SUPERB Evaluation
|
| 167 |
|
| 168 |
+
To evaluate LLM-Codec with Codec-SUPERB-tiny:
|
| 169 |
|
| 170 |
+
```bash
|
| 171 |
+
PYTHONPATH=. python3 scripts/dataset_creator.py \
|
| 172 |
+
--dataset voidful/codec-superb-tiny
|
| 173 |
|
| 174 |
+
PYTHONPATH=. python3 scripts/benchmarking.py \
|
| 175 |
+
--dataset datasets/voidful/codec-superb-tiny_synth \
|
| 176 |
+
--models llmcodec
|
| 177 |
+
```
|
| 178 |
|
| 179 |
+
## Model Files
|
| 180 |
|
| 181 |
+
The model repository provides:
|
| 182 |
|
| 183 |
+
- codec weights as `llm-codec.pt`
|
| 184 |
+
- a tokenizer extended with `<CODEC_*>` audio tokens
|
| 185 |
+
- Qwen-compatible model artifacts containing trained audio-token embeddings
|
| 186 |
|
| 187 |
+
The codec uses 20,480 audio tokens with the canonical token format:
|
| 188 |
|
| 189 |
+
```text
|
| 190 |
+
<CODEC_0>, <CODEC_1>, ..., <CODEC_20479>
|
| 191 |
+
```
|
| 192 |
|
| 193 |
+
## Training Data
|
| 194 |
|
| 195 |
+
The codec was trained on LibriSpeech `train-clean-100` with paired transcripts.
|
| 196 |
+
The validation split used during training is LibriSpeech `validation`.
|
| 197 |
|
| 198 |
+
Because training is speech-centric and transcript-supervised, performance may be
|
| 199 |
+
weaker on non-English speech, conversational speech, music, environmental audio,
|
| 200 |
+
or audio with strong noise and overlap.
|
| 201 |
|
| 202 |
+
## Training Procedure
|
| 203 |
|
| 204 |
+
Base components:
|
| 205 |
|
| 206 |
+
- Base codec: AUV
|
| 207 |
+
- Frozen LLM backbone: Qwen3-4B-Instruct
|
| 208 |
+
- Token rate: 50 Hz
|
| 209 |
+
- Audio vocabulary size: 20,480
|
| 210 |
+
- Segment length: 4 seconds
|
| 211 |
|
| 212 |
+
Losses:
|
| 213 |
|
| 214 |
+
- reconstruction mel loss
|
| 215 |
+
- multi-scale mel loss
|
| 216 |
+
- multi-resolution STFT loss
|
| 217 |
+
- complex STFT loss with phase term
|
| 218 |
+
- VQ commitment loss
|
| 219 |
+
- Gumbel bridge cross entropy
|
| 220 |
+
- Future Token Prediction loss
|
| 221 |
+
- Semantic Alignment cosine loss
|
| 222 |
+
- Semantic Alignment contrastive loss with memory bank
|
| 223 |
+
- MPD/MSD GAN and feature matching losses
|
| 224 |
|
| 225 |
+
## Evaluation Results
|
| 226 |
|
| 227 |
+
### Token Learnability
|
| 228 |
|
| 229 |
+
SALMon speech coherence accuracy after token-level LM training:
|
| 230 |
|
| 231 |
+
| Tokenizer | Overall accuracy |
|
| 232 |
+
| --- | ---: |
|
| 233 |
+
| WavTok-L | 48.3 |
|
| 234 |
+
| BigCodec | 49.4 |
|
| 235 |
+
| UniCodec | 50.1 |
|
| 236 |
+
| AUV | 49.4 |
|
| 237 |
+
| LLM-Codec | 61.6 |
|
| 238 |
|
| 239 |
+
Token-level perplexity on LibriSpeech after 3 epochs of LM training:
|
| 240 |
|
| 241 |
+
| Tokenizer | Eval loss | Perplexity |
|
| 242 |
+
| --- | ---: | ---: |
|
| 243 |
+
| WavTok-L | 11.91 | 148,122 |
|
| 244 |
+
| UniCodec | 11.92 | 150,197 |
|
| 245 |
+
| BigCodec | 11.96 | 156,448 |
|
| 246 |
+
| AUV | 11.98 | 159,768 |
|
| 247 |
+
| LLM-Codec | 8.44 | 4,617 |
|
| 248 |
+
|
| 249 |
+
### Reconstruction Quality
|
| 250 |
|
| 251 |
+
Codec-SUPERB-tiny speech reconstruction:
|
| 252 |
|
| 253 |
+
| Model | Mel lower is better | STFT lower is better | PESQ higher is better | STOI higher is better |
|
| 254 |
+
| --- | ---: | ---: | ---: | ---: |
|
| 255 |
+
| AUV base | 0.762 | 1.648 | 2.094 | 0.850 |
|
| 256 |
+
| LLM-Codec | 0.724 | 1.599 | 2.102 | 0.859 |
|
| 257 |
|
| 258 |
+
## Limitations
|
| 259 |
|
| 260 |
+
- The semantic alignment objective depends on paired speech and text.
|
| 261 |
+
- The model is primarily validated on read speech.
|
| 262 |
+
- Downstream generation quality depends on the separate speech language model.
|
| 263 |
+
- The model may preserve speaker identity information present in the input.
|
| 264 |
+
- The Hugging Face `transformers` artifacts are not a standalone text chatbot;
|
| 265 |
+
they accompany the codec/tokenizer workflow.
|
| 266 |
|
| 267 |
+
## Citation
|
| 268 |
+
|
| 269 |
+
```bibtex
|
| 270 |
+
@misc{chung2026llmcodec,
|
| 271 |
+
title = {LLM-Codec: Neural Audio Codec Meets Language Model Objectives},
|
| 272 |
+
author = {Chung, Ho-Lam and Chen, Yiming and Lee, Hung-yi},
|
| 273 |
+
year = {2026},
|
| 274 |
+
note = {Model and code available at https://github.com/voidful/llm-codec}
|
| 275 |
+
}
|
| 276 |
+
```
|
| 277 |
|
| 278 |
+
If you use the Codec-SUPERB interface or benchmark, please also cite
|
| 279 |
+
Codec-SUPERB:
|
| 280 |
+
|
| 281 |
+
```bibtex
|
| 282 |
+
@inproceedings{wu-etal-2024-codec,
|
| 283 |
+
title = {Codec-SUPERB: An In-Depth Analysis of Sound Codec Models},
|
| 284 |
+
author = {Wu, Haibin and Chung, Ho-Lam and Lin, Yi-Cheng and Wu, Yuan-Kuei and Chen, Xuanjun and Pai, Yu-Chi and Wang, Hsiu-Hsuan and Chang, Kai-Wei and Liu, Alexander and Lee, Hung-yi},
|
| 285 |
+
booktitle = {Findings of the Association for Computational Linguistics: ACL 2024},
|
| 286 |
+
year = {2024},
|
| 287 |
+
url = {https://aclanthology.org/2024.findings-acl.616},
|
| 288 |
+
doi = {10.18653/v1/2024.findings-acl.616},
|
| 289 |
+
pages = {10330--10348}
|
| 290 |
+
}
|
| 291 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|