<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Work on Matias Di Bernardo</title><link>https://dibernardo.netlify.app/tags/work/</link><description>Recent content in Work on Matias Di Bernardo</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>Matías Di Bernardo</copyright><lastBuildDate>Mon, 24 Mar 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://dibernardo.netlify.app/tags/work/index.xml" rel="self" type="application/rss+xml"/><item><title>Generative AI, Flow Matching and TTS</title><link>https://dibernardo.netlify.app/p/generative-ai-flow-matching-and-tts/</link><pubDate>Mon, 24 Mar 2025 00:00:00 +0000</pubDate><guid>https://dibernardo.netlify.app/p/generative-ai-flow-matching-and-tts/</guid><description>&lt;img src="https://dibernardo.netlify.app/p/generative-ai-flow-matching-and-tts/front2.PNG" alt="Featured image of post Generative AI, Flow Matching and TTS" />&lt;p>At &lt;em>Intercambios Transorgánicos&lt;/em>, we continuously work with state-of-the-art &lt;em>Deep Learning&lt;/em> models. To achieve this, we stay up to date with the latest developments in the field. In this presentation, the objective was to explain the fundamentals of the &lt;em>F5-TTS&lt;/em> model, a cutting-edge speech synthesis system. During the session, the concept of generative artificial intelligence and flow-based models was introduced, as &lt;em>F5-TTS&lt;/em> is based on this technique. The purpose is to share this knowledge with the team and with anyone interested in getting started with &lt;em>Text-to-Speech&lt;/em> (TTS) models.&lt;/p>
&lt;h2 id="introduction---generative-ai-and-tts">Introduction - Generative AI and TTS
&lt;/h2>&lt;p>The class was structured as follows:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Introduction to TTS models&lt;/strong>: Description of the different models used, their main characteristics, and the reasons behind changing approaches.&lt;/li>
&lt;li>&lt;strong>Evolution of TTS models&lt;/strong>: A graph-based survey illustrating the progression of various TTS technologies.&lt;/li>
&lt;li>&lt;strong>Paradigm shift in language models&lt;/strong>: Explanation of how using large datasets has enabled better generalization in language models.&lt;/li>
&lt;li>&lt;strong>Example of generalization&lt;/strong>: Illustrative cases, such as generating an image of an astronaut riding a horse, audio examples, and synthesis of specific accents (e.g., an angry Cordoban speaker).&lt;/li>
&lt;li>&lt;strong>Change in dataset structuring&lt;/strong>:
&lt;ul>
&lt;li>&lt;strong>Traditional approach&lt;/strong>: Use of a single high-quality speaker with a large amount of data (model trained for each speaker).&lt;/li>
&lt;li>&lt;strong>Current and future approach&lt;/strong>: Use of diverse datasets with labels that enable training models capable of understanding speech concepts and generalizing across multiple tasks (&lt;em>VoiceBox&lt;/em> examples).&lt;/li>
&lt;li>&lt;strong>Computational cost&lt;/strong>: Discussion of the increasing model size and training difficulty, similar to large-scale language models (&lt;em>LLMs&lt;/em>).&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;strong>Explanation of Generative AI&lt;/strong>:
&lt;ul>
&lt;li>Introduction to generative models and the concept of underlying distribution.&lt;/li>
&lt;li>Explanation of &lt;em>Transformers&lt;/em> and their function in classification with context. Clarification that while &lt;em>Transformers&lt;/em> are &lt;em>Non-Autoregressive&lt;/em> (NAR) during training, they operate &lt;em>Autoregressively&lt;/em> (AR) in inference.&lt;/li>
&lt;li>Difference between classification models and generative models based on dimensionality reduction and latent variables.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h2 id="tts-models-voicebox-e2-and-f5">TTS Models: VoiceBox, E2, and F5
&lt;/h2>&lt;p>This section details the key advancements in TTS models leading to the development of &lt;em>F5-TTS&lt;/em>.&lt;/p>
&lt;h3 id="1-voicebox-tts---in-context-learning">1. VoiceBox TTS - &lt;em>In Context Learning&lt;/em>
&lt;/h3>&lt;p>The initial architecture of &lt;em>VoiceBox&lt;/em> is introduced, focusing on generalization through &lt;em>In Context Learning&lt;/em>. This approach allows the model to infer information based on prior examples. To achieve this, it is given an audio sample with a missing segment, forcing it to complete it coherently.&lt;/p>
&lt;blockquote>
&lt;p>&lt;em>&amp;ldquo;We show that Voicebox’s text-guided speech infilling approach is much more scalable in terms of data while subsuming many common speech generative tasks.&amp;rdquo;&lt;/em>&lt;/p>
&lt;/blockquote>
&lt;p>This method, introduced by Meta in &lt;em>VoiceBox&lt;/em>, represents a paradigm shift by demonstrating that TTS models can benefit from techniques previously used in language and image models.&lt;/p>
&lt;p>However, the model still relies on classical TTS techniques such as phoneme duration prediction and &lt;em>Forced Alignment&lt;/em> to map phonemes to Mel spectrograms, as their lengths do not match those of text tokens.&lt;/p>
&lt;h3 id="2-e2-tts---filler-tokens">2. E2 TTS - &lt;em>Filler Tokens&lt;/em>
&lt;/h3>&lt;p>&lt;em>E2 TTS&lt;/em> simplifies many of the architectural decisions of &lt;em>VoiceBox&lt;/em>, particularly in handling the differing lengths of Mel spectrograms and text. Instead of using forced alignment, it introduces &lt;em>Filler Tokens&lt;/em>, which allow text and audio dimensions to be equalized more efficiently. This approach makes it easier for the model to learn temporal associations between the two elements.&lt;/p>
&lt;p>Another significant change is that the model directly processes text instead of phonemes. While this might seem disadvantageous (since homographic words can have different pronunciations), context provides enough information to infer the correct pronunciation, similar to how humans process natural language.&lt;/p>
&lt;h3 id="3-f5-tts---open-source">3. F5 TTS - &lt;em>Open Source&lt;/em>
&lt;/h3>&lt;p>Although &lt;em>E2 TTS&lt;/em> is a major step forward, its training is slow due to the need to infer associations that were previously guided. &lt;em>F5 TTS&lt;/em> optimizes the previous model with the following improvements:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Use of ConvNeXt&lt;/strong>: Enhances text processing.&lt;/li>
&lt;li>&lt;strong>Architectural change&lt;/strong>: Replaces the &lt;em>U-Net&lt;/em> network with &lt;em>DiT&lt;/em> (&lt;em>Diffusion Transformer&lt;/em>).&lt;/li>
&lt;li>&lt;strong>Sway Sampling&lt;/strong>: Optimizes the inference process.&lt;/li>
&lt;/ul>
&lt;p>Additionally, &lt;em>F5-TTS&lt;/em> is open-source, facilitating adoption and improvement by the community.&lt;/p>
&lt;h2 id="flow-matching---theoretical-foundations">Flow Matching - Theoretical Foundations
&lt;/h2>&lt;p>To understand how &lt;em>F5-TTS&lt;/em> works, it is essential to review the models it is based on, known as &lt;em>Flow Matching Models&lt;/em>. These models have evolved from previous techniques in probabilistic distribution modeling.&lt;/p>
&lt;h3 id="1-normalizing-flow">1. Normalizing Flow
&lt;/h3>&lt;p>&lt;em>Normalizing Flows&lt;/em> are a family of probabilistic models that transform a simple distribution into a more complex one through a series of invertible and differentiable functions. They are used to model high-dimensional data distributions and generate realistic samples with precise control over probability.&lt;/p>
&lt;h3 id="2-residual-flow">2. Residual Flow
&lt;/h3>&lt;p>&lt;em>Residual Flows&lt;/em> extend &lt;em>Normalizing Flows&lt;/em> by allowing more flexible transformations without strictly adhering to the invertibility condition. This is achieved through residual networks that approximate transformation functions without structural constraints.&lt;/p>
&lt;h3 id="3-continuous-normalizing-flows-cnf">3. Continuous Normalizing Flows (CNF)
&lt;/h3>&lt;p>&lt;em>Continuous Normalizing Flows&lt;/em> reformulate &lt;em>Normalizing Flows&lt;/em> using ordinary differential equations (ODEs). Instead of applying discrete transformations in successive steps, these models learn a continuous dynamic in the latent space, allowing for greater expressiveness and computational efficiency.&lt;/p>
&lt;h3 id="4-flow-matching">4. Flow Matching
&lt;/h3>&lt;p>&lt;em>Flow Matching&lt;/em> is a technique that optimizes the transformation of a reference distribution into a target distribution by minimizing a specific cost function. It differs from previous approaches by not requiring explicit density function calculations, making it particularly useful for large-scale generative models such as &lt;em>F5-TTS&lt;/em>.&lt;/p>
&lt;h2 id="online-presentation">Online Presentation
&lt;/h2>&lt;p>All of this sections are explained in detail on the online class avaliable here (in Spanish):&lt;/p>
&lt;div class="video-wrapper">
&lt;iframe loading="lazy"
src="https://www.youtube.com/embed/YIpvFC41NUw"
allowfullscreen
title="YouTube Video"
>
&lt;/iframe>
&lt;/div></description></item><item><title>Understanding FastPitch and the Transformer Architecture</title><link>https://dibernardo.netlify.app/p/understanding-fastpitch-and-the-transformer-architecture/</link><pubDate>Wed, 23 Aug 2023 00:00:00 +0000</pubDate><guid>https://dibernardo.netlify.app/p/understanding-fastpitch-and-the-transformer-architecture/</guid><description>&lt;img src="https://dibernardo.netlify.app/p/understanding-fastpitch-and-the-transformer-architecture/front.png" alt="Featured image of post Understanding FastPitch and the Transformer Architecture" />&lt;p>Understanding a modern deep learning model is challenging due to the extensive prior knowledge required and the rapid pace of advancements in the field. In the research project &lt;em>Intercambios Transorgánicos&lt;/em>, we are working with TTS, specifically the FastPitch model from Nvidia. I have studied this model to fine-tune it for Spanish and shared my research process in a class to help my colleagues in the research group understand it better.&lt;/p>
&lt;h2 id="understanding-seq2seq-models">Understanding Seq2Seq Models
&lt;/h2>&lt;p>In &lt;em>Intercambios Transorgánicos&lt;/em>, we previously used Tacotron2 as our TTS model. While Tacotron2 performs well, it has several issues, primarily during training and inference, due to its auto-regressive nature. In contrast, FastPitch is a non-auto-regressive (NAR) model. To grasp these distinctions, I delved into seq2seq models, exploring their evolution over time and creating a quick overview of the sequence analysis models that have been pivotal:&lt;/p>
&lt;ul>
&lt;li>RNN&lt;/li>
&lt;li>LSTM&lt;/li>
&lt;li>Transformers&lt;/li>
&lt;/ul>
&lt;p>Tacotron2 is based on an LSTM (AR) model, whereas FastPitch utilizes Transformers (NAR). Understanding this technological progression provides crucial background knowledge, particularly about transformers, including positional encoding, a key factor in their non-auto-regressive nature, and the attention mechanism.&lt;/p>
&lt;h2 id="the-transformer-architecture">The Transformer Architecture
&lt;/h2>&lt;p>I began by studying the transformer architecture, as it is fundamental to the FastPitch model. I reviewed online resources and the seminal &lt;em>Attention is All You Need&lt;/em> paper. Below are some key points I noted during my study:&lt;/p>
&lt;ol>
&lt;li>
&lt;p>&lt;strong>Self-Attention Mechanism&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Purpose&lt;/strong>: Dynamically focuses on different parts of the input sequence.&lt;/li>
&lt;li>&lt;strong>Mechanism&lt;/strong>:
&lt;ul>
&lt;li>Query (Q), Key (K), Value (V): Derived from input embeddings.&lt;/li>
&lt;li>Attention scores are computed as the dot product of Q and K, scaled by the square root of the dimension.&lt;/li>
&lt;li>Scores are normalized using softmax to create attention weights.&lt;/li>
&lt;li>A weighted sum of V is computed based on these weights to produce the output.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Multi-Head Attention&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Purpose&lt;/strong>: Captures diverse relationships between tokens by applying multiple self-attention mechanisms in parallel.&lt;/li>
&lt;li>&lt;strong>Mechanism&lt;/strong>: Outputs from multiple attention heads are concatenated and linearly transformed.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Positional Encoding&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Purpose&lt;/strong>: Provides information about token order in the sequence, compensating for the Transformer&amp;rsquo;s lack of built-in sequence order (unlike RNNs).&lt;/li>
&lt;li>&lt;strong>Mechanism&lt;/strong>: A fixed or learnable vector is added to the input embeddings.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Encoder-Decoder Structure&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Encoder&lt;/strong>: Processes the input sequence into context-rich representations.
&lt;ul>
&lt;li>Components:
&lt;ul>
&lt;li>Multi-head self-attention&lt;/li>
&lt;li>Feed-forward neural network (FFN)&lt;/li>
&lt;li>Layer normalization and residual connections&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>&lt;strong>Decoder&lt;/strong>: Generates the output sequence by attending to both encoder outputs and previously generated tokens.
&lt;ul>
&lt;li>Components:
&lt;ul>
&lt;li>Masked multi-head self-attention (prevents attending to future tokens)&lt;/li>
&lt;li>Multi-head attention over encoder outputs&lt;/li>
&lt;li>FFN, layer normalization, and residual connections&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Feed-Forward Network (FFN)&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Purpose&lt;/strong>: Introduces non-linearity and processes each token independently.&lt;/li>
&lt;li>&lt;strong>Mechanism&lt;/strong>: Two linear layers with a ReLU activation in between.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Layer Normalization and Residual Connections&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Purpose&lt;/strong>: Stabilizes training and improves gradient flow by normalizing inputs to each layer and adding skip connections.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h2 id="fastpitch">FastPitch
&lt;/h2>&lt;p>After covering the theory, I examined each section of the FastPitch architecture in detail. I provided a brief explanation of word embeddings and positional encoding, as these are complex topics, and I wanted to keep the class concise.
FastPitch converts text into mel spectrograms, which are then transformed into audio by another model (in our case, HiFi-GAN). The training sequence involves the following steps:&lt;/p>
&lt;ol>
&lt;li>Text to Word Embedding&lt;/li>
&lt;li>Word Embedding concatenated with mel spectrogram&lt;/li>
&lt;li>Positional encoding and FFT (Feed-Forward Transformer block)&lt;/li>
&lt;li>Pitch Prediction&lt;/li>
&lt;li>Phoneme Duration Prediction&lt;/li>
&lt;li>Another FFT block&lt;/li>
&lt;li>Fully connected layer&lt;/li>
&lt;li>Output mel spectrogram&lt;/li>
&lt;/ol>
&lt;p>For each block, I presented the corresponding equations and provided qualitative explanations for their roles in the model. For instance, phoneme duration prediction is crucial for aligning a phoneme&amp;rsquo;s duration with the expected duration in the spectrogram.&lt;/p>
&lt;h2 id="online-class">Online Class
&lt;/h2>&lt;p>Finally, I summarized the most important points and conducted an online class to share these concepts with my colleagues. You can watch it here (in Spanish):&lt;/p>
&lt;div class="video-wrapper">
&lt;iframe loading="lazy"
src="https://www.youtube.com/embed/v4bt8bGIM00"
allowfullscreen
title="YouTube Video"
>
&lt;/iframe>
&lt;/div></description></item></channel></rss>