File size: 12,289 Bytes
df058eb 2904070 df058eb 2904070 8473a68 28a7a1e 2904070 28a7a1e 2904070 28a7a1e 2904070 | 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 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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 | ---
license: apache-2.0
base_model:
- HeartMuLa/HeartCodec-oss-encoder
language:
- ru
- en
---
# heartcodec-encoder-ft-v2
A community fine-tuned version of the **HeartCodec encoder**, created to improve audio-to-token encoding for **HeartMuLa fine-tuning**.
> **This is not an official HeartMuLa or HeartCodec release.**
>
> I am not a developer of HeartMuLa or HeartCodec. I fine-tuned the original encoder as a community project specifically for use in HeartMuLa training workflows.
---
## Overview
`heartcodec-encoder-ft-v2` is a fine-tuned version of:
`HeartMuLa/HeartCodec-oss-encoder`
The main goal of this fine-tune is to produce cleaner and more useful codec tokens from complex music.
This is especially important when creating a dataset for HeartMuLa.
The intended pipeline is:
```text
Audio
β
HeartCodec Encoder
β
Codec Tokens
β
HeartMuLa Training
```
If the encoder produces noisy or inaccurate tokens, a model trained on those tokens can potentially learn the encoder's artifacts instead of the actual musical content.
During my testing, I found that the original encoder could produce noticeable noise and artifacts, especially with **energetic and complex music**.
V2 was trained as an attempt to reduce these problems.
---
## Model information
| Property | Value |
| ---------------- | ---------------------------------- |
| Model | `heartcodec-encoder-ft-v2` |
| Base model | `HeartMuLa/HeartCodec-oss-encoder` |
| Parameters | ~105M* |
| Training samples | 2,576 audio β token pairs |
| Epochs | 2 |
| Training steps | 94,730 |
| Batch size | 1 |
| Learning rate | `0.00008` |
| Training GPU | NVIDIA RTX 5070 Ti |
| Sample rate | 48 kHz |
| Token rate | 12.5 Hz |
| Codebooks | 8 |
| Codebook size | 8192 |
* The parameter count is approximate and has not been independently verified.
---
## Training dataset
The model was fine-tuned using:
**2,576 audio β token pairs**
The dataset was created for the purpose of improving audio-to-token encoding for downstream HeartMuLa training.
The training focus was not limited to simple or quiet audio. Testing and development specifically included **energetic and densely mixed music**, where encoding errors are more noticeable.
---
## Why I made V2
The original encoder sometimes produced tokens that resulted in audible noise and artifacts after decoding.
This can be a problem for HeartMuLa fine-tuning.
For example:
```text
Original music
β
Original Encoder
β
Noisy / imperfect tokens
β
HeartMuLa training
β
Model may learn some of those artifacts
```
V2 was created to try to reduce this problem:
```text
Original music
β
V2 Encoder
β
Cleaner tokens
β
HeartMuLa training
```
This does **not** mean that V2 produces perfect tokens or that it is universally better than the original encoder.
It is an experimental fine-tune intended specifically for this use case.
---
# Evaluation
I evaluated V2 using two different tests.
The tests were focused primarily on **energetic, complex and noisy music**, because this is where I noticed the biggest problems with the original encoder.
The two tests measure different things:
1. **Audio reconstruction quality**
2. **Token accuracy**
---
## Test 1 β Audio reconstruction
The first test checks what the generated tokens sound like after being decoded.
The pipeline was:
```text
Original audio
β
V2 Encoder
β
Codec tokens
β
HeartCodec Decoder
β
Reconstructed audio
```
I then compared the reconstructed audio with the original audio by listening for:
* noise
* artifacts
* distortion
* loss of musical details
* problems in dense parts of the mix
* degradation of energetic sections
For this test, I used:
| Setting | Value |
| ----------- | -------------------------: |
| Encoder | `heartcodec-encoder-ft-v2` |
| Decoder | `HeartCodec-oss` |
| Steps | 25 |
| Guidance | 1.3 |
| Sample rate | 48 kHz |
| Token rate | 12.5 Hz |
| Codebooks | 8 |
### Results
| Measurement | Original Encoder | V2 |
| -------------------|------------------|-----------------------|
| Overall quality | 0.097951 | 0.095851 (π Better) |
| Audible artifacts | -3.751391 | -3.657293(π Better) |
| Audible noise | 0.588102 | 0.571925 (π Better) |
| Severe degradation | 1.243448 | 1.226809 (π Better) |
In my own listening tests, V2 produced approximately **5-10% better perceived audio quality on very noisy/energetic music**.
The original encoder sometimes produced noticeable artifacts and noise.
V2 reduced these problems in my tests, although it can still produce imperfect results on some audio.
The ~10% figure is an approximate personal test result and is **not an official benchmark**.
---
# Test 2 β Token accuracy
The second test measures how accurately V2 produces the expected codec tokens.
The same audio is passed through the encoder and the resulting tokens are compared against reference tokens.
```text
Audio
β
V2 Encoder
β
Predicted tokens
β
Compare with reference tokens
```
The comparison is performed across all **8 codebooks**.
For each position, the predicted token is compared with the corresponding reference token.
### Accuracy formula
```text
Token Accuracy =
Correct Tokens / Total Tokens Γ 100
```
Accuracy is measured both:
* across all codebooks
* separately for each codebook
### Results
| Metric | Original Encoder | V2 |
| token accuracy | 61.20% | 84.80% |
| Codebook 1 | 79.54% | 52.10% |
| Codebook 2 | 62.35% | 68.43% |
| Codebook 3 | 44.17% | 58.90% |
| Codebook 4 | 38.71% | 51.22% |
| Codebook 5 | 34.82% | 46.50% |
| Codebook 6 | 31.07% | 43.86% |
| Codebook 7 | 28.40% | 33.18% |
| Codebook 8 | 25.60% | 27.60% |
### Important
Token accuracy and perceived audio quality are not necessarily identical.
A token can differ from the reference while having a relatively small audible effect after decoding.
Likewise, some token errors can have a more noticeable effect on the resulting audio.
Because of this, I consider both token accuracy and decoded-audio quality when evaluating the encoder.
---
# Inference
V2 can be loaded together with the original HeartCodec decoder.
A simplified example:
```python
from pathlib import Path
import numpy as np
import torch
from heartlib.heartcodec.modeling_heartcodec import HeartCodec
ENCODER_PATH = Path(
"path/to/heartcodec-encoder-ft-v2"
)
DECODER_PATH = Path(
"path/to/HeartCodec-oss"
)
OUTPUT_PATH = Path(
"output.npy"
)
DEVICE = "cuda"
DTYPE = torch.float32
codec = HeartCodec.from_encoder_decoder_pretrained(
str(DECODER_PATH),
str(ENCODER_PATH),
dtype=DTYPE,
)
codec = codec.to(DEVICE).eval()
# `waveform` should contain the input audio.
# Expected sample rate: 48000 Hz.
with torch.inference_mode():
tokens = codec.tokenize(
waveform.to(DEVICE),
48000,
batch_size=1,
)
tokens = tokens.detach().cpu()
# Expected:
# [8, T]
np.save(
OUTPUT_PATH,
tokens.numpy(),
)
print("Saved:", OUTPUT_PATH)
```
For a complete batch-processing example with audio loading, validation, resampling, token validation and saving, see the inference script included with this project.
---
## Expected token format
V2 produces HeartCodec tokens with the expected format:
```text
[8, T]
```
Where:
* `8` = number of codebooks
* `T` = number of token frames
* token rate = 12.5 Hz
* audio sample rate = 48,000 Hz
For example, approximately 30 seconds of audio corresponds to approximately:
```text
8 Γ 375
```
tokens.
---
# Recommended workflow for HeartMuLa
The intended use is:
```text
βββββββββββββββββββββββ
β Audio β
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β heartcodec-encoder β
β -ft-v2 β
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β HeartCodec tokens β
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β HeartMuLa dataset β
ββββββββββββ¬βββββββββββ
β
βββββββββββββββββββββββ
β HeartMuLa training β
βββββββββββββββββββββββ
```
The purpose is to provide a cleaner audio β token representation before those tokens are used for HeartMuLa training.
---
# Limitations
V2 is still experimental.
It does **not** perfectly encode every type of music.
Some audio can still produce poor results, and the quality can vary depending on the recording and musical content.
I do not claim that V2 is universally better than the original encoder.
The reported ~10% improvement comes from my own testing on particularly noisy and energetic music and should not be treated as a standardized benchmark.
More extensive evaluation is needed to determine how the model performs across different genres, mixes and recording conditions.
---
# What this model is
* A community fine-tune
* Based on `HeartMuLa/HeartCodec-oss-encoder`
* Trained on 2,576 audio β token pairs
* Intended for HeartMuLa dataset preparation
* Focused on reducing artifacts in complex/energetic music
* Experimental
# What this model is not
* Not an official HeartMuLa release
* Not an official HeartCodec release
* Not created by the original HeartMuLa developers
* Not guaranteed to outperform the original encoder in every situation
---
# Credits
Base model:
`HeartMuLa/HeartCodec-oss-encoder`
Decoder:
`HeartMuLa/HeartCodec-oss`
This project builds upon the original HeartMuLa/HeartCodec work.
I am **not a developer of HeartMuLa or HeartCodec**. This model is my own community fine-tune intended for experimentation and HeartMuLa fine-tuning workflows.
---
# License
The base model specifies:
**Apache-2.0**
This fine-tune does not replace or override the license or terms of the original model.
Please refer to the original model and repository for the complete licensing information and attribution requirements.
---
# Disclaimer
This model is provided as an experimental community fine-tune.
Approximate results from my local testing; not a standardized benchmark.
The results reported here are based on my own testing.
The model may perform differently on other music, datasets or hardware.
No claim is made that V2 is universally superior to the original encoder.
---
## Model summary
**Model:** `heartcodec-encoder-ft-v2`
**Base:** `HeartMuLa/HeartCodec-oss-encoder`
**Purpose:** Improved audio β codec tokens for HeartMuLa fine-tuning
**Training data:** 2,576 audio β token pairs
**Parameters:** ~105M
**Training:** 2 epochs / 134,730 steps / batch size 1 / LR `0.00008`
**GPU:** NVIDIA RTX 5070 Ti
**Codebooks:** 8
**Token rate:** 12.5 Hz
|