Pytorch Implementation of Google's Parallel Tacotron 2: A Non-Autoregressive Neural TTS Model with Differentiable Duration Modeling

Overview

Parallel Tacotron2

Pytorch Implementation of Google's Parallel Tacotron 2: A Non-Autoregressive Neural TTS Model with Differentiable Duration Modeling

Updates

  • 2021.05.15: Implementation done. Sanity checks on training and inference. But still the model cannot converge.

    I'm waiting for your contribution! Please inform me if you find any mistakes in my implementation or any valuable advice to train the model successfully. See the Implementation Issues section.

Training

Requirements

  • You can install the Python dependencies with

    pip3 install -r requirements.txt
  • In addition to that, install fairseq (official document, github) to utilize LConvBlock.

Datasets

The supported datasets:

  • LJSpeech: a single-speaker English dataset consists of 13100 short audio clips of a female speaker reading passages from 7 non-fiction books, approximately 24 hours in total.
  • (will be added more)

Preprocessing

After downloading the datasets, set the corpus_path in preprocess.yaml and run the preparation script:

python3 prepare_data.py config/LJSpeech/preprocess.yaml

Then, run the preprocessing script:

python3 preprocess.py config/LJSpeech/preprocess.yaml

Training

Train your model with

python3 train.py -p config/LJSpeech/preprocess.yaml -m config/LJSpeech/model.yaml -t config/LJSpeech/train.yaml

The model cannot converge yet. I'm debugging but it would be boosted if your awesome contribution is ready!

TensorBoard

Use

tensorboard --logdir output/log/LJSpeech

to serve TensorBoard on your localhost.

Implementation Issues

Overall, normalization or activation, which is not suggested in the original paper, is adequately arranged to prevent nan value (gradient) on forward and backward calculations.

Text Encoder

  1. Use the FFTBlock of FastSpeech2 for the transformer block of the text encoder.
  2. Use dropout 0.2 for the ConvBlock of the text encoder.
  3. To restore "proprietary normalization engine",
    • Apply the same text normalization as in FastSpeech2.
    • Implement grapheme_to_phoneme function. (See ./text/init).

Residual Encoder

  1. Use 80 channels mel-spectrogrom instead of 128-bin.
  2. Regular sinusoidal positional embedding is used in frame-level instead of combinations of three positional embeddings in Parallel Tacotron. As the model depends entirely on unsupervised learning for the position, this choice can be a reason for the fails on model converge.

Duration Predictor & Learned Upsampling (The most important but ambiguous part)

  1. Use log durations with the prior: there should be at least one frame in total per sequence.
  2. Use nn.SiLU() for the swish activation.
  3. When obtaining W and C, concatenation operation is applied among S, E, and V after frame-domain (T domain) broadcasting of V. As the detailed process is not described in the original paper, this choice can be a reason for the fails on model converge.

Decoder

  1. Use (Multi-head) Self-attention and LConvBlock.
  2. Iterative mel-spectrogram is projected by a linear layer.
  3. Apply nn.Tanh() to each LConvBLock output (following activation pattern of decoder part in FastSpeech2).

Loss

  1. Use optimization & scheduler of FastSpeech2 (which is from Attention is all you need as described in the original paper).
  2. Base on pytorch-softdtw-cuda (post) for the soft-DTW.
    1. Implement customized soft-DTW in model/soft_dtw_cuda.py, reflecting the recursion suggested in the original paper.
    2. In the original soft-DTW, the final loss is not assumed and therefore only E is computed. But employed as a loss function, jacobian product is added to return target derivetive of R w.r.t. input X.
    3. Currently, the maximum batch size is 6 in 24GiB GPU (TITAN RTX) due to space complexity problem in soft-DTW Loss.
      • In the original paper, a custom differentiable diagonal band operation was implemented and used to solve the complexity of O(T^2), but this part has not been explored in the current implementation yet.
  3. For the stability, mel-spectrogroms are compressed by a sigmoid function before the soft-DTW. If the sigmoid is eliminated, the soft-DTW value is too large, producing nan in the backward.
  4. Guided attention loss is applied for fast convergence of the attention module in residual encoder.

Citation

@misc{lee2021parallel_tacotron2,
  author = {Lee, Keon},
  title = {Parallel-Tacotron2},
  year = {2021},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/keonlee9420/Parallel-Tacotron2}}
}

References

Comments
  • LightWeightConv layer warnings during training

    LightWeightConv layer warnings during training

    If just install specified requirements + Pillow and fairseq following warnings appear during training start:

    No module named 'lightconv_cuda'

    If install lightconv-layer from fairseq, the folllowing warning displayed:

    WARNING: Unsupported filter length passed - skipping forward pass

    Pytorch 1.7 Cuda 10.2 Fairseq 1.0.0a0+19793a7

    opened by idcore 10
  • Suggestion for adding open German

    Suggestion for adding open German "Thorsten" dataset

    Hi.

    According to text in README (will be added more) i would like to suggest to add my open German "Thorsten" dataset.

    Thorsten: a single-speaker German open dataset consists of 22.668 short audio clips of a male speaker, approximately 23 hours in total (LJSpeech file/directory syntax).

    https://github.com/thorstenMueller/deep-learning-german-tts/

    opened by thorstenMueller 4
  • Soft DTW with Cython implementation

    Soft DTW with Cython implementation

    Hi @keonlee9420 , have you tried the Cython version of Soft DTW from this repo

    https://github.com/mblondel/soft-dtw

    Is it available to apply for Parallel Tacotron 2 ? I am trying that repo because the current batch is too small when using CUDA implement of @Maghoumi .


    I just wonder that @Maghoumi in https://github.com/Maghoumi/pytorch-softdtw-cuda claims that experiment with batch size

    image

    But when applying for Para Taco, the batch size is too small, are there any gap?

    opened by v-nhandt21 2
  • Handle audios with long duration

    Handle audios with long duration

    When I load audios with mel-spectrogram frames larger than max sequence of mel len (1000 frames):

    • There is a problem when concatenating pos + speaker + mels: I try to set max_seq_len larger (1500),
    • Then lead to a problem with Soft DTW, they said the maximum is 1024

    image

    For solution, I tried to trim mels for fitting 1024 but it seems complicated, now I filter out all audios with frames > 1024

    Any suggestion for handle Long Audios? I wonder how it work at inference steps.

    opened by v-nhandt21 2
  • cannot import name II from omegaconf

    cannot import name II from omegaconf

    Great work. But I encounter one problems when train this model :( The error message:

    ImportError: cannot import name II form omegaconf
    

    The version of fairseq is 0.10.2 (latest releaser version) and omegaconf is 1.4.1. How to fix it?

    Thank you

    opened by cnlinxi 2
  • It seems cannot run

    It seems cannot run

    I following your command to run the code, but I get following error. File "train.py", line 87, in main output = model(*(batch[2:])) File "/home/ydc/anaconda3/envs/CD/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/home/ydc/anaconda3/envs/CD/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py", line 162, in forward return self.gather(outputs, self.output_device) File "/home/ydc/anaconda3/envs/CD/lib/python3.8/site-packages/torch/nn/parallel/data_parallel.py", line 174, in gather return gather(outputs, output_device, dim=self.dim) File "/home/ydc/anaconda3/envs/CD/lib/python3.8/site-packages/torch/nn/parallel/scatter_gather.py", line 68, in gather res = gather_map(outputs) File "/home/ydc/anaconda3/envs/CD/lib/python3.8/site-packages/torch/nn/parallel/scatter_gather.py", line 63, in gather_map return type(out)(map(gather_map, zip(*outputs))) File "/home/ydc/anaconda3/envs/CD/lib/python3.8/site-packages/torch/nn/parallel/scatter_gather.py", line 63, in gather_map return type(out)(map(gather_map, zip(*outputs))) File "/home/ydc/anaconda3/envs/CD/lib/python3.8/site-packages/torch/nn/parallel/scatter_gather.py", line 55, in gather_map return Gather.apply(target_device, dim, *outputs) File "/home/ydc/anaconda3/envs/CD/lib/python3.8/site-packages/torch/nn/parallel/_functions.py", line 71, in forward return comm.gather(inputs, ctx.dim, ctx.target_device) File "/home/ydc/anaconda3/envs/CD/lib/python3.8/site-packages/torch/nn/parallel/comm.py", line 230, in gather return torch._C._gather(tensors, dim, destination) RuntimeError: Input tensor at index 1 has invalid shape [1, 474, 80], but expected [1, 302, 80]

    opened by yangdongchao 2
  • fix mask and soft-dtw loss

    fix mask and soft-dtw loss

    1 fix mask problem when calculating W in LearnUpsampling Module and attention matrix in VaribleLengthAttention module. 2 a new Jacobian matrix of Manhattan distance 3 deal with mel spectrograms of different lengths

    opened by zhang-wy15 1
  • why Lconv block doesn't have stride argument?

    why Lconv block doesn't have stride argument?

    Hi, Thanks for implement.

    I think Parallel TacoTron2 using same residual Encoder as parallel tacotron 1. In parallel tacotron, using five 17 × 1 LConv blocks interleaved with strided 3 × 1 convolutions

    캡처

    But, in your implementation, Lconvblock doesn't have stride argument. How did you handle this part?

    Thanks.

    opened by yw0nam 0
  • Soft DTW

    Soft DTW

    Hello, Has anybody been able to train with softdtw loss. It doesn't converge at all. I think there is a problem with the implementation but I could't spot it. When I train with the real alignments it works well

    opened by talipturkmen 0
  • weights required

    weights required

    Can someone share the weights file link? I couldn't synthesize it or use its inference. If I am wrong please tell me the correct method of using it. Thanks

    opened by mrqasimasif 0
  • Why no alignment at all?

    Why no alignment at all?

    I cloned the code, prepared data according to README, and just updated:

    1. ljspeech data path in config/LJSpeech/train.yaml
    2. unzip generator_LJSpeech.pth.tar.zip to get generator_LJSpeech.pth.tar and the code can run! But, no matter how many steps I trained, the images are always like this and demo audio sounds like noise:
    截屏2022-08-25 下午3 08 07
    opened by mikesun4096 2
  • training problem

    training problem

      File "/data1/hjh/pycharm_projects/tts/parallel-tacotron2_try/model/parallel_tacotron2.py", line 68, in forward
        self.learned_upsampling(durations, V, src_lens, src_masks, max_src_len)
      File "/home/huangjiahong.dracu/miniconda2/envs/parallel_tc2/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
        result = self.forward(*input, **kwargs)
      File "/data1/hjh/pycharm_projects/tts/parallel-tacotron2_try/model/modules.py", line 335, in forward
        mel_mask = get_mask_from_lengths(mel_len, max_mel_len)
      File "/data1/hjh/pycharm_projects/tts/parallel-tacotron2_try/utils/tools.py", line 87, in get_mask_from_lengths
        ids = torch.arange(0, max_len).unsqueeze(0).expand(batch_size, -1).to(device)
    RuntimeError: upper bound and larger bound inconsistent with step sign
    

    Thank you for you jobs. I got above problem when training. I guess it's a Duration prediction problem. How to solve it?

    opened by aijianiula0601 0
  • Could you please share your audio samples, pretrained models and loss curves?

    Could you please share your audio samples, pretrained models and loss curves?

    Hi, Thanks for your excellent work! Could you possibly share your audio samples, pretrained models and loss curves with me? Thanks so much for your help!

    opened by CocoWang1010 0
  • fix in implementation of S-DTW backward @taras-sereda

    fix in implementation of S-DTW backward @taras-sereda

    Hey, I've found that in your implementation of S-DTW backward, E - matrices are not used, instead you are using G - matrices and their entries are ignoring scaling factors a, b, c. What's the reason for this? My guess you are doing this in order to preserve and propagate gradients, because they are vanishing due to small values of a, b, c. But I might be wrong, so I'd be glad to hear your motivation on doing this.

    Playing with your code, I also found that gradients are vanishing, especially when bandwitdth=None. So I'm solving this problem by normalizing distance matrix, by n_mel_channel. And with this normalization and exact implementation of S-dtw backward I'm able to converge on overfit experiments quicker then with non-exact computation of s-dtw backward. I'm using these SDT hparams:

    gamma = 0.05
    warp = 256
    bandwidth = 50
    

    here is a small test I'm using for checks:

            target_spectro = np.load('')
            target_spectro = torch.from_numpy(target_spectro)
            target_spectro = target_spectro.unsqueeze(0).cuda()
            pred_spectro = torch.randn_like(target_spectro, requires_grad=True)
    
            optimizer = Adam([pred_spectro])
    
            # model fits in ~3k iterations
            n_iter = 4_000
            for i in range(n_iter):
    
                loss = self.numba_soft_dtw(pred_spectro, target_spectro)
                loss = loss / pred_spectro.size(1)
                loss.backward()
    
                if i % 1_000 == 0:
                    print(f'iter: {i}, loss: {loss.item():.6f}')
                    print(f'd_loss_pred {pred_spectro.grad.mean()}')
    
                optimizer.step()
                optimizer.zero_grad()
    

    Curious to hear how your training is going! Best. Taras

    opened by taras-sereda 1
Releases(v0.1.0)
Owner
Keon Lee
Conversational AI | Expressive Speech Synthesis | Open-domain Dialog | Empathic Computing | NLP | Disentangled Representation | Generative Models | HCI
Keon Lee
Code for our paper A Transformer-Based Feature Segmentation and Region Alignment Method For UAV-View Geo-Localization,

FSRA This repository contains the dataset link and the code for our paper A Transformer-Based Feature Segmentation and Region Alignment Method For UAV

Dmmm 32 Dec 18, 2022
🤗 Transformers: State-of-the-art Natural Language Processing for Pytorch, TensorFlow, and JAX.

English | 简体中文 | 繁體中文 State-of-the-art Natural Language Processing for Jax, PyTorch and TensorFlow 🤗 Transformers provides thousands of pretrained mo

Hugging Face 77.2k Jan 02, 2023
Multi-modal co-attention for drug-target interaction annotation and Its Application to SARS-CoV-2

CoaDTI Multi-modal co-attention for drug-target interaction annotation and Its Application to SARS-CoV-2 Abstract Environment The test was conducted i

Layne_Huang 7 Nov 14, 2022
Churn-Prediction-Project - In this project, a churn prediction model is developed for a private bank as a term project for Data Mining class.

Churn-Prediction-Project In this project, a churn prediction model is developed for a private bank as a term project for Data Mining class. Project in

1 Jan 03, 2022
Autoformer: Decomposition Transformers with Auto-Correlation for Long-Term Series Forecasting

Autoformer (NeurIPS 2021) Autoformer: Decomposition Transformers with Auto-Correlation for Long-Term Series Forecasting Time series forecasting is a c

THUML @ Tsinghua University 847 Jan 08, 2023
Code for our CVPR 2022 Paper "GEN-VLKT: Simplify Association and Enhance Interaction Understanding for HOI Detection"

GEN-VLKT Code for our CVPR 2022 paper "GEN-VLKT: Simplify Association and Enhance Interaction Understanding for HOI Detection". Contributed by Yue Lia

Yue Liao 47 Dec 04, 2022
[ICML 2021] Towards Understanding and Mitigating Social Biases in Language Models

Towards Understanding and Mitigating Social Biases in Language Models This repo contains code and data for evaluating and mitigating bias from generat

Paul Liang 42 Jan 03, 2023
The official PyTorch code for NeurIPS 2021 ML4AD Paper, "Does Thermal data make the detection systems more reliable?"

MultiModal-Collaborative (MMC) Learning Framework for integrating RGB and Thermal spectral modalities This is the official code for NeurIPS 2021 Machi

NeurAI 12 Nov 02, 2022
Code accompanying "Evolving spiking neuron cellular automata and networks to emulate in vitro neuronal activity," accepted to IEEE SSCI ICES 2021

Evolving-spiking-neuron-cellular-automata-and-networks-to-emulate-in-vitro-neuronal-activity Code accompanying "Evolving spiking neuron cellular autom

SOCRATES: Self-Organizing Computational substRATES 2 Dec 02, 2022
Code to reproduce the results for Compositional Attention

Compositional-Attention This repository contains the official implementation for the paper Compositional Attention: Disentangling Search and Retrieval

Sarthak Mittal 58 Nov 30, 2022
A curated list of Machine Learning and Deep Learning tutorials in Jupyter Notebook format ready to run in Google Colaboratory

Awesome Machine Learning Jupyter Notebooks for Google Colaboratory A curated list of Machine Learning and Deep Learning tutorials in Jupyter Notebook

Carlos Toxtli 245 Jan 01, 2023
A framework for analyzing computer vision models with simulated data

3DB: A framework for analyzing computer vision models with simulated data Paper Quickstart guide Blog post Installation Follow instructions on: https:

3DB 112 Jan 01, 2023
[CVPR 2022] Pytorch implementation of "Templates for 3D Object Pose Estimation Revisited: Generalization to New objects and Robustness to Occlusions" paper

template-pose Pytorch implementation of "Templates for 3D Object Pose Estimation Revisited: Generalization to New objects and Robustness to Occlusions

Van Nguyen Nguyen 92 Dec 28, 2022
Disentangled Lifespan Face Synthesis

Disentangled Lifespan Face Synthesis Project Page | Paper Demo on Colab Preparation Please follow this github to prepare the environments and dataset.

何森 50 Sep 20, 2022
Code for ViTAS_Vision Transformer Architecture Search

Vision Transformer Architecture Search This repository open source the code for ViTAS: Vision Transformer Architecture Search. ViTAS aims to search fo

46 Dec 17, 2022
This is the code related to "Sparse-to-dense Feature Matching: Intra and Inter domain Cross-modal Learning in Domain Adaptation for 3D Semantic Segmentation" (ICCV 2021).

Sparse-to-dense Feature Matching: Intra and Inter domain Cross-modal Learning in Domain Adaptation for 3D Semantic Segmentation This is the code relat

39 Sep 23, 2022
Unofficial implementation of Alias-Free Generative Adversarial Networks. (https://arxiv.org/abs/2106.12423) in PyTorch

alias-free-gan-pytorch Unofficial implementation of Alias-Free Generative Adversarial Networks. (https://arxiv.org/abs/2106.12423) This implementation

Kim Seonghyeon 502 Jan 03, 2023
Motion planning environment for Sampling-based Planners

Sampling-Based Motion Planners' Testing Environment Sampling-based motion planners' testing environment (sbp-env) is a full feature framework to quick

Soraxas 23 Aug 23, 2022
Enhancing Aspect-Based Sentiment Analysis with Supervised Contrastive Learning.

Enhancing Aspect-Based Sentiment Analysis with Supervised Contrastive Learning. Enhancing Aspect-Based Sentiment Analysis with Supervised Contrastive

<a href=[email protected](SZ)"> 7 Dec 16, 2021
Official repository for the ICLR 2021 paper Evaluating the Disentanglement of Deep Generative Models with Manifold Topology

Official repository for the ICLR 2021 paper Evaluating the Disentanglement of Deep Generative Models with Manifold Topology Sharon Zhou, Eric Zelikman

Stanford Machine Learning Group 34 Nov 16, 2022