Instructions to use Ritori/Yue_tacotron2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Ritori/Yue_tacotron2 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Ritori/Yue_tacotron2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download loss_function.py from Ritori/Yue_tacotron2: direct link, hf CLI and curl.
- Browser
- Download file 673 Bytes
-
https://huggingface.co/Ritori/Yue_tacotron2/resolve/main/loss_function.py
- Command line
-
hf download hf://Ritori/Yue_tacotron2/loss_function.py
-
curl -L -o loss_function.py https://huggingface.co/Ritori/Yue_tacotron2/resolve/main/loss_function.py
673 Bytes
| from torch import nn | |
| class Tacotron2Loss(nn.Module): | |
| def __init__(self): | |
| super(Tacotron2Loss, self).__init__() | |
| def forward(self, model_output, targets): | |
| mel_target, gate_target = targets[0], targets[1] | |
| mel_target.requires_grad = False | |
| gate_target.requires_grad = False | |
| gate_target = gate_target.view(-1, 1) | |
| mel_out, mel_out_postnet, gate_out, _ = model_output | |
| gate_out = gate_out.view(-1, 1) | |
| mel_loss = nn.MSELoss()(mel_out, mel_target) + \ | |
| nn.MSELoss()(mel_out_postnet, mel_target) | |
| gate_loss = nn.BCEWithLogitsLoss()(gate_out, gate_target) | |
| return mel_loss + gate_loss | |