初始化项目,由ModelHub XC社区提供模型

Model: beleata74/bg-tts-v7
Source: Original Platform
This commit is contained in:
ModelHub XC
2026-04-24 00:55:06 +08:00
commit 8ec8e51538
13 changed files with 292848 additions and 0 deletions

36
.gitattributes vendored Normal file
View File

@@ -0,0 +1,36 @@
*.7z filter=lfs diff=lfs merge=lfs -text
*.arrow filter=lfs diff=lfs merge=lfs -text
*.bin filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.ckpt filter=lfs diff=lfs merge=lfs -text
*.ftz filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.h5 filter=lfs diff=lfs merge=lfs -text
*.joblib filter=lfs diff=lfs merge=lfs -text
*.lfs.* filter=lfs diff=lfs merge=lfs -text
*.mlmodel filter=lfs diff=lfs merge=lfs -text
*.model filter=lfs diff=lfs merge=lfs -text
*.msgpack filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.npz filter=lfs diff=lfs merge=lfs -text
*.onnx filter=lfs diff=lfs merge=lfs -text
*.ot filter=lfs diff=lfs merge=lfs -text
*.parquet filter=lfs diff=lfs merge=lfs -text
*.pb filter=lfs diff=lfs merge=lfs -text
*.pickle filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pth filter=lfs diff=lfs merge=lfs -text
*.rar filter=lfs diff=lfs merge=lfs -text
*.safetensors filter=lfs diff=lfs merge=lfs -text
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
*.tar.* filter=lfs diff=lfs merge=lfs -text
*.tar filter=lfs diff=lfs merge=lfs -text
*.tflite filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.wasm filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text
*tfevents* filter=lfs diff=lfs merge=lfs -text
tokenizer.json filter=lfs diff=lfs merge=lfs -text

186
README.md Normal file
View File

@@ -0,0 +1,186 @@
---
language:
- bg
- en
license: apache-2.0
tags:
- tts
- text-to-speech
- speech-synthesis
- bulgarian
- miocodec
- qwen3
pipeline_tag: text-to-speech
base_model: Qwen/Qwen3-0.6B-Base
datasets:
- custom
---
# BG-TTS-V7 — Българско Text-to-Speech с MioCodec
Open-source TTS модел за български език, базиран на Qwen3-0.6B-Base и MioCodec аудио кодек. Втора версия след [mio-tts-0.6b-bg-finetuned](https://huggingface.co/beleata74/mio-tts-0.6b-bg-finetuned).
## Описание
BG-TTS-V7 е decoder-only езиков модел, дообучен (fine-tuned) да генерира реч от текст на български език. Моделът приема текст в ChatML формат и генерира поредица от аудио токени, които след това се декодират до реч чрез [MioCodec](https://huggingface.co/Aratako/MioCodec-25Hz-24kHz).
Проектът е базиран на [Aratako/MioTTS-0.6B](https://huggingface.co/Aratako/MioTTS-0.6B) — японски TTS модел, чийто подход адаптирахме за български език.
### Оригинален модел
Базиран на **[Qwen/Qwen3-0.6B-Base](https://huggingface.co/Qwen/Qwen3-0.6B-Base)** — pre-trained езиков модел от Alibaba с 608M параметри. Оригиналният Qwen3 tokenizer е разширен с 12,800 специални speech токени (`<|s_0|>` до `<|s_12799|>`), съответстващи на кодбука на MioCodec.
### Какво направихме
1. **Взехме Qwen3-0.6B-Base** с оригиналните pre-trained тегла (разбиране на текст на 100+ езика, включително български)
2. **Добавихме 12,800 speech токена** в tokenizer-а и resize на embedding слоя (151,669 → 164,469 vocab)
3. **Подготвихме 769 часа аудио данни** — български реч, кодирана с MioCodec (25 Hz, 1 codebook, 24 kHz)
4. **Fine-tune** с ChatML формат: текстът е в `user` ролята, speech токените — в `assistant` ролята
5. **Loss само върху speech токените** — моделът учи mapping text → audio, без да разваля текстовото разбиране
### Данни за обучение
| Датасет | Часове | Семпли | Описание |
|---------|--------|--------|----------|
| encoded_dataset_v3 | ~660ч | 292K | Мулти-датасет, български |
| encoded_dataset_v4 | ~49ч | 52K | Чист български (4 източника) |
| encoded_dataset_v4_d12 | ~105ч | 54K | Допълнителен български |
| **Общо** | **~769ч** | **389K** | |
Всички аудио файлове са кодирани с [MioCodec-25Hz-24kHz](https://huggingface.co/Aratako/MioCodec-25Hz-24kHz) — 25 fps, 1 codebook, 12,800 кода.
### Резултати от обучението
- **Training loss**: 4.56 (min)
- **Validation loss**: 5.06 (best @ step 12000)
- **Epochs**: ~2 от 5 (step 12000 от 30,355)
- **Effective batch size**: 64 (4 × 16 gradient accumulation)
- **Learning rate**: 2e-4 (cosine decay, 910 warmup steps)
- **Hardware**: NVIDIA RTX 5090 (32GB VRAM)
- **Време за обучение**: ~8 часа до step 12000
## Как да се ползва
### Подход 1: С MioTTS-Inference (препоръчителен)
Моделът е съвместим с [MioTTS-Inference](https://github.com/Aratako/MioTTS-Inference) — същият inference pipeline като оригиналния MioTTS.
```bash
# 1. Зареди модела с vLLM
python -m vllm.entrypoints.openai.api_server \
--model beleata74/bg-tts-v7 \
--dtype bfloat16 \
--gpu-memory-utilization 0.4 \
--max-model-len 2048 \
--port 8000
# 2. Стартирай MioTTS сървъра
cd MioTTS-Inference
MIOTTS_CODEC_MODEL=Aratako/MioCodec-25Hz-24kHz \
MIOTTS_LLM_BASE_URL=http://localhost:8000/v1 \
python run_server.py --host 0.0.0.0 --port 8001
# 3. Стартирай Gradio UI
GRADIO_SERVER_PORT=7861 \
MIOTTS_API_BASE=http://127.0.0.1:8001 \
python run_gradio.py
```
### Подход 2: Директно с transformers
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_name = "beleata74/bg-tts-v7"
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_name, torch_dtype=torch.bfloat16, device_map="auto"
)
# ChatML формат: user = текст, assistant = speech токени
text = "Здравейте, как сте днес?"
messages = [{"role": "user", "content": text}]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(
**inputs,
max_new_tokens=500,
temperature=0.7,
top_p=0.9,
repetition_penalty=1.1,
)
# Извлечи speech токени (offset 151669)
generated = output[0][inputs["input_ids"].shape[1]:]
speech_offset = 151669
audio_codes = [t.item() - speech_offset for t in generated
if speech_offset <= t.item() < speech_offset + 12800]
# Декодирай с MioCodec
# audio_codes -> numpy array -> MioCodec decode -> wav
```
### Подход 3: Декодиране на audio кодовете до wav
```python
import numpy as np
import torch
from miocodec import MioCodec
codec = MioCodec.from_pretrained("Aratako/MioCodec-25Hz-24kHz")
# audio_codes е списък с MioCodec индекси (0-12799)
codes_tensor = torch.tensor([audio_codes], dtype=torch.long).unsqueeze(0) # [1, 1, T]
wav = codec.decode(codes_tensor) # -> [1, 1, num_samples]
import soundfile as sf
sf.write("output.wav", wav[0, 0].cpu().numpy(), 24000)
```
## Архитектура
| Параметър | Стойност |
|-----------|----------|
| Базов модел | Qwen3-0.6B-Base |
| Параметри | 608.9M |
| Hidden size | 1024 |
| Attention heads | 16 (8 KV heads) |
| Layers | 28 |
| Vocab size | 164,469 (151,669 оригинални + 12,800 speech) |
| Max seq length | 2048 |
| Precision | bfloat16 |
## Формат на данните
```
<|im_start|>user
Здравейте, как сте?<|im_end|>
<|im_start|>assistant
<|s_2559|><|s_3752|><|s_2751|>...<|s_1234|><|im_end|>
```
- **User**: Текст на български (subword tokenization от Qwen3)
- **Assistant**: Поредица от MioCodec токени (`<|s_N|>`, N ∈ [0, 12799])
- **Loss**: Изчислява се САМО върху assistant частта (speech + `<|im_end|>`)
## Ограничения
- Обучен предимно на български — може да генерира и английски, но с по-ниско качество
- 769 часа данни е относително малко за TTS задача (MioTTS е обучен на 100K часа)
- Validation loss стига плато при ~5.06 — вътрешна ентропия на MioCodec кодбука
- Кратки думи (2-4 букви) понякога се грешат — alignment проблем при малко контекст
- Не поддържа voice cloning в промпта — speaker характеристиката идва от MioCodec decode
## Благодарности
- **[Aratako/MioTTS-0.6B](https://huggingface.co/Aratako/MioTTS-0.6B)** — оригиналният проект, чийто подход следваме
- **[Aratako](https://huggingface.co/Aratako)** — за MioCodec и MioTTS архитектурата
- **[Qwen Team](https://huggingface.co/Qwen)** — за Qwen3-0.6B-Base
- **[MioTTS-Inference](https://github.com/Aratako/MioTTS-Inference)** — inference pipeline
- **[beleata74/mio-tts-0.6b-bg-finetuned](https://huggingface.co/beleata74/mio-tts-0.6b-bg-finetuned)** — първата ни версия на български TTS
## Лиценз
Apache 2.0 (следва лиценза на Qwen3)

12828
added_tokens.json Normal file

File diff suppressed because it is too large Load Diff

85
chat_template.jinja Normal file
View File

@@ -0,0 +1,85 @@
{%- if tools %}
{{- '<|im_start|>system\n' }}
{%- if messages[0].role == 'system' %}
{{- messages[0].content + '\n\n' }}
{%- endif %}
{{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
{%- for tool in tools %}
{{- "\n" }}
{{- tool | tojson }}
{%- endfor %}
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
{%- else %}
{%- if messages[0].role == 'system' %}
{{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}
{%- for message in messages[::-1] %}
{%- set index = (messages|length - 1) - loop.index0 %}
{%- if ns.multi_step_tool and message.role == "user" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}
{%- set ns.multi_step_tool = false %}
{%- set ns.last_query_index = index %}
{%- endif %}
{%- endfor %}
{%- for message in messages %}
{%- if (message.role == "user") or (message.role == "system" and not loop.first) %}
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
{%- elif message.role == "assistant" %}
{%- set content = message.content %}
{%- set reasoning_content = '' %}
{%- if message.reasoning_content is defined and message.reasoning_content is not none %}
{%- set reasoning_content = message.reasoning_content %}
{%- else %}
{%- if '</think>' in message.content %}
{%- set content = message.content.split('</think>')[-1].lstrip('\n') %}
{%- set reasoning_content = message.content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %}
{%- endif %}
{%- endif %}
{%- if loop.index0 > ns.last_query_index %}
{%- if loop.last or (not loop.last and reasoning_content) %}
{{- '<|im_start|>' + message.role + '\n<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + content }}
{%- endif %}
{%- else %}
{{- '<|im_start|>' + message.role + '\n' + content }}
{%- endif %}
{%- if message.tool_calls %}
{%- for tool_call in message.tool_calls %}
{%- if (loop.first and content) or (not loop.first) %}
{{- '\n' }}
{%- endif %}
{%- if tool_call.function %}
{%- set tool_call = tool_call.function %}
{%- endif %}
{{- '<tool_call>\n{"name": "' }}
{{- tool_call.name }}
{{- '", "arguments": ' }}
{%- if tool_call.arguments is string %}
{{- tool_call.arguments }}
{%- else %}
{{- tool_call.arguments | tojson }}
{%- endif %}
{{- '}\n</tool_call>' }}
{%- endfor %}
{%- endif %}
{{- '<|im_end|>\n' }}
{%- elif message.role == "tool" %}
{%- if loop.first or (messages[loop.index0 - 1].role != "tool") %}
{{- '<|im_start|>user' }}
{%- endif %}
{{- '\n<tool_response>\n' }}
{{- message.content }}
{{- '\n</tool_response>' }}
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
{{- '<|im_end|>\n' }}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
{{- '<|im_start|>assistant\n' }}
{%- if enable_thinking is defined and enable_thinking is false %}
{{- '<think>\n\n</think>\n\n' }}
{%- endif %}
{%- endif %}

60
config.json Normal file
View File

@@ -0,0 +1,60 @@
{
"architectures": [
"Qwen3ForCausalLM"
],
"attention_bias": false,
"attention_dropout": 0.0,
"dtype": "bfloat16",
"eos_token_id": 151643,
"head_dim": 128,
"hidden_act": "silu",
"hidden_size": 1024,
"initializer_range": 0.02,
"intermediate_size": 3072,
"layer_types": [
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention",
"full_attention"
],
"max_position_embeddings": 32768,
"max_window_layers": 28,
"model_type": "qwen3",
"num_attention_heads": 16,
"num_hidden_layers": 28,
"num_key_value_heads": 8,
"pad_token_id": 151643,
"rms_norm_eps": 1e-06,
"rope_scaling": null,
"rope_theta": 1000000,
"sliding_window": null,
"tie_word_embeddings": true,
"transformers_version": "4.57.6",
"use_cache": true,
"use_sliding_window": false,
"vocab_size": 164469
}

8
generation_config.json Normal file
View File

@@ -0,0 +1,8 @@
{
"eos_token_id": [
151643
],
"max_new_tokens": 2048,
"pad_token_id": 151643,
"transformers_version": "4.57.6"
}

151388
merges.txt Normal file

File diff suppressed because it is too large Load Diff

3
model.safetensors Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:cc10d034ab91c8b23cd96c1e709adb5822c820989f35c1c4eb12302abd3cc185
size 1217802696

12812
special_tokens_map.json Normal file

File diff suppressed because it is too large Load Diff

3
tokenizer.json Normal file
View File

@@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0a6a1c75f1463acfe4a8e70410bbce1a8e17399501c9d530064d39b73ea295ce
size 13817944

115426
tokenizer_config.json Normal file

File diff suppressed because it is too large Load Diff

1
vocab.json Normal file

File diff suppressed because one or more lines are too long

12
vocab_info.json Normal file
View File

@@ -0,0 +1,12 @@
{
"base_model": "Qwen/Qwen3-0.6B-Base",
"original_vocab_size": 151669,
"total_vocab_size": 164469,
"num_speech_tokens": 12800,
"speech_token_offset": 151669,
"first_speech_token": "<|s_0|>",
"last_speech_token": "<|s_12799|>",
"eos_token_id": 151643,
"im_start_id": 151644,
"im_end_id": 151645
}