<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Deep Learning on Matias Di Bernardo</title><link>https://dibernardo.netlify.app/categories/deep-learning/</link><description>Recent content in Deep Learning 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/categories/deep-learning/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>The effect of denosing on TTS</title><link>https://dibernardo.netlify.app/p/the-effect-of-denosing-on-tts/</link><pubDate>Fri, 22 Nov 2024 00:00:00 +0000</pubDate><guid>https://dibernardo.netlify.app/p/the-effect-of-denosing-on-tts/</guid><description>&lt;p>This study was conducted in the context of the class &lt;em>Laboratorio de Acústica&lt;/em> at UNTREF. I chose this topic because it aligns with research I have been pursuing as part of the group &lt;em>Intercambios Transorgánicos&lt;/em>. The class assignment involved conducting a subjective study using a survey to explore the relationship between objective and subjective variables.&lt;/p>
&lt;p>In my research group, I have been investigating how denoising algorithms affect Text-to-Speech (TTS) systems trained on low-quality recordings. The focus is on Rioplatense Spanish, a regional accent with limited high-quality data. Within this context, it was natural to combine both tasks and perform a subjective test on the impact of denoising algorithms on TTS systems.&lt;/p>
&lt;h2 id="overview">Overview
&lt;/h2>&lt;p>The key points of this investigation are:&lt;/p>
&lt;ul>
&lt;li>Evaluation of three denoising algorithms: Wave U-Net, HiFi-GAN, and DeepFilterNet.&lt;/li>
&lt;li>Use of both subjective (CMOS) and objective metrics (PESQ, STOI, MCD).&lt;/li>
&lt;li>Insights into resource-efficient TTS model development for underrepresented accents.&lt;/li>
&lt;/ul>
&lt;h2 id="methodology">Methodology
&lt;/h2>&lt;ul>
&lt;li>&lt;strong>Algorithms&lt;/strong>: Wave U-Net, HiFi-GAN, and DeepFilterNet evaluated with the FastPitch TTS model.&lt;/li>
&lt;li>&lt;strong>Dataset&lt;/strong>: Subset of the ArchiVoz collection (15 minutes of noisy audio).&lt;/li>
&lt;li>&lt;strong>Testing&lt;/strong>: CMOS subjective test and objective metrics (PESQ, STOI, MCD).&lt;/li>
&lt;li>&lt;strong>Participants&lt;/strong>: 24 valid responses, including both experts and non-experts.&lt;/li>
&lt;/ul>
&lt;h2 id="key-findings">Key Findings
&lt;/h2>&lt;ol>
&lt;li>
&lt;p>&lt;strong>DeepFilterNet Performance&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>Achieved the highest CMOS score, reflecting the best subjective quality.&lt;/li>
&lt;li>Demonstrated significant improvements in TTS output despite mixed correlations with objective metrics.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Objective Metrics Analysis&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>PESQ and MCD showed limited correlation with subjective preferences.&lt;/li>
&lt;li>STOI scores were consistent across algorithms, indicating preserved intelligibility.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Algorithm Comparisons&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>DeepFilterNet&lt;/strong>: Superior subjective evaluations, moderate MCD.&lt;/li>
&lt;li>&lt;strong>Demucs&lt;/strong>: Comparable to DeepFilterNet in PESQ but lower subjective scores.&lt;/li>
&lt;li>&lt;strong>Wave U-Net&lt;/strong>: Poor subjective and objective performance.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>&lt;strong>Subject Expertise&lt;/strong>:&lt;/p>
&lt;ul>
&lt;li>No significant differences were observed between expert and non-expert evaluations in subjective testing.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ol>
&lt;h2 id="implications">Implications
&lt;/h2>&lt;ul>
&lt;li>&lt;strong>Efficiency&lt;/strong>: Advanced denoising methods like DeepFilterNet can enhance TTS systems without requiring high-quality recordings.&lt;/li>
&lt;li>&lt;strong>Limitations&lt;/strong>: Objective metrics like PESQ and MCD are insufficient standalone indicators of subjective TTS quality.&lt;/li>
&lt;li>&lt;strong>Future Work&lt;/strong>:
&lt;ul>
&lt;li>Expand datasets and noise levels for more robust analysis.&lt;/li>
&lt;li>Explore TTS systems trained jointly with denoising algorithms.&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h2 id="conclusions">Conclusions
&lt;/h2>&lt;p>This work concludes that preprocessing with DeepFilterNet significantly improves TTS performance, with a 1.1 CMOS score increase. These findings underscore the importance of algorithm selection in optimizing low-resource TTS systems. Additionally, I gained valuable insights into subjective evaluations and the statistical analysis required to draw meaningful conclusions from data.&lt;/p>
&lt;p>All the information for this study can be found in the &lt;a class="link" href="https://drive.google.com/file/d/1F4aJGIU9FX2LT8OFik-Yjg4uSz6T09jw/view?usp=sharing" target="_blank" rel="noopener"
>academic report&lt;/a>.&lt;/p></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><item><title>AI learns to play 2048 game</title><link>https://dibernardo.netlify.app/p/ai-learns-to-play-2048-game/</link><pubDate>Fri, 17 Feb 2023 00:00:00 +0000</pubDate><guid>https://dibernardo.netlify.app/p/ai-learns-to-play-2048-game/</guid><description>&lt;img src="https://dibernardo.netlify.app/p/ai-learns-to-play-2048-game/game_img.jpg" alt="Featured image of post AI learns to play 2048 game" />&lt;p>I used this project as an introduction to Reinforcement Learning. Having mostly worked with supervised and unsupervised learning, I wanted to start with a small, simple project to quickly grasp the main ideas and create something fun. I followed this &lt;a class="link" href="https://youtu.be/L8ypSXwyBds" target="_blank" rel="noopener"
>YouTube video&lt;/a> as a reference, which explains how to use Reinforcement Learning (RL) to train a model capable of playing the snake game. To make it more challenging, I applied the same network to the 2048 game.&lt;/p>
&lt;h2 id="code">Code
&lt;/h2>&lt;p>The code has three main components:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>The Game&lt;/strong>: Implements the game logic and the graphical user interface (GUI).&lt;/li>
&lt;li>&lt;strong>Agent&lt;/strong>: Controls the gameplay.&lt;/li>
&lt;li>&lt;strong>AI Model&lt;/strong>: A neural network that learns how to play and guides the agent.&lt;/li>
&lt;/ul>
&lt;h3 id="game-state">Game State
&lt;/h3>&lt;p>I modeled the game state as a 4x4 matrix representing the board. The actions in the game are represented by a vector, with the following possibilities:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Left&lt;/strong>: [1, 0, 0, 0]&lt;/li>
&lt;li>&lt;strong>Right&lt;/strong>: [0, 1, 0, 0]&lt;/li>
&lt;li>&lt;strong>Up&lt;/strong>: [0, 0, 1, 0]&lt;/li>
&lt;li>&lt;strong>Down&lt;/strong>: [0, 0, 0, 1]&lt;/li>
&lt;/ul>
&lt;h3 id="reward">Reward
&lt;/h3>&lt;p>The RL model works with rewards to quantify when the agent performs well or poorly. Initially, I defined the following rewards:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>+10 points&lt;/strong>: When the agent doubles the points. This is crucial because, in 2048, points increase exponentially.&lt;/li>
&lt;li>&lt;strong>-10 points&lt;/strong>: When the game is lost. This serves as a straightforward negative reward.&lt;/li>
&lt;/ul>
&lt;p>Initially, the model showed slow improvement. To address this, I added an additional reward:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>+2 points&lt;/strong>: When points are increased. This reward incentivizes actions that maximize board clearance and progress.&lt;/li>
&lt;/ul>
&lt;h2 id="how-the-model-works">How the Model Works
&lt;/h2>&lt;p>The model is a simple linear neural network. It takes the game state as input and predicts the best next action to maximize the reward.&lt;/p>
&lt;p>Rewards are managed using a technique called Q-Learning. A &lt;em>Q Value&lt;/em> represents the quality of a decision based on the loss function. The loss function is derived from the &lt;em>Bellman Equation&lt;/em>:&lt;/p>
$$
NewQ(s, a) = Q(s, a) + \alpha [R(s, a) + \lambda \, \text{max}Q'(s', a') - Q(s, a)]
$$&lt;p>Where:&lt;/p>
&lt;ul>
&lt;li>$Q(s, a)$: The &lt;em>Q Value&lt;/em> for a specific state and action.&lt;/li>
&lt;li>$\alpha$: Learning rate.&lt;/li>
&lt;li>$R(s, a)$: Reward for a specific state and action.&lt;/li>
&lt;li>$\lambda$: Discount rate.&lt;/li>
&lt;li>$\text{max}Q&amp;rsquo;(s&amp;rsquo;, a&amp;rsquo;)$: Maximum expected future reward.&lt;/li>
&lt;/ul>
&lt;h2 id="experiments-and-results">Experiments and Results
&lt;/h2>&lt;h3 id="random-test-as-a-baseline">Random Test as a Baseline
&lt;/h3>&lt;p>To establish a baseline, I tested the average score achievable by taking random actions. After 1,000 iterations, the average score was &lt;strong>170&lt;/strong>, far below the 2048 points needed to win the game.&lt;/p>
&lt;h3 id="initial-results">Initial Results
&lt;/h3>&lt;p>My initial attempts were discouraging. The model performed worse than random movements. Here are some early results:&lt;/p>
&lt;ol>
&lt;li>&lt;strong>Game 1,000&lt;/strong> | Score: 208 | Record: 416 | Mean Score: 200 | Reward: 640&lt;/li>
&lt;li>&lt;strong>Game 1,000&lt;/strong> | Score: 116 | Record: 346 | Mean Score: 161 | Reward: 310&lt;/li>
&lt;li>&lt;strong>Game 1,000&lt;/strong> | Score: 112 | Record: 348 | Mean Score: 146 | Reward: 320&lt;/li>
&lt;/ol>
&lt;p>In these attempts, the agent developed a suboptimal strategy of filling the board before increasing points.&lt;/p>
&lt;h3 id="improvements">Improvements
&lt;/h3>&lt;p>After experimenting with the reward parameters, I focused on the exploration phase. Initially, the &lt;em>exploration games&lt;/em> parameter, which randomly picks moves, was set to 25 games. Increasing this parameter allowed the agent to explore more strategies, leading to better results:&lt;/p>
&lt;ol start="4">
&lt;li>&lt;strong>Game 1,000&lt;/strong> | Score: 478 | Record: 478 | Mean Score: 230&lt;/li>
&lt;li>&lt;strong>Game 1,000&lt;/strong> | Score: 514 | Record: 964 | Mean Score: 382&lt;/li>
&lt;/ol>
&lt;p>As the model improved, I extended the training to more games:&lt;/p>
&lt;ol start="6">
&lt;li>&lt;strong>Game 3,796&lt;/strong> | Score: 770 | Record: 1,366 | Mean Score: 469&lt;/li>
&lt;li>&lt;strong>Game 4,852&lt;/strong> | Score: 631 | Record: 1,462 | Mean Score: 483&lt;/li>
&lt;/ol>
&lt;p>Finally, with 200 exploration games and 5,000 training games, the results were as follows:&lt;/p>
&lt;ol start="8">
&lt;li>&lt;strong>Game 5,000&lt;/strong> | Score: 840 | Record: 1,678 | Mean Score: 512&lt;/li>
&lt;/ol>
&lt;p>Although the model didn&amp;rsquo;t beat the game, I was satisfied with the progress. I believe that with longer training (the final run lasted 4 hours) and additional network layers, it would be possible to win the game using this architecture.&lt;/p>
&lt;h2 id="demo">Demo
&lt;/h2>&lt;p>Here is a demo of the application, showcasing the agent&amp;rsquo;s learning process:&lt;/p>
&lt;div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
&lt;iframe src="https://player.vimeo.com/video/1045495533" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="vimeo video" webkitallowfullscreen mozallowfullscreen allowfullscreen>&lt;/iframe>
&lt;/div>
&lt;p>I implemented keybindings to control the game&amp;rsquo;s speed, providing three options:&lt;/p>
&lt;ul>
&lt;li>&lt;strong>Fast&lt;/strong>: For rapid training.&lt;/li>
&lt;li>&lt;strong>Slow&lt;/strong>: To observe and analyze the agent&amp;rsquo;s progress and mistakes.&lt;/li>
&lt;li>&lt;strong>Medium&lt;/strong>: Rarely used.&lt;/li>
&lt;/ul>
&lt;p>The complete code for this project is available in this &lt;a class="link" href="https://github.com/MatiasDiBernardo/RF_2048-game" target="_blank" rel="noopener"
>repository&lt;/a>.&lt;/p></description></item><item><title>Evaluation of different models for Speaker Diarization task</title><link>https://dibernardo.netlify.app/p/evaluation-of-different-models-for-speaker-diarization-task/</link><pubDate>Fri, 04 Nov 2022 00:00:00 +0000</pubDate><guid>https://dibernardo.netlify.app/p/evaluation-of-different-models-for-speaker-diarization-task/</guid><description>&lt;p>This project started as the final assignment for a seminar class at UNTREF called &lt;em>Seminario en Aplicaciones de Redes Neuronales en la recuperación de información musical&lt;/em>. The objective was to use a Siamese Neural Network (SNN) in a different context than the one explored in class (music similarity detection).&lt;/p>
&lt;p>For the final project of this course, we developed an SNN model from scratch using the &lt;em>Keras&lt;/em> framework and the &lt;em>SincNet&lt;/em> architecture to reduce audio dimensionality, achieving good results. Later, to expand this project, I tried another approach by using &lt;em>Wav2Vec&lt;/em> for dimensionality reduction and re-implementing the entire project in the &lt;em>PyTorch&lt;/em> framework. This attempt, however, yielded suboptimal results, indicating that the dimensionality reduction using Wav2Vec lost critical information required for the speaker diarization task.&lt;/p>
&lt;h2 id="speaker-diarization-task">Speaker Diarization Task
&lt;/h2>&lt;p>The goal of a speaker diarization model is to identify different speakers in an audio stream containing multiple speakers. For example, in a podcast with two people (A and B), the model must determine the time steps where speaker A is talking and the time steps where speaker B is speaking (and implicitly identify the periods of silence). These models are incredibly useful for audio editing and analyzing long audio sequences with multiple speakers.&lt;/p>
&lt;h2 id="why-siamese-neural-networks">Why Siamese Neural Networks?
&lt;/h2>&lt;p>In class, we explored the Siamese architecture to compare similarities between pieces of music, developing a tool capable of identifying covers of famous songs.&lt;/p>
&lt;p>A Siamese Neural Network consists of two or more identical subnetworks sharing the same weights and parameters. It is designed to compare input pairs and measure their similarity, typically using a distance metric like Euclidean distance. Each subnetwork processes one input, and the outputs are combined to compute a similarity score.&lt;/p>
&lt;p>With this similarity comparison in mind, we wanted to apply these networks to the speaker diarization task. The idea was to generate speaker embeddings from audio using a pre-trained model and compare the outputs of different audio segments. Based on the similarity score, we aimed to identify the segments where different speakers are talking.&lt;/p>
&lt;h2 id="experiments">Experiments
&lt;/h2>&lt;p>I tested two different methods for audio feature extraction to serve as speaker embeddings.&lt;/p>
&lt;h3 id="keras-implementation-with-sincnet">Keras Implementation with SincNet
&lt;/h3>&lt;p>In this approach, we used the SincNet architecture to extract speaker-specific features from audio. SincNet applies learnable sinc functions as its filters, which are particularly well-suited for audio processing as they mimic traditional bandpass filters. These features were then fed into the Siamese Neural Network, which compared pairs of audio segments to calculate their similarity scores. The model was trained on labeled audio datasets, and we observed strong performance in clustering audio segments by speaker, achieving clear boundaries between different speakers.&lt;/p>
&lt;p>A report with the results can be found in the following &lt;a class="link" href="https://github.com/MatiasDiBernardo/Speaker-Diarization-with-SNN/blob/master/TP%20Final%20Seminario%20Redes%20-%20Di%20Bernardo%20Ferreyra.ipynb" target="_blank" rel="noopener"
>Jupyter notebook&lt;/a> (in Spanish).&lt;/p>
&lt;h3 id="pytorch-implementation-with-wav2vec">PyTorch Implementation with Wav2Vec
&lt;/h3>&lt;p>For this method, I utilized Wav2Vec, a powerful pre-trained model for extracting deep audio embeddings. Unlike SincNet, Wav2Vec embeddings are derived from self-supervised learning, capturing high-level representations of audio. These embeddings were used in the Siamese Neural Network for similarity comparisons. However, the results were suboptimal for the diarization task. It appears that Wav2Vec, while excellent for speech recognition tasks, lost some speaker-specific details necessary for distinguishing between speakers in our setup.&lt;/p>
&lt;h2 id="results">Results
&lt;/h2>&lt;p>The experiments demonstrated that the choice of feature extraction method is crucial for speaker diarization. The Keras implementation with SincNet outperformed the PyTorch implementation with Wav2Vec, showing higher accuracy in identifying speaker transitions. This suggests that task-specific feature extraction, like SincNet, is more effective than general-purpose embeddings like Wav2Vec for speaker diarization.&lt;/p>
&lt;p>The code for this project is available in this &lt;a class="link" href="https://github.com/MatiasDiBernardo/Speaker-Diarization-with-SNN" target="_blank" rel="noopener"
>repository&lt;/a>.&lt;/p>
&lt;h2 id="conclusions">Conclusions
&lt;/h2>&lt;p>This project was one of my first experiences with deep learning models, where I applied my knowledge to a problem without following a specific paper or using a pre-trained model. I explored different solutions and concluded on the importance of feature extraction and model selection.&lt;/p>
&lt;p>It also helped me become familiar with the syntax of the most popular deep learning frameworks and solidified my understanding in the process.&lt;/p></description></item></channel></rss>