<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohammad Hassan Vali on Medium]]></title>
        <description><![CDATA[Stories by Mohammad Hassan Vali on Medium]]></description>
        <link>https://medium.com/@mohammad.vali?source=rss-840f2c687344------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GIGWvfLqSFR5k0T_1Nt7dw.jpeg</url>
            <title>Stories by Mohammad Hassan Vali on Medium</title>
            <link>https://medium.com/@mohammad.vali?source=rss-840f2c687344------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:58:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohammad.vali/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Anonymization of Speaker’s Attributes in DNN-Based Speech Processing Tools]]></title>
            <link>https://medium.com/data-science/speakers-privacy-protection-in-dnn-based-speech-processing-tools-f446ad1d8871?source=rss-840f2c687344------2</link>
            <guid isPermaLink="false">https://medium.com/p/f446ad1d8871</guid>
            <category><![CDATA[privacy-preserving]]></category>
            <category><![CDATA[thoughts-and-theory]]></category>
            <category><![CDATA[vector-quantization]]></category>
            <category><![CDATA[anonymization]]></category>
            <category><![CDATA[differential-privacy]]></category>
            <dc:creator><![CDATA[Mohammad Hassan Vali]]></dc:creator>
            <pubDate>Tue, 20 Aug 2024 00:42:52 GMT</pubDate>
            <atom:updated>2025-03-17T22:15:11.192Z</atom:updated>
            <content:encoded><![CDATA[<h4>A novel method in privacy-preserving speech processing which anonymizes the speaker attributes using space-filling vector quantization</h4><blockquote>This post is a short explanation of our proposed privacy preservation technique called Privacy-PORCUPINE [1] published at Interspeech 2024 conference. The post discusses a potential privacy threat that might happen when using ordinary vector quantization in the bottleneck of DNN-based speech processing tools. For more detail, please look at the paper under <a href="https://www.isca-archive.org/interspeech_2024/vali24_interspeech.pdf">this link</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aaWMhO5lX4wrUcZj" /><figcaption>Photo by <a href="https://unsplash.com/@aadeshjpg?utm_source=medium&amp;utm_medium=referral">Aadesh Thapa</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Speech is a convenient medium for interacting between humans and with technology, yet evidence demonstrates that it exposes speakers to threats to their privacy. A central issue is that, besides the linguistic content which may be private, speech contains also private side-information such as the speaker’s identity, age, state of health, ethnic background, gender, and emotions. Revealing such sensitive information to a listener may expose the speaker to threats such as price gouging, tracking, harassment, extortion, and identity theft. To protect speakers, privacy-preserving speech processing seeks to anonymize speech signals by stripping away private information that is not required for the downstream task [2].</p><p>A common operating principle for privacy-preserving speech processing is to pass information through an information bottleneck that is tight enough to allow only the desired information pass through it and prevent transmission of any other private information. Such bottlenecks can be implemented for example as <em>autoencoders</em>, where a neural network, known as the encoder, compresses information to a bottleneck, and a second network, the decoder, reconstructs the desired output. The information rate of the bottleneck can be quantified absolutely, only if it is quantized, and quantization is thus a required component of any proof of privacy [2]. The figure below shows a vector quantized variational autoencoder (VQ-VAE) architecture, and its bottleneck.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K8mnyo5ITi4gRHQUz8TtIw.png" /><figcaption>Figure 1: Architecture of a vector quantized variational autoencoder (VQ-VAE). (image by author)</figcaption></figure><p>As pointed out in the Privacy ZEBRA framework [3], we need to characterize privacy protections both in terms of average disclosure of private information (in bits) as well as worst-case disclosure (in bits). <a href="https://medium.com/towards-data-science/improving-vector-quantization-in-vector-quantized-variational-autoencoders-vq-vae-915f5814b5ce">Vector quantization</a> (VQ) [4] is a constant-bitrate quantizer in the sense that it quantizes the input with a codebook of K elements, and the indices of such a codebook can be expressed with B=log2(K) bits. This B equals to the average disclosure of private information in bits. In terms of the worst-case disclosure, it is obvious that different codebook elements are used with different frequencies (see Fig. 2.1 below). This means that a relatively smaller subset of speakers could be assigned to a particular codebook index, such that any time a speaker is assigned to that codebook index, the range of possible speakers is relatively smaller than for other codebook indices and the corresponding disclosure of private information is larger (for the speakers assigned to this particular codebook index). However, to the best of the authors’ knowledge, this disclosure has not previously been quantified nor do we have prior solutions for compensating for such an increase in disclosure. Hence, our main goal is to modify VQ such that all codebook elements have equal occurrence likelihoods to prevent private information leakage (and thus improve worst-case disclosure).</p><p>As a solution, we use here our recently proposed modification of VQ known as <a href="https://medium.com/towards-data-science/interpretable-latent-spaces-using-space-filling-vector-quantization-e4eb26691b14">space-filling vector quantization</a> (SFVQ) [5], which incorporates space-filling curves into VQ. We define the SFVQ as the linear continuation of VQ, such that subsequent codebook elements are connected with a line where inputs can be mapped to any point on that piece-wise continuous line (see Fig. 2.2). To read more about SFVQ, please see <a href="https://medium.com/towards-data-science/interpretable-latent-spaces-using-space-filling-vector-quantization-e4eb26691b14">this post</a>.</p><p>In our technique, named Privacy PORCUPINE [1], we proposed to use a codebook resampling method together with SFVQ, where a vector quantizer is resampled along the SFVQ’s curve, such that all elements of the resampled codebook have equal occurrence likelihoods (see Fig. 2.3 and 2.4).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z_WqFJr20D-IFBL0A0xrtg.png" /><figcaption>Figure 2: 1. Codebook vectors (blue points) of a 5 bit vector quantization applied on a Gaussian distribution (gray points); Voronoi-regions are shown in green 2. Space-filling vector quantization (SFVQ) with 5 bit applied on the same Gaussian distribution (curve in black with codebook vectors in blue) 3. Same SFVQ curve together with the resampled codebook vectors (red crosses) 4. Same resampled codebook vectors along with their Voronoi-regions (in green). (image by author)</figcaption></figure><h4>How we measure the disclosure?</h4><p>Figure 2.1 demonstrates that in areas where inputs are less likely, the Voronoi-regions are larger. Hence, such larger Voronoi-regions contain a smaller number of input samples. Similarly, small Voronoi-regions have a larger number of input samples. Such differences are due to the optimization of the codebook by minimizing the mean square error (MSE) criterion; more common inputs are quantized with a smaller error to minimize the average error. Our objective is to determine how such uneven distribution of inputs to codebook entries influences the disclosure of private information.</p><p>We measure disclosure in terms of how much the population size of possible identities for an unknown speaker is decreased with a new observation. In other words, assume that we have prior knowledge that the speaker belongs to a population of size M. If we have an observation that the speaker is quantized to an index k, we have to evaluate how many speakers L out of M will be quantized to the same index. This decrease can be quantified by the ratio of populations L/M corresponding to the disclosure of B_leak=log2(M/L) bits of information.</p><p>At the extreme, it is possible that only a single speaker may be quantized to a particular index. This means that only one speaker L=1 is quantized to the bin out of an arbitrarily large M, though in practice we can verify results only for finite M. Still, in theory, if M → ∞, then also the disclosure diverges B_leak → ∞ bits. The main objective of our proposed method is to modify vector quantization to prevent such catastrophic leaks.</p><h4>Codebook Resampling</h4><p>After training the space-filling vector quantizer (SFVQ) [5] on the training set comprising speaker embeddings for a population of M speakers (Fig. 2.2), we map all the M embedding vectors onto the learned curve. To normalize the occurrence frequency using K codebook vectors, each codebook element has to represent M/K speaker embeddings. In other words, each Voronoi- region should encompass M/K speaker embeddings. Considering these M mapped embeddings on SFVQ’s curve, we start from the first codebook element (one end of the curve), take the first M/K mapped embeddings, and calculate the average of these vectors. We define this average vector as the new resampled codebook vector (red crosses in Fig. 2.3) representing the first chunk of M/K speaker embeddings. Then similarly, we continue until we compute all K resampled codebook vectors for all K chunks of M/K speaker embeddings.</p><h4>Experiments</h4><p>In our experiments, we used <a href="https://commonvoice.mozilla.org/en/datasets">Common Voice corpus (version 16.1)</a> to get a large pool of speakers. We selected 10,240 speakers randomly for the test set and 79,984 speakers for the train set. To compute speaker embeddings, we used the pretrained speaker verification model of ECAPA-TDNN [6]. We trained vector quantization (VQ) and space-filling vector quantization (SFVQ) methods on the train set (of speaker embeddings) for different bitrates ranging from 4 bit to 10 bit (16 to 1024 codebook vectors).</p><p>As a showcase to compare VQ and resampled SFVQ, the figure below illustrates the occurrence frequencies for VQ and resampled SFVQ, both with 4 bit of information corresponding to 16 codebook vectors. By informal visual inspection we can see that entries in the proposed method are more uniformly distributed, as desired, but to confirm results we need a proper evaluation. To compare the obtained histograms from VQ and resampled SFVQ, we used different evaluation metrics which are discussed in the next section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ysJNITwUJ7Rm8WUiaMV-vA.png" /><figcaption>Figure 3: Probability of codebook occurrences for VQ and resampled SFVQ in case of 4 bit quantization. (image by author)</figcaption></figure><h4>Evaluation Metrics</h4><p>Suppose we have K codebook vectors (bins) to quantize a population of M speakers. Our target is to achieve a uniform distribution of samples onto the K codebook vectors, U(1,K), such that every codebook vector is used M/K times. If we sample M integers from the uniform distribution of U(1,K), we will obtain the histogram h(k). Then, if we take the histogram of occurrences in the bins of h(k) (i.e. histogram of histogram), we will see that the new histogram follows a binomial distribution f(k) such that</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmath.embed.fun%2Fembed%2Fkd6LEWwNjHfuqX79BFxzbi&amp;display_name=Embed+Fun&amp;url=https%3A%2F%2Fmath.embed.fun%2Fkd6LEWwNjHfuqX79BFxzbi&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=embed" width="328" height="158" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4051e956243d3ba2d3c27d13c0752f8/href">https://medium.com/media/b4051e956243d3ba2d3c27d13c0752f8/href</a></iframe><p>where the random variable X is the occurrence in each bin, n is the number of trials (n=M), and p is the success probability for each trial which is p=1/K. After obtaining the histogram of codebook indices occurrences g(k) (Figure 3) for both VQ and resampled SFVQ methods, we compute the histogram of occurrences in the bins of g(k) denoted by f_hat(k). The binomial distribution f(k) is the theoretical optimum, to which our observation f_hat(k) should coincide. Hence, we use Kullback-Leibler (KL) divergence between f(k) and f_hat(k) to assess the distance between the observed and the ideal distributions.</p><p>By having the histogram of occurrences g(k), we calculate the minimum of the histogram divided by the total number of samples (M=Σ g(k)) as the worst-case disclosure. We also compute the average disclosure as entropy of occurrence frequencies g(k)/M. In addition, we use a sparseness measure and standard deviation as heuristic measures of uniformity of the obtained histogram g(k). Here are the evaluation formulas:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmath.embed.fun%2Fembed%2FaRtAdVzF4UqyKQiEjL9Goe&amp;display_name=Embed+Fun&amp;url=https%3A%2F%2Fmath.embed.fun%2FaRtAdVzF4UqyKQiEjL9Goe&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=embed" width="723" height="324" frameborder="0" scrolling="no"><a href="https://medium.com/media/74d65270077510627168690510139c6e/href">https://medium.com/media/74d65270077510627168690510139c6e/href</a></iframe><h4>Results</h4><p>Figure 4 shows the performance of VQ and resampled SFVQ as a function of bitrate. In each case and for all bitrates, the proposed method (blue line) is below VQ (red line), indicating that the leakage of private information is smaller for the proposed method. One important point to mention is that as expected, resampled SFVQ makes the average disclosure to be slightly higher than VQ, whereas the average disclosure for both resampled SFVQ and VQ are extremely close to the upper bound of average disclosure where the histogram of occurrence frequencies is perfectly flat.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UP3UNNldI5ajRmhppnp-Aw.png" /><figcaption>Figure 4: Performance comparison between VQ and resampled SFVQ under evaluation metrics. (image by author)</figcaption></figure><h4>Conclusions</h4><p>Privacy-preserving speech processing is becoming increasingly important as the usage of speech technology is increasing. By removing superfluous private information from a speech signal by passing it through a quantized information bottleneck, we can gain provable protections for privacy. Such protections however rely on the assumption that quantization levels are used with equal frequency. Our theoretical analysis and experiments demonstrate that vector quantization, optimized with the minimum mean square (MSE) criterion, does generally not provide such uniform occurrence frequencies. In the worst case, some speakers could be uniquely identified even if the quantizer on average provides ample protection.</p><p>We proposed the resampled SFVQ method to avoid such privacy threats. The protection of privacy is thus achieved by increasing the quantization error for inputs that occur less frequently, while more common inputs gain better accuracy (see Fig. 2.4). This is in line with the theory of differential privacy [7].</p><p>We used speaker identification as an illustrative application, though the proposed method can be used in gaining a provable reduction of private information leakage for any attributes of speech. In summary, resampled SFVQ is a generic tool for privacy-preserving speech processing. It provides a method for quantifying the amount of information passing through an information bottleneck and thus forms the basis of speech processing methods with provable privacy.</p><h3>GitHub Repository</h3><p>The code for implementation of our proposed method and the relevant evaluations is publicly available in the following link:</p><p><a href="https://github.com/MHVali/Privacy-PORCUPINE.git">GitHub - MHVali/Privacy-PORCUPINE</a></p><h4>Acknowledgement</h4><p>Special thanks to my doctoral program supervisor <a href="https://research.aalto.fi/en/persons/tom-b%C3%A4ckstr%C3%B6m">Prof. Tom Bäckström</a>, who supported me and was the other contributor for this work.</p><h3>References</h3><p>[1] M.H. Vali, T. Bäckström, “Privacy PORCUPINE: Anonymization of Speaker Attributes Using Occurrence Normalization for Space-Filling Vector Quantization”, in <em>Proceedings of Interspeech</em>, 2024.</p><p>[2] T. Bäckström, “Privacy in speech technology”, 2024. [Online] Available at: <a href="https://arxiv.org/abs/2305.05227">https://arxiv.org/abs/2305.05227</a></p><p>[3] A. Nautsch et. al. , “The Privacy ZEBRA: Zero Evidence Biometric Recognition Assessment,” in <em>Proceedings of Interspeech</em>, 2020.</p><p>[4] M. H. Vali and T. Bäckström, “NSVQ: Noise Substitution in Vector Quantization for Machine Learning,” <em>IEEE Access</em>, 2022.</p><p>[5] M.H. Vali, T. Bäckström, “Interpretable Latent Space Using Space-Filling Curves for Phonetic Analysis in Voice Conversion”, in <em>Proceedings of Interspeech</em>, 2023.</p><p>[6] B. Desplanques, J. Thienpondt, and K. Demuynck, “ECAPA-TDNN: Emphasized Channel Attention, Propagation and Aggregation in TDNN Based Speaker Verification,” in <em>Proceedings of Interspeech</em>, 2020.</p><p>[7] C. Dwork, “Differential privacy: A survey of results,” in<br>International conference on theory and applications of models<br>of computation. Springer, 2008.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f446ad1d8871" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/speakers-privacy-protection-in-dnn-based-speech-processing-tools-f446ad1d8871">Anonymization of Speaker’s Attributes in DNN-Based Speech Processing Tools</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interpretable Latent Spaces Using Space-Filling Vector Quantization]]></title>
            <link>https://medium.com/data-science/interpretable-latent-spaces-using-space-filling-vector-quantization-e4eb26691b14?source=rss-840f2c687344------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4eb26691b14</guid>
            <category><![CDATA[interpretable-ai]]></category>
            <category><![CDATA[space-filling-curves]]></category>
            <category><![CDATA[vector-quantization]]></category>
            <category><![CDATA[deep-neural-networks]]></category>
            <category><![CDATA[latent-space]]></category>
            <dc:creator><![CDATA[Mohammad Hassan Vali]]></dc:creator>
            <pubDate>Mon, 08 Apr 2024 19:22:49 GMT</pubDate>
            <atom:updated>2024-08-16T09:32:24.728Z</atom:updated>
            <content:encoded><![CDATA[<h4>A new unsupervised method that combines two concepts of vector quantization and space-filling curves to interpret the latent space of DNNs.</h4><blockquote>This post is a short explanation of our novel unsupervised distribution modeling technique called space-filling vector quantization [1] published at Interspeech 2023 conference. For more details, please look at the paper under <a href="https://www.isca-archive.org/interspeech_2023/vali23_interspeech.pdf">this link</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*481OtKfJqJE7PgDyGstuvw.jpeg" /><figcaption>Image from <a href="https://stocksnap.io/">StockSnap.io</a></figcaption></figure><p>Deep generative models are well-known neural network-based architectures that learn a latent space whose samples can be mapped to sensible real-world data such as image, video, and speech. Such latent spaces act as a black-box and they are often difficult to interpret. In this post, we introduce our novel unsupervised distribution modeling technique that combines two concepts of space-filling curves and vector quantization (VQ) which is called <strong>Space-Filling Vector Quantization</strong> (SFVQ) [1]. SFVQ helps to make the latent space interpretable by capturing its underlying morphological structure. <strong>Important to note that SFVQ is a generic tool for modeling distributions and using it is not restricted to any specific neural network architecture nor any data type (e.g. image, video, speech and etc.)</strong>. In this post, we demonstrate the application of SFVQ to interpret the latent space of a voice conversion model. To understand this post you don’t need to know about speech signals technically, because we explain everything in general (not technical). Before everything, let me explain what is the SFVQ technique and how it works.</p><h4>Space-Filling Vector Quantization (SFVQ)</h4><p><a href="https://medium.com/towards-data-science/improving-vector-quantization-in-vector-quantized-variational-autoencoders-vq-vae-915f5814b5ce"><strong>Vector quantization</strong></a><strong> (VQ)</strong> [2] is a data compression technique similar to k-means algorithm which can model any data distribution. The figure below shows a VQ applied on a Gaussian distribution. VQ clusters this distribution (gray points) using 32 codebook vectors (blue points) or clusters. Each voronoi cell (green lines) contains one codebook vector such that this codebook vector is the closest codebook vector (in terms of Euclidean distance) to all data points located in that voronoi cell. In other words, each codebook vector is the representative vector of all data points located in its corresponding voronoi cell. Therefore, applying VQ on this Gaussian distribution means to map each data point to its closest codebook vector, i.e. represent each data point with its closest codebook vector. For more information about VQ and its other variants you can check out <a href="https://towardsdatascience.com/optimizing-vector-quantization-methods-by-machine-learning-algorithms-77c436d0749d">this post</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nPTV7QNbtbvIjuVqY_oVQg.png" /><figcaption>Vector Quantization applied on a Gaussian distribution using 32 codebook vectors. (image by author)</figcaption></figure><p><strong>Space-filling curve</strong> is a piece-wise continuous line generated with a recursive rule and if the recursion iterations are repeated infinitely, the curve gets bent until it completely fills a multi-dimensional space. The following figure illustrates the Hilbert curve [3] which is a well-known type of space-filling curves in which the corner points are defined using a specific mathematical formulation at each recursion iteration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gF4iQdaBAR_fAQkr_0K8Og.png" /><figcaption>Five first iterations of Hilbert curve to fill a 2D square distribution. (image by author)</figcaption></figure><p>Getting intuition from space-filling curves, we can thus think of vector quantization (VQ) as mapping input data points on a space-filling curve (rather than only mapping data points exclusively on codebook vectors as what we do in normal VQ). Therefore, we incorporate vector quantization into space-filling curves, such that our proposed space-filling vector quantizer (SFVQ) [1] models a D-dimensional data distribution by continuous piece-wise linear curves whose corner points are vector quantization codebook vectors. The following figure illustrates VQ and SFVQ applied on a Gaussian distribution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M6lRaA640BswwQ-CtQ_PeA.png" /><figcaption>Codebook vectors (blue points) of a vector quantizer, and a space-filling vector quantizer (curve in black) on a Gaussian distribution (gray points). Voronoi regions for VQ are shown in green. (image by author)</figcaption></figure><p>For technical details on how to train SFVQ and how to map data points on SFVQ’s curve, please see section 2 in <a href="https://www.isca-archive.org/interspeech_2023/vali23_interspeech.pdf">our paper</a> [1].</p><p>Note that when we train a normal VQ on a distribution, the adjacent codebook vectors that exists inside the learned codebook matrix can refer to totally different contents. For example, the first codebook element could refer to a vowel phone and the second one could refer to a silent part of speech signal. However, when we train SFVQ on a distribution, the learned codebook vectors will be located in an arranged form such that adjacent elements in the codebook matrix (i.e. adjacent codebook indices) will refer to similar contents in the distribution. We can use this property of SFVQ to interpret and explore the latent spaces in Deep Neural Networks (DNNs). As a typical example, in the following we will explain how we used our SFVQ method to interpret the latent space of a voice conversion model [4].</p><h4>Voice Conversion</h4><p>The following figure shows a voice conversion model [4] based on vector quantized variational autoencoder (VQ-VAE) [5] architecture. According to this model, encoder takes the speech signal of speaker A as the input and passes the output into vector quantization (VQ) block to extracts the phonetic information (phones) out of this speech signal. Then, these phonetic information together with the identity of speaker B goes into the decoder which outputs the converted speech signal. The converted speech would contain the phonetic information (context) of speaker A with the identity of speaker B.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nFJl_WIHQCJYdK2FYHFJlQ.png" /><figcaption>Voice conversion model based on VQ-VAE architecture. (image by author)</figcaption></figure><p>In this model, the VQ module acts as an information bottleneck that learns a discrete representation of speech that captures only phonetic content and discards the speaker-related information. In other words, VQ codebook vectors are expected to collect only the phone-related contents of the speech. Here, the representation of VQ output is considered the latent space of this model. Our objective is to replace the VQ module with our proposed SFVQ method to interpret the latent space. By interpretation we mean to figure out what phone each latent vector (codebook vector) corresponds to.</p><h4>Interpreting the Latent Space using SFVQ</h4><p>We evaluate the performance of our space-filling vector quantizer (SFVQ) on its ability to find the structure in the latent space (representing phonetic information) in the above voice conversion model. For our evaluations, we used the TIMIT dataset [6], since it contains phone-wise labeled data using the phone set from [7]. For our experiments, we use the following phonetic grouping:</p><ul><li><strong>Plosives (Stops):</strong> {p, b, t, d, k, g, jh, ch}</li><li><strong>Fricatives:</strong> {f, v, th, dh, s, z, sh, zh, hh, hv}</li><li><strong>Nasals:</strong> {m, em, n, nx, ng, eng, en}</li><li><strong>Vowels:</strong> {iy, ih, ix, eh, ae, aa, ao, ah, ax, ax-h, uh, uw, ux}</li><li><strong>Semi-vowels (Approximants):</strong> {l, el, r, er, axr, w, y}</li><li><strong>Diphthongs:</strong> {ey, aw, ay, oy, ow}</li><li><strong>Silence:</strong> {h#}.</li></ul><p>To analyze the performance of our proposed SFVQ, we pass the labeled TIMIT speech files through the trained encoder and SFVQ modules, respectively, and extract the codebook vector indices corresponding to all existing phones in the speech. In other words, we pass a speech signal with labeled phones and then compute the index of the learned SFVQ’s codebook vector which those phones are getting mapped to them. As explained above, we expect our SFVQ to map similar phonetic contents next to each other (index-wise in the learned codebook matrix). To examine this expectation, in the following figure we visualize the <a href="https://en.wikipedia.org/wiki/Spectrogram">spectrogram</a> of the sentence <em>“she had your dark suit”</em>, and its corresponding codebook vector indices for the ordinary vector quantizer (VQ) and our proposed SFVQ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ueUf5Zw6NIxMGUXEPHeTwQ.png" /><figcaption><em>(Top) Codebook vector indices for the speech signal using our proposed SFVQ (in dark blue circles) and the ordinary VQ (in gray crosses). (Bottom) Spectrogram of the speech signal including codebook vector indices corresponding to speech frames. (image by author)</em></figcaption></figure><p>We observe that the indices of the ordinary VQ does not have any particular structure. However, when using our proposed SFVQ, there is a clear structure for the codebook vector indices. The indices for the speech frames containing fricative phones of {sh, s} within the words {she, suit} are uniformly distributed next to each other throughout the frames. In addition, silence frames containing phone {h#} and some other low energy frames containing {kcl, tcl: k, t closures} within the words {dark, suit} are uniformly located next to each other in the range 0–20. Notice that the figure below remains sufficiently consistent for sentences with the same phonetic content, even across speakers with different genders, speech rhythms, and dialects.</p><p>The figure below demonstrates the histogram of SFVQ’s codebook indices for each phonetic group (explained above) for the whole TIMIT speech files. At first glance, we observe that consonants:{silence, plosives, fricatives, nasals} and vowels:{vowels, diphthongs, approximants} can be separated around index 125 (apart from the peak near index 20). We also observe that the most prominent peaks of different groups are separated in different parts of the histogram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qNNHqkbI3gB2Ozd2-jbBuQ.png" /><figcaption><em>Histogram of SFVQ’s codebook vector indices for different phonetic groups. (image by author)</em></figcaption></figure><p>By having this visualization, we have a better understanding of the latent space and we can now distinguish which part of the latent space refers to what phonetic group. We can even go further in details and explore the latent space in terms of phone level. As an example for distribution of phones within a phonetic group, the figure below illustrates the histograms of all phones in fricatives group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xcO5O0GARPzuzi902Cdqjg.png" /><figcaption><em>Histogram of SFVQ’s codebook vector indices for fricative phones. (image by author)</em></figcaption></figure><p>By observing the most prominent peak for each phone, we find out the peaks of similar phones are located next to each other. To elaborate, we listed similar phones and their corresponding peak index here as {f:51, v:50}, {th:78, dh:80}, {s:71, z:67, sh:65, zh:67}, {hh:46, hv:50}. Except {hh, hv} phones, fricatives are mainly located in the range 50–85. Further structures can be readily identified from all provided figures by visual inspection.</p><p>These experiments demonstrate that our proposed SFVQ achieves a coherently structured and easily interpretable representation for latent codebook vectors, which represent phonetic information of the input speech. Accordingly, there is an obvious distinction of various phonetic groupings such as {consonants vs. vowels}, {fricatives vs. nasals vs. diphthongs vs. …}, and we can simply tell apart which phone each codebook vector represents. In addition, similar phones within a specific phonetic group are encoded next to each other in the latent codebook space. This is the main interpretability that we aimed to obtain from a black-box called <em>latent space</em>.</p><p>One advantage of SFVQ over other supervised approaches which tries to make the latent space interpretable is that SFVQ does not incur any human labeling and manual restrictions on the learned latent space. To make our method interpretable, it only requires the user to study the unsupervised learned latent space entirely once by observation. This observation needs much much less labeled data than what is necessary for supervised training of big models. <strong>Again we want to note that SFVQ is a generic tool for modeling distributions and using it is not restricted to any specific neural network architecture nor any data type (e.g. image, video, speech and etc.)</strong>.</p><h3>GitHub Repository</h3><p>PyTorch implementation of our SFVQ technique is publicly available in GitHub using the following link:</p><p><a href="https://github.com/MHVali/Space-Filling-Vector-Quantizer.git">GitHub - MHVali/Space-Filling-Vector-Quantizer</a></p><h4>Acknowledgement</h4><p>Special thanks to my doctoral program supervisor <a href="https://research.aalto.fi/en/persons/tom-b%C3%A4ckstr%C3%B6m">Prof. Tom Bäckström</a>, who supported me and was the other contributor for this work.</p><h3>References</h3><p>[1] M.H. Vali, T. Bäckström, “Interpretable Latent Space Using Space-Filling Curves for Phonetic Analysis in Voice Conversion”, in <em>Proceedings of Interspeech</em>, 2023.</p><p>[2] M. H. Vali and T. Bäckström, “NSVQ: Noise Substitution in Vector Quantization for Machine Learning,” <em>IEEE Access</em>, 2022.</p><p>[3] H. Sagan, “Space-filling curves<em>”,</em> Springer Science &amp; Business Media, 2012.</p><p>[4] B. Van Niekerk, L. Nortje, and H. Kamper, “Vector-quantized neural networks for acoustic unit discovery in the Zerospeech 2020 challenge”, in <em>Proceedings of Interspeech</em>, 2020.</p><p>[5] A. Van Den Oord, O. Vinyals, and K. Kavukcuoglu, “Neural Discrete Representation Learning,” in <em>Proceedings of the 31st International Conference on Neural Information Processing Systems</em>, 2017.</p><p>[6] J. S. Garofolo, L. F. Lamel, W. M. Fisher, J. G. Fiscus, D. S. Pallett, and N. L. Dahlgren, “<em>The DARPA TIMIT Acoustic-Phonetic Continuous Speech Corpus CDROM”,</em> Linguistic Data Consortium, 1993.</p><p>[7] C. Lopes and F. Perdigao, “Phoneme recognition on the TIMIT database”, in <em>Speech Technologies</em>. IntechOpen, 2011, ch. 14. [Online]. Available: <a href="https://doi.org/10.5772/17600">https://doi.org/10.5772/17600</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4eb26691b14" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/interpretable-latent-spaces-using-space-filling-vector-quantization-e4eb26691b14">Interpretable Latent Spaces Using Space-Filling Vector Quantization</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Vector Quantization Methods by Machine Learning Algorithms]]></title>
            <link>https://medium.com/data-science/optimizing-vector-quantization-methods-by-machine-learning-algorithms-77c436d0749d?source=rss-840f2c687344------2</link>
            <guid isPermaLink="false">https://medium.com/p/77c436d0749d</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-compression]]></category>
            <category><![CDATA[vector-quantization]]></category>
            <category><![CDATA[nearest-neighbor-search]]></category>
            <category><![CDATA[vq-vae]]></category>
            <dc:creator><![CDATA[Mohammad Hassan Vali]]></dc:creator>
            <pubDate>Wed, 17 May 2023 12:03:40 GMT</pubDate>
            <atom:updated>2024-04-08T13:50:42.927Z</atom:updated>
            <content:encoded><![CDATA[<h4>Machine learning optimization of vector quantization methods used in end-to-end training of neural networks</h4><blockquote>This post is a short explanation of our paper [1] published at ICASSP 2023 conference. For more details, please look at the paper <a href="https://ieeexplore.ieee.org/abstract/document/10096204">under this link</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mWmqsD6PrgD62hZjCVjDsg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@alinnnaaaa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Alina Grubnyak</a> on <a href="https://unsplash.com/photos/ZiQkhI7417A?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><h3>Vector Quantization</h3><p>Vector quantization (VQ) is a data compression technique similar to k-means algorithm which can model any data distribution. Vector quantization has been used in a wide range of applications for speech, image, and video data, such as image generation [2], speech and audio coding [3], voice conversion [4,5], music generation [6], and text-to-speech synthesis [7,8]. The figure below shows how vector quantization (VQ) works. For VQ process, we require a codebook which includes a number of codewords. Applying VQ on a data point (gray dots) means to map it to the closest codeword (blue dots), i.e. replace the value of data point with the closest codeword value. Each voronoi cell (black lines) contains one codeword such that all data points located in that cell will be mapped to that codeword, since it is the closest codeword to data points located in that voronoi cell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_9jpKb52FxrxDj_LYS-Saw.png" /><figcaption>Vector Quantization Operation (image by author)</figcaption></figure><p>In other words, vector quantization maps the input vector x to the closest codeword within the codebook (CB) using the following formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UrUxjTCuqhL8MR6_gMOR8A.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmath.embed.fun%2Fembed%2Fcb7MkBFgFen69JgvFqFR7V&amp;display_name=Embed+Fun&amp;url=https%3A%2F%2Fmath.embed.fun%2Fcb7MkBFgFen69JgvFqFR7V&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=embed" width="450" height="168" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7a36868dea349ba9813cd516f2d6e76/href">https://medium.com/media/c7a36868dea349ba9813cd516f2d6e76/href</a></iframe><p>The computational complexity of VQ increases exponentially with the increase in the codebook size (increase in VQ bitrate). Hence, this plain form of VQ is applicable only for limited bitrates (limited codebook sizes). To solve this challenge and apply VQ for higher bitrates and higher dimensional data, we use some variants of VQ such as Residual VQ, Additive VQ, and Product VQ. These methods considers more than one codebook to apply VQ on the data. We will explain these three VQ methods in the following.</p><h3><strong>Residual Vector Quantization (RVQ)</strong></h3><p>Residual VQ quantizes the input vector x by applying M consecutive VQ modules on it. According to the following figure, suppose M=3. We apply the first VQ module on input vector x using the first codebook (CB¹). Then, after finding the closest codeword form first codebook, we calculate the remainder (R1). Afterwards, we pass R1 as input to the next VQ module using the second codebook (CB²). This process will continue for M stages where we would find three closest codeword coming from separate codebooks. At the end, we quantize the input vector x as a summation of M closest codewords.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AwR_OK2eqVWjG3jyvSTlBQ.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmath.embed.fun%2Fembed%2FqiqouTcUvB1t7LLshqFaVN&amp;display_name=Embed+Fun&amp;url=https%3A%2F%2Fmath.embed.fun%2FqiqouTcUvB1t7LLshqFaVN&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=embed" width="200" height="96" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4ebdaacefa87dade735b6461e95f116/href">https://medium.com/media/c4ebdaacefa87dade735b6461e95f116/href</a></iframe><h3><strong>Additive Vector Quantization (AVQ)</strong></h3><p>In a similar way as Residual VQ, Additive VQ quantizes the input vector x by applying M consecutive VQ modules. However, Additive VQ adopts the complex beam searching algorithm to find the closest codewords for the quantization process (you can find the details of beam searching algorithm in this paper [9]). According to the following figure, we suppose M=3. In Additive VQ, first we search for the closest codeword from the union of all three codebooks (here CB¹, CB², CB³). Then, suppose we find the best codeword from CB². After that, we calculate the residual (R1) and pass it as input to the next VQ module. Since the first codeword is selected from CB², now we search for the closest codeword from the union of CB¹ and CB³. After calculating the residual R2, we pass it as input to the last VQ module, where we do the search using the last codebook (in this case CB¹) which is not yet contributed to the quantization process. At the end, we quantize the input vector x as a summation of M closest codewords.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MKdoOmncPYQG05gK0rJEqw.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmath.embed.fun%2Fembed%2F4H3s72781X8xboaCskSZia&amp;display_name=Embed+Fun&amp;url=https%3A%2F%2Fmath.embed.fun%2F4H3s72781X8xboaCskSZia&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=embed" width="200" height="96" frameborder="0" scrolling="no"><a href="https://medium.com/media/4076b83d128f41367d34198ef895195a/href">https://medium.com/media/4076b83d128f41367d34198ef895195a/href</a></iframe><h3><strong>Product Vector Quantization (PVQ)</strong></h3><p>Product VQ splits the input vector x of dimension D to M independent subspaces of dimension D/M. Then it applies M independent VQ modules to the existing subspaces. At the end, Product VQ quantizes the input vector x as a concatenation of M closest codewords (one per each codebook). The figure below shows the Product VQ when M=3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X1NOYMquE6BthlJKSGlXaw.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmath.embed.fun%2Fembed%2Febi3LTCe1g2Lc57vSady8m&amp;display_name=Embed+Fun&amp;url=https%3A%2F%2Fmath.embed.fun%2Febi3LTCe1g2Lc57vSady8m&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=embed" width="344" height="136" frameborder="0" scrolling="no"><a href="https://medium.com/media/011343c5e58964a6eac997d0f96002fc/href">https://medium.com/media/011343c5e58964a6eac997d0f96002fc/href</a></iframe><h3><strong>Codebooks Optimization</strong></h3><p>Vector quantization (VQ) training means to optimize the codebook(s) such that they model the data distribution in a way that the error of quantization (such as mean squared error) between data points and codebook elements is minimized. To optimize the codebooks for these three above-mentioned variants of VQ (Residual VQ, Additive VQ, and Product VQ) there are different approaches which we will mention in the following.</p><h4>1. K-means Algorithm (traditional approach):</h4><p>Based on the literature review, in most of the papers, codebooks for these three VQ methods have been optimized by <a href="https://en.wikipedia.org/wiki/K-means_clustering">k-means algorithm</a>.</p><h4>2. Stochastic Optimization (machine learning algorithms):</h4><p>Machine learning optimization algorithms are based on gradient calculation. Therefore, it is impossible to optimize vector quantization methods using machine learning optimization, since the argmin function in vector quantization function (first equation above) is not differentiable. In other words, we cannot pass the gradients over vector quantization function in backpropagation. Here we have mentioned two solutions to solve this problem.</p><h4>2.1. Straight Through Estimator (STE)</h4><p>STE [10] solves the problem by simply copying the gradients intactly over VQ module in backpropagation. Hence, it does not consider the influence of vector quantization and leads to a mismatch between the gradients and true behavior of the VQ function.</p><h4>2.2. Noise Substitution in Vector Quantization (NSVQ):</h4><p>The NSVQ technique [11] is our recently proposed method, in which the vector quantization error is simulated by adding noise to the input vector, such that the simulated noise would gain the shape of original VQ error distribution (you can read shortly about NSVQ <a href="https://medium.com/towards-data-science/improving-vector-quantization-in-vector-quantized-variational-autoencoders-vq-vae-915f5814b5ce">in this post</a>).</p><p>NSVQ technique [11] has some advantages over STE method [10] which are listed in the following. 1) NSVQ yields more accurate gradients for VQ function. 2) NSVQ achieves faster convergence for VQ training (codebook optimization). 3) NSVQ does not need any additional hyper-parameter tuning for VQ training (does not require additional loss term for VQ training to be added to the global optimization loss function).</p><h3>Experiments</h3><p>In our paper, we have used our recently proposed NSVQ technique [11] to optimize three above-mentioned variants of VQ by machine learning optimization. To evaluate the performance of these three VQ methods and study the trade-offs between accuracy, bitrate, and complexity of them, we conducted four different scenarios for experiments. We will explain all these scenarios of experiments in the following.</p><h4>1. Approximate Nearest Neighbor (ANN) Search</h4><p>In this experiment, we modeled the distribution of SIFT1M dataset [12] (128-D image descriptors) by training three VQ methods on its learning set. The SIFT1M image descriptors dataset [12] includes 10⁶ base vectors, 10⁵ learning vectors, and 10⁴ query vectors for testing purposes. The ground truth contains the set of actual nearest neighbors, from the base vectors to the query vectors. In the ANN search, we first compress the base vectors using the corresponding learnt codebooks trained on the learning set. Then, for each query vector, we find the approximate nearest neighbors from the compressed base vectors by performing an exhaustive search. To assess the quality of data compression, we calculate the <em>recall metric</em> at different values for parameter <strong><em>T</em></strong>, which shows whether the actual nearest neighbor (from groundtruth) exists in the first <strong><em>T</em></strong> computed nearest neighbors. The figure below illustrates the comparison of three variants of VQ optimized by our proposed NSVQ technique with the baseline methods under <em>recall metric</em>. In general, all three machine learning-based optimized VQ methods achieve comparable (even slightly better in case of RVQ) recall values to the baselines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyLsc0yF9gFfkZGUz5rwQA.png" /><figcaption>Comparison of recall values for compression of SIFT1M dataset by applying our proposed VQ methods and baselines at 64 bits (8 codebooks each with 256 codewords); Recall@T shows whether the actual nearest neighbor (from groundtruth) exists in the T computed nearest neighbors. (image by author)</figcaption></figure><h4>2. Image Compression using VQ-VAE</h4><p>In this experiment, we trained a vector quantized variational autoencoder (VQ-VAE) on the training set of CIFAR10 dataset to compress it. To apply the vector quantization in the bottleneck of VQ-VAE, we used each of these three VQ methods. After training, we reconstructed the test images of CIFAR10 using the trained encoder, decoder, and learnt codebooks for each VQ method. To evaluate the quality of reconstructed images, we employ Peak Signal to Noise Ratio (Peak SNR) metric. In addition, we computed the complexity of each VQ method using Weighted Million Operations Per Second (WMOPS) metric, which is under <a href="https://en.wikipedia.org/wiki/ITU-T">ITU-T standard</a>. The following figure shows the results of this experiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KsHxsstNIa90OPA7J50Ryw.png" /><figcaption>Peak SNR and complexity of proposed VQ methods over 15 k training batches and 10 individual experiments in the image compression scenario; lines refer to the mean values and the corresponding filled areas refer to their 95 % quantiles. For all VQ bitrates we used four codebooks i.e. M=4. (image by author)</figcaption></figure><p>According to the complexity figure (in the right), we found that for the same use of computational resources (left vertical red line) and a higher bitrate, Product VQ performs better than Residual VQ. In addition, for the same use of computational resources (right vertical red line) and a higher bitrate, Residual VQ performs better than Additive VQ. Therefore, depending on how much computational resources are available, we can conclude which is the best VQ method to use.</p><h4>3. Speech Coding</h4><p>In this experiment, we model the spectral envelope of speech signals by three VQ methods using the speech codec presented in [13]. To evaluate the quality of decoded speech signals, we used perceptual evaluation of speech quality (PESQ) and perceptually weighted signal to noise ratio (pSNR) as objective metrics. The following figure shows the performance of all three VQ methods under PESQ and pSNR criteria. According to the results, we observe that Additive VQ gains higher mean and lower variance than both Residual VQ and Product VQ in both metrics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q_rN7m8iX1xS_TyaggLwGQ.png" /><figcaption>Performance of proposed VQ methods in terms of PESQ and pSNR metrics for 16 bit VQ (with 4 codebooks i.e. M=4) at overall bitrates of 8, 9.6, 13.2, 16.4, 24.4 and 32 kbit/s in the speech coding scenario; solid lines refer to the mean values of PESQ and pSNR, and the corresponding filled areas refer to their 95% quantiles. (image by author)</figcaption></figure><h4>4. Toy Examples</h4><p>In this experiment, we intend to compare the performance of three VQ methods with respect to the correlation in the data. Hence, we prepared two correlated and uncorrelated datasets of dimension 64. Then, we compressed these datasets using these three VQ methods. To evaluate the performance, we computed the mean squared error (MSE) between each dataset and its quantized version. The following figure shows the results for this experiment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*60JrSh1juM0bf_4q1ansHA.png" /><figcaption>Vector quantization error for correlated and uncorrelated datasets using all three proposed VQ methods (data dimension=64, and for all VQ bitrates we used four codebooks i.e. M=4). (image by author)</figcaption></figure><p>In correlated dataset, since Residual VQ and Additive VQ take the correlation among all data dimensions into account, they have much lower quantization error than Product VQ as expected. On the other hand, Product VQ has better performance than Additive VQ and Residual VQ for uncorrelated data, since there is no correlation among data dimensions and that is exactly what Product VQ presumes.</p><h3>Conclusions</h3><p>Using variants of Vector Quantization (VQ) such as Residual VQ, Additive VQ, and Product VQ allows to apply VQ for high bitrates and high dimensional data. These VQ methods have been optimized by classic expectation maximization and k-menas algorithm so far. In this paper, we optimize these VQ methods by machine learning optimization using our recently proposed Noise Substitution in Vector Quantization (NSVQ) [11] technique. In addition, NSVQ allows end-to-end optimization of VQ methods in Neural Netwroks. We also study the trade-offs between bitrate, accuracy, and complexity of these three VQ methods. Hence, our open-source implementation [14] helps to make the best choice of VQ method for a particular use-case.</p><h3>GitHub Repository</h3><p>We provide the PyTorch implementation of these VQ methods in the following webpage.</p><p><a href="https://github.com/MHVali/Additive-Residual-Product-Vector-Quantization-Methods.git">GitHub - MHVali/Additive-Residual-Product-Vector-Quantization-Methods</a></p><h4>Acknowledgement</h4><p>Special thanks to my doctoral program supervisor <a href="https://research.aalto.fi/en/persons/tom-b%C3%A4ckstr%C3%B6m">Prof. Tom Bäckström</a>, who supported me and was the other contributor for this work.</p><h3><strong>References</strong></h3><p>[1] M. H. Vali and T. Bäckström, “Stochastic Optimization of Vector Quantization Methods in Application to Speech and Image Processing,” in <em>Proceedings of ICASSP</em>, 2023.</p><p>[2] A. Razavi, A. van den Oord, and O. Vinyals, “Generating diverse high-fidelity images with VQ-VAE-2,” in <em>Proceedings of NeurIPS</em>, 2019.</p><p>[3] C. Gârbacea, A. van den Oord, Y. Li, F. S. C. Lim, A. Luebs, O. Vinyals, and T. C. Walters, “Low bit-rate speech coding with VQ-VAE and a Wavenet decoder,” in <em>Proceedings of ICASSP</em>, 2019.</p><p>[4] B. van Niekerk, L. Nortje, and H. Kamper, “Vector-quantized neural networks for acoustic unit discovery in the zerospeech 2020 challenge,” in <em>Proceedings of Interspeech</em>, 2020.</p><p>[5] S. Ding and R. Gutierrez-Osuna, “Group latent embedding for vector quantized variational autoencoder in non-parallel voice conversion,” in <em>Proceedings of Interspeech</em>, 2019.</p><p>[6] P. Dhariwal, H. Jun, C. Payne, J. W. Kim, A. Radford, and I. Sutskever, “Jukebox: a generative model for music,” <em>arXiv preprint arXiv:2005.00341</em>, 2020.</p><p>[7] A. Tjandra, B. Sisman, M. Zhang, S. Sakti, H. Li, and S. Nakamura, “VQVAE unsupervised unit discovery and multi-scale code2spec inverter for Zerospeech challenge 2019,” in <em>Proceedings of Interspeech</em>, 2019.</p><p>[8] X. Wang, S. Takaki, J. Yamagishi, S. King, and K. Tokuda, “A vector quantized variational autoencoder (VQ-VAE) autoregressive neural F0 model for statistical parametric speech synthesis,” <em>IEEE Transactions on Audio, Speech, and Language Processing</em>, 2020.</p><p>[9] A. Babenko and V. Lempitsky, “Additive quantization for extreme vector compression,” in <em>Proceedings of CVPR</em>, 2014.</p><p>[10] Y. Bengio, N. Léonard, and A. Courville, “Estimating or Propagating Gradients Through Stochastic Neurons for Conditional Computation,” a<em>rXiv preprint arXiv:1308.3432,</em> 2013.</p><p>[11] M. H. Vali and T. Bäckström, “NSVQ: Noise Substitution in Vector Quantization for Machine Learning,” <em>IEEE Access</em>, vol. 10, 2022.</p><p>[12] H. Jegou, M. Douze, and C. Schmid, “Product Quantization for Nearest Neighbor Search,” <em>IEEE Transactions on Pattern Analysis and Machine Intelligence</em>, vol. 33, no. 1, pp. 117–128, 2010.</p><p>[13] M. H. Vali and T. Bäckström, “End-to-End Optimized Multi-Stage Vector Quantization of Spectral Envelopes for Speech and Audio Coding,” in <em>Proceedings of Interspeech</em>, 2021.</p><p>[14] <a href="https://gitlab.com/speech-interaction-technology-aalto-university/vq-variants">https://gitlab.com/speech-interaction-technology-aalto-university/vq-variants</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77c436d0749d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/optimizing-vector-quantization-methods-by-machine-learning-algorithms-77c436d0749d">Optimizing Vector Quantization Methods by Machine Learning Algorithms</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NSVQ: Improved Vector Quantization technique for Neural Networks Training]]></title>
            <link>https://medium.com/data-science/improving-vector-quantization-in-vector-quantized-variational-autoencoders-vq-vae-915f5814b5ce?source=rss-840f2c687344------2</link>
            <guid isPermaLink="false">https://medium.com/p/915f5814b5ce</guid>
            <category><![CDATA[variational-autoencoder]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[vector-quantization]]></category>
            <category><![CDATA[backpropagation]]></category>
            <dc:creator><![CDATA[Mohammad Hassan Vali]]></dc:creator>
            <pubDate>Wed, 20 Jul 2022 13:28:48 GMT</pubDate>
            <atom:updated>2023-11-27T21:52:44.033Z</atom:updated>
            <content:encoded><![CDATA[<h4>Efficient vector quantization for machine learning optimizations (esp. vector quantized variational autoencoders), better than straight through estimator</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mQbE21i6fsfqpU3L" /><figcaption>Photo by <a href="https://unsplash.com/@vackground?utm_source=medium&amp;utm_medium=referral">vackground.com</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Vector quantization (VQ) is a data compression technique like k-means clustering algorithm, which models the probability density function of the data by some representative vectors called codebooks. Vector quantization has been recently used in a wide range of machine learning-based applications, especially those based on vector quantized variational autoencoders (VQ-VAE); e.g. image generation [1], speech coding [2], voice conversion [3], music generation [4], and text-to-speech synthesis [5].</p><p>According to the following figure, vector quantization is the operation of mapping all data points (in a voronoi-cell) to its nearest codebook point. In other words, it finds the nearest codebook vector (c_k*) to the input data vector (x) from a set of codebook vectors (c_k)s using the following formula, and map (quantize) x to x_hat by replacing its value by the nearest codebook which is c_k*.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmath.embed.fun%2Fembed%2FdFwF4kUVi57marjiAcBtwT&amp;display_name=Embed+Fun&amp;url=https%3A%2F%2Fmath.embed.fun%2FdFwF4kUVi57marjiAcBtwT&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=embed" width="314" height="147" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8e05a7949bd268d93fd7393a14d4e83/href">https://medium.com/media/e8e05a7949bd268d93fd7393a14d4e83/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*_j4iFnsv7Xt5CoeZ40rZoQ.png" /><figcaption>Vector Quantization operation (image from <a href="https://speechprocessingbook.aalto.fi/Modelling/Vector_quantization_VQ.html">here</a>)</figcaption></figure><p>It is obvious that vector quantization cannot be used directly in machine learning-based optimizations, since there is no real gradients defined for it (for the above-mentioned equation). Hence, we need to apply some tricks to estimate gradients for VQ function, and make it pass these gradients through backpropagation and update the codebook vectors.</p><p>VQ-VAE was first introduced in the paper “<a href="https://proceedings.neurips.cc/paper/2017/file/7a98af17e63a0ac09ce2e96d03992fbc-Paper.pdf">Neural Discrete representation Learning</a>” by Oord et al [6]. They apply VQ to model a discrete representation of the latent space of variational autoencoder. In other words, they apply VQ on the output of the encoder and find the best embeddings (codebooks) for that, and then pass these embeddings to the decoder. To pass the gradients for VQ function in backpropagation (backward pass), this paper and all above-mentioned ones use straight through estimator (STE) [7], which just simply copies gradients over VQ module, like what is shown in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pTECMRydvo-e3j58W75Hnw.png" /><figcaption>Straight Through Estimator (Image from <a href="https://www.hassanaskary.com/python/pytorch/deep%20learning/2020/09/19/intuitive-explanation-of-straight-through-estimators.html">here</a>)</figcaption></figure><p>However, straight through estimator (STE) does not consider the influence of quantization and leads to a mismatch between the gradient and true behavior of the vector quantization. In addition, for the methods which use STE, it is essential to add an additional loss term to the global loss function to make the VQ codebooks (embeddings) to be updated. Therefore, the weighting coefficient for the additional loss term is a new hyper-parameter, which is required to be tuned manually. The loss function for the VQ-VAE introduced by Oord et al. [6] is shown below. The second and third terms in the formula are the required loss terms for VQ module with the weighting coefficients of alpha and beta. For more details about the loss function, please see the paper.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fmath.embed.fun%2Fembed%2FkndCuT9eDprL4LPEXFq7Es&amp;display_name=Embed+Fun&amp;url=https%3A%2F%2Fmath.embed.fun%2FkndCuT9eDprL4LPEXFq7Es&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=embed" width="511" height="137" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4294b615c27c89d78151465de1af548/href">https://medium.com/media/c4294b615c27c89d78151465de1af548/href</a></iframe><p>In this post, we want to introduce our recently proposed vector quantization technique for machine learning-based approaches, which is published under the title of “<a href="https://ieeexplore.ieee.org/abstract/document/9696322"><strong>NSVQ: Noise Substitution in Vector Quantization for Machine Learning</strong></a>” [8]. NSVQ is a technique in which the vector quantization error is simulated by adding noise to the input vector, such that the simulated noise would gain the shape of original VQ error distribution. The block diagram of NSVQ is shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xvwZLWlnBY41-4dlyEZE-Q.png" /><figcaption>Block diagram of NSVQ: Noise Substitution in Vector Quantization (Image by author)</figcaption></figure><p>We test our NSVQ method in three different scenarios of experiments,</p><ol><li>speech coding: to model the spectral envelopes of speech signals (<a href="https://www.isca-speech.org/archive/pdfs/interspeech_2021/vali21_interspeech.pdf">speech coding method proposed in [9]</a>)</li><li>image compression: to model the latent representation of VQ-VAE proposed in [6]</li><li>toy-examples: to model some well-known data distributions.</li></ol><p>Based on the results in <a href="https://ieeexplore.ieee.org/abstract/document/9696322">our paper</a> [8] (which are also provided in the following figures), it has been shown that not only NSVQ can pass the gradients in the backward pass, but it also can provide more accurate gradients for codebooks than STE. Furthermore, NSVQ leads to higher quantization accuracy, and faster convergence compared to STE. In addition, NSVQ performs more deterministically (shows less variance in performance) when running an individual experiment for several times. One great benefit of using NSVQ is that it does not need any addtional loss term to be added to the global loss function. Hence, it does not incur any additional hyper-parameter tuning (the coefficient for the additional loss term in STE).</p><p>In the speech coding scenario, we use perceptual evaluation of speech quality (PESQ) and perceptually weighted signal to noise ratio (pSNR) as objective metrics to evaluate the quality of decoded speech for STE and our proposed NSVQ method. The following figure shows the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fobBGu61-2QmsNsvuIwktA.png" /><figcaption>Performance of the proposed NSVQ and STE in terms of PESQ and pSNR metrics for 12 bit VQ at overall bitrates of 8, 9.6, 13.2, 16.4, 24.4 and 32 kbit/s in the speech coding scenario; solid lines refer to the mean values of PESQ and pSNR, and the corresponding filled areas refer to their 95% quantiles. (Image by author)</figcaption></figure><p>In the image compression scenario, we employ structural similarity index measure (SSIM) and peak signal to noise ratio (Peak SNR) as objective metrics to evaluate the quality of the reconstructed image on the decoder side of VQ-VAE. The following figure demonstrates the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P0LWep6XHRHZT-e3nnfr5A.png" /><figcaption>SSIM and Peak SNR values of STE and the proposed NSVQ for different VQ bitrates after 15 k training updates and over 20 individual experiments in the image compression scenario; solid lines refer to the mean values of SSIM and Peak SNR, and the corresponding filled areas refer to their 95% quantiles. (Image by author)</figcaption></figure><p>According to the above figure, the proposed NSVQ obtains strictly ascending SSIM and Peak SNR values when increasing the VQ bitrate, which confirms that it behaves consistently with the increase in bitrate. This behavior is what we expect from a genuine VQ. However, the STE method does not follow the same behavior. We think the reason is that the STE does not consider the influence of VQ function in backpropagation.</p><p>In the image compression scenario, apart from objective evaluations we also investigate two other things; the training convergence speed and the codebook vectors perplexity (the average codebook usage). Here is the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xZS1wtQHkWXTCXBo3OvdxA.png" /><figcaption>Smoothed training error (MSE) and smoothed average codebook usage (perplexity) of STE and the proposed NSVQ for 11 bit VQ after 15 k training updates and over 20 individual experiments in the image compression scenario; solid lines refer to the mean values of MSE and perplexity, and the corresponding filled areas refer to their 95% quantiles. (Image by author)</figcaption></figure><p>In the third scenario of our paper, we model the distribution of several well-known machine learning data distributions using our proposed NSVQ, STE, and also MiniBatchKmeans (from scikit-learn library) methods. Here we only show vector quantization applied on the <em>swiss-roll</em> distribution in 2D space using 8 bits (2⁸=256 codebooks). We initialize the locations of codebook vectors out of data distribution to make the VQ more challenging. The final optimized codebook locations for NSVQ, STE, and MiniBatchKmeans methods are shown in the following figures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYByHhJjFqfzRtEIzX7npA.png" /><figcaption>Final optimized codebooks for 8 bit vector quantization using <strong>NSVQ</strong> method (Image by author)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6diWUUxradTGbc7ZnAtA_g.png" /><figcaption>Final optimized codebooks for 8 bit vector quantization using <strong>STE</strong> method (Image by author)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xFbvFZR5ZEuiQPbtZDAU9Q.png" /><figcaption>Final optimized codebooks for 8 bit vector quantization using <strong>MiniBatchKmeans</strong> method (Image by author)</figcaption></figure><p>According to the figures, NSVQ captures the <em>swiss-roll</em> distribution shape much better than STE with much less number of dead codebooks (codebook which is selected out of the data distribution and is useless for the decoding phase). Hence, it can be concluded that NSVQ is much less sensitive to the initialization of the codebooks compared to STE. Note that this behavior of NSVQ is partially due to the <em>codebook replacement</em> function mentioned in our paper.</p><p>In addition, NSVQ locate the codebooks in a more uniform and homogeneous way than MiniBatchKmeans method. Look at the dense codebook distribution in the black boxes in the last figure, which shows the codebook locations of MiniBatchKmeans method. This phenomenon is not happened in NSVQ approach (notice that the nature of data distribution is not dense in the black boxes regions). We have calculated the mean squared errors (MSE) between the original data distribution and the vector quantized version of it for all of these three approaches. According to the MSE values which are published in <a href="https://ieeexplore.ieee.org/abstract/document/9696322">our paper</a> [8], NSVQ quantizes the data with lower MSE values than STE and MiniBatchKmeans methods.</p><p>At the end, I have to mention that the NSVQ technique is applicable to train any machine learning application, which requires vector quantization somewhere in the computational graph. However, please note that <strong>NSVQ is only applied for the training phase</strong> in order to learn the vector quantization codebooks. But, it is not used in the inference phase, since we do not need any gradients to be passed in the backpropagation. So, in the inference phase, it is better and more accurate to proceed with the original vector quantization formula mentioned above.</p><h3>GitHub Repository</h3><p>We provide the <strong>PyTorch code of the NSVQ</strong> in the following public webpage:</p><p><a href="https://github.com/MHVali/Noise-Substitution-in-Vector-Quantization.git">GitHub - MHVali/Noise-Substitution-in-Vector-Quantization: Python implementation of the code for NSVQ</a></p><h3>Acknowledgement</h3><p>Special thanks to my doctoral program supervisor <a href="https://research.aalto.fi/en/persons/tom-b%C3%A4ckstr%C3%B6m">Prof. Tom Bäckström</a>, who supported me and was the other contributor for this work.</p><h3>References</h3><p><strong>[1]</strong> A. Razavi, A. van den Oord, and O. Vinyals, ‘‘Generating diverse high- fidelity images with VQ-VAE-2,’’ in <em>Proc. 33th Int. Conf. Neural Inf. Process. Syst.</em>, vol. 32, 2019, pp. 14866–14876.</p><p><strong>[2]</strong> C. Garbacea, A. V. den Oord, Y. Li, F. S. C. Lim, A. Luebs, O. Vinyals, and T. C. Walters, ‘‘Low bit-rate speech coding with VQ-VAE and a WaveNet decoder,’’ in <em>Proc. IEEE Int. Conf. Acoust., Speech Signal Process. (ICASSP)</em>, May 2019, pp. 735–739.</p><p><strong>[3]</strong> S. Ding and R. Gutierrez-Osuna, “Group latent embedding for vector quantized variational autoencoder in non-parallel voice conversion,” in <em>Proceedings of Inter- speech</em>, 2019, pp. 724–728.</p><p><strong>[4]</strong> P. Dhariwal, H. Jun, C. Payne, J. W. Kim, A. Radford, and I. Sutskever, “Jukebox: a generative model for music,” <em>arXiv preprint arXiv:2005.00341</em>, 2020.</p><p><strong>[5]</strong> A. Tjandra, B. Sisman, M. Zhang, S. Sakti, H. Li, and S. Nakamura, “VQVAE unsupervised unit discovery and multi-scale code2spec inverter for Zerospeech challenge 2019,” <em>arXiv preprint arXiv:1905.11449</em>, 2019.</p><p><strong>[6]</strong> A. van den Oord, O. Vinyals, and K. Kavukcuoglu, “Neural discrete representation learning,” in <em>Proceedings of the 31st International Conference on Neural Information Processing Systems</em>, 2017, pp. 6309–6318.</p><p><strong>[7]</strong> Y. Bengio, N. Le ́onard, and A. Courville, “Estimating or propagating gradients through stochastic neurons for conditional computation,” <em>arXiv preprint arXiv:1308.3432</em>, 2013.</p><p><strong>[8]</strong> M. H. Vali and T. Bäckström, “NSVQ: Noise Substitution in Vector Quantization for Machine Learning,” <em>IEEE Access</em>, vol. 10, pp. 13 598–13 610, 2022.</p><p><strong>[9]</strong> M. H. Vali and T. Bäckström, ‘‘End-to-end optimized multi-stage vector quantization of spectral envelopes for speech and audio coding,’’ in Pr<em>oc. Interspeech, </em>Aug. 2021, pp. 3355–3359.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=915f5814b5ce" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/improving-vector-quantization-in-vector-quantized-variational-autoencoders-vq-vae-915f5814b5ce">NSVQ: Improved Vector Quantization technique for Neural Networks Training</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>