<?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 Chella Priyadharshini on Medium]]></title>
        <description><![CDATA[Stories by Chella Priyadharshini on Medium]]></description>
        <link>https://medium.com/@m.chellaa?source=rss-465e2a8d715c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6WwrfDDXqPf1zZiJNTQxqA.jpeg</url>
            <title>Stories by Chella Priyadharshini on Medium</title>
            <link>https://medium.com/@m.chellaa?source=rss-465e2a8d715c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:49:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@m.chellaa/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[Power Analysis and Sample Size Estimate]]></title>
            <link>https://medium.com/@m.chellaa/power-analysis-and-sample-size-estimate-de2cdd7df6fe?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/de2cdd7df6fe</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Wed, 30 Apr 2025 15:22:37 GMT</pubDate>
            <atom:updated>2025-04-30T15:22:37.282Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6yY-S1rnjmlSzqLBV-wDBA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Markus Spiske</a> on <a href="https://unsplash.com/photos/text-XrIfY_4cK1w?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><h3>Type of Statistical Test:</h3><ul><li>Single Sample T-test</li></ul><h3>Assumptions:</h3><ul><li>Test Statistic Distribution: Student’s t-distribution</li><li>Population Standard Deviation is Unknown</li><li>Data is Approximately Normally Distributed</li><li>Purpose: to compare the mean of a sample to a known value</li><li>Hypothesis Test: Single Sample T-Test</li></ul><h3>Types of Errors &amp; their Probabilities:</h3><p>In hypothesis testing we can make two types of errors:</p><ul><li>Type I error: Rejecting the Null hypothesis when it is True (False Positive error)</li><li>Type II error: Failing to Reject the Null hypothesis when it is False (False Negative error)</li></ul><p>The probability of a Type I error is pre-determined by the Significance Level α.</p><p>The probability of a Type II error (β) generally cannot be computed because it depends on the population mean which is unknown.</p><h3>Statistical Power:</h3><p>Probability of Correctly Rejecting the Null hypothesis when it is False.</p><p>Power = 1 — β</p><h3>What is Effect &amp; how is it related to α, β and Power:</h3><p>“Effect” is a way to understand how much of an effect an intervention or treatment has, or how much one variable influences another, often measured as “effect size”. Effect size quantifies the magnitude of an observed effect. Effect size complements statistical significance tests. While p-values tell us if a result is statistically significant (unlikely to be due to chance), effect size tells us how meaningful or practically important that result is. A statistically significant result with a small effect size might not be practically important, while a large effect size, even if not statistically significant, might still be meaningful.</p><h4>Re-defining α, β and Power in terms of Effect:</h4><p>α : probability of claiming an effect which is not there (by incorrectly rejecting the null hypothesis)</p><p>β : probability of missing an effect which is really there (by incorrectly failing to reject the null hypothesis)</p><p>Power : ( 1 — β ) : probability of detecting an effect which is really there (by correctly rejecting the null hypothesis)</p><h4>Effect Size:</h4><p>There are many ways to compute effect size. We will follow the “Mean Difference” method (known as Cohen’s d) — the difference between the means of two groups, often divided by the standard deviation. For a Single Sampled test this is computed as:</p><p>Cohen’s d = ( m — μ ) / s</p><ul><li>m → sample mean</li><li>μ → theoretical mean</li><li>s → sample standard deviation</li></ul><p>Effect Size buckets:</p><ul><li>&lt; 0.1 → Trivial Effect</li><li>0.1–0.3 → Small Effect</li><li>0.3–0.5 → Moderate Effect</li><li>&gt; 0.5 → Large Effect</li></ul><p>Because effect size can only be calculated after you collect data from program participants, you will have to use an estimate for the power analysis.</p><p>Common practice is to use a value of 0.5 as it indicates a moderate to large difference.</p><h3>Relationship between Power, Effect Size and Sample Size:</h3><p>Power, effect size, and sample size are interconnected in statistical analysis; larger sample sizes generally lead to higher power, and a larger effect size also increases power, allowing for easier detection of a true effect.</p><ul><li>A study with high power is more likely to find a statistically significant result when there is a true effect, while a study with low power may fail to detect a real effect.</li><li>A larger effect size indicates a stronger or more meaningful effect, while a smaller effect size suggests a weaker or less important effect.</li><li>A larger sample size generally provides more statistical power, as it reduces the variability of the sample estimates and allows for more precise estimation of the effect.</li></ul><p>In a nutshell:</p><ul><li>Larger Sample Size, Higher Power: For a given effect size, a larger sample size will lead to higher statistical power.</li><li>Larger Effect Size, Higher Power: For a given sample size, a larger effect size will lead to higher statistical power.</li></ul><h3>Power Analysis:</h3><p>As Power, Effect Size and Sample Size are inter-related, for desired values of power and effect size we can compute the required sample size. To ensure that our sample size is big enough, we will need to conduct a “Power Analysis”. As these calculations are not easy to do by hand, we take the help of a software program G*Power. G*Power is a free, user-friendly software tool for performing statistical power analyses, including sample size calculations, for various statistical tests.</p><p>Details of the Power Analysis parameters:</p><ul><li>Test Family : t-tests</li><li>Statistical Test : Means: Difference from constant (one sample case)</li><li>Type of Power Analysis : A priori: Compute required sample size — given α, Power and Effect Size</li><li>Input Parameters &amp; Corresponding Output:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0i3RTLJiBOBQQNfojyYnnA.png" /></figure><h4>G* Power:</h4><p>Effect Size : Small</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RQTdM-ha-vCtEccxrt-5iw.png" /></figure><p>Effect Size : Medium</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TgAC7sJUFEoGCQQFGTAxCA.png" /></figure><p>Effect Size : Large</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I5tER6pdGAmBHb7pqNK7iw.png" /></figure><h3>Conclusion:</h3><h4>Estimated Range of Sample Size:</h4><p><strong>Upper Bound:</strong></p><ul><li>For a small effect size, we need to have a sample which is large enough to detect the smallest effect size of interest — but not so large — because large sample size can make even small effects look statistically significant — but this does not mean the effect should be practically important.</li><li>Keeping in mind the above points and the G*Power computed sample sizes, we can consider the following Upper Bound on sample size:</li><li>sample size &lt;= 97 (sample size large enough to detect the smallest effect size of interest)</li></ul><p><strong>Lower Bound:</strong></p><ul><li>For a moderate effect size, we need to have a sample which can be small — because even small sample size can detect a moderate to large effect easily.</li><li>Keeping in mind the above points and the G*Power computed sample sizes, we can consider the following Lower Bound on sample size:</li><li>sample size &gt;= 36 (minimum sample size if we consider a moderate effect size)</li></ul><p>Combining the above two we get:</p><ul><li><strong>sample size &gt;= 36</strong></li><li><strong>sample size &lt;= 97</strong></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de2cdd7df6fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Curse of Dimensionality]]></title>
            <link>https://medium.com/analytics-vidhya/the-curse-of-dimensionality-974e60b09835?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/974e60b09835</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Fri, 17 Jun 2022 20:17:09 GMT</pubDate>
            <atom:updated>2022-06-18T05:05:46.616Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*F7J22QSYY1w8Y5kTRonFMQ.png" /></figure><p>If you are into Machine Learning, you’d have definitely come across the much feared curse of dimensionality. In this post, I’ll attempt to help shed a light on how having excessive number of dimensions (a.k.a features, independent variables, predictors) is in fact a bane.</p><h3>Model Complexity Increases:</h3><p>Assume a classification problem, where the purpose is to find a “decision surface” — a hyperplane — that partitions the underlying vector space into “k” regions, one for each of the “k” classes.</p><p>Case 1: When the number of dimensions is 2 and the number of datapoints is n, where n&gt;&gt;2</p><p>Case 2: When the number of dimensions is ‘d’ and the number of datapoints is n, where n&lt;&lt;d</p><p>See the equation of the hyperplane in both the cases as shown in the figure below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i-7OYZZJL90hJws-TnCxsg.png" /></figure><p>In case 1 you have a 1-D hyperplane and estimate 3 parameters w_0, w_1 and w_2, whereas in case 2 you have a (d-1) dimensional hyperplane and estimate d+1 parameters w_0, w_1, w_2, … w_d. Simply put, as the number of dimensions increases, the number of parameters to be estimated increases, or in other words, the complexity of the model increases. And as discussed in <a href="https://www.linkedin.com/posts/chellapriyadharshini_ml-datascience-variance-activity-6942936249833766912-RbIY?utm_source=linkedin_share&amp;utm_medium=member_desktop_web">this linked post</a>, a high complexity model implies higher variance and leads to the model overfitting your data.</p><h3>Visualization becomes a problem:</h3><p>Beyond 3 dimensions, visualizing the data becomes a problem.</p><h3>Hughe’s Phenomenon:</h3><p>Consider a set of points in a 1-D space as given below. The average distance between the datapoints being d.</p><p>Now, if you take these points to a higher dimensional space — let’s say you are projecting them in a 3-D space</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gLCswwChwhLJl-fmY2Oa7g.png" /></figure><p>You can see that the same points from 1-D are spaced out when projected to a 3-D space. Let us say the average distance between the datapoints now is d’.</p><p>If there are a fixed number of samples in our dataset, then as the number of dimensions increase, the number of points per region decreases (density decreases). As the density of points decrease, the mean distance between the points increases. Even the nearest neighbour being too far in a higher dimensional space. That is, d’ &gt;&gt; d.</p><p>So, lower data density means, you require more number of datapoints — if you want to keep the average distance between the datapoints the same. And these additional datapoints required increases exponentially as the number of dimensions increases. Let us see how.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aaY_bemgTNskxN4N95-0gA.png" /></figure><p>Consider our dataset has 3 features, f1 (gender), f2 (age) and f3 (country) and the number of unique feature values are as given in the figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GIny29QEQf7543YJ5aWzbQ.png" /></figure><p>Now the minimum number of datapoints that can be formed for the given combination of feature values is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EB2OvWo21m06PQnFydmLxg.png" /></figure><p>So in this case, an example of one such data record would be [M, 20, India].</p><p>If we have 30000 datapoints, then we will have only 1 instance of every combination of feature values. That is for example you will have only 1 instance of [M, 20, India].</p><p>But for the machine learning model to learn the patterns well enough, we would want at least ‘k’ instances of each combination of feature values, let’s say.</p><p>In that case, the above formula for minimum number of datapoints would become:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFuuhWvEiy_TpHYOD36gZA.png" /></figure><p>Now, if you add more features to this dataset, say features f4 and f5, now the minimum number of datapoints required for the model to perform decently would be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bPZazNLriCwel9Gdm58uLQ.png" /></figure><p>And this keeps increasing as you keep increasing the number of features or dimensions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gP5bW-rGwYFmBLgKHH262g.png" /></figure><p>But in reality, you cannot keep increasing the number of data samples you have, that too exponentially! You have a finite number of data samples that you need to work with. In that case, all you can play around with is the number of features that you can use, for the given number of data samples.</p><p>This was what was analyzed by Hughes in his study. He said that with a fixed number of training samples, the predictive power of a machine learning model at first increases as the number of dimensions increases, but after a certain number of dimensions (optimal), the performance starts to decrease.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jSuLRxcUEuNzok_xMVZUZg.png" /></figure><p>These are the limitations of having a huge number of features in your dataset. Hope the post was able to provide some intuition into this topic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=974e60b09835" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/the-curse-of-dimensionality-974e60b09835">The Curse of Dimensionality</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blender Bot — Part 3: The Many Architectures]]></title>
            <link>https://medium.com/data-science/blender-bot-part-3-the-many-architectures-a6ebff0d75a6?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6ebff0d75a6</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Fri, 26 Jun 2020 20:59:48 GMT</pubDate>
            <atom:updated>2020-06-26T20:59:48.266Z</atom:updated>
            <content:encoded><![CDATA[<h3>Blender Bot — Part 3: The Many Architectures</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H8btECr6I5c8Ck8eFW-9eg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@lunarts?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Volodymyr Hryshchenko</a> on Unsplash</figcaption></figure><p>We have been looking into Facebook’s open-sourced conversational offering, Blender Bot.</p><p>In <a href="https://towardsdatascience.com/blender-bot-part-1-the-data-524beaedde65">Part-1</a> we went over in detail about the DataSets used in the pre-training and fine-tuning of it and the failure cases as well as limitations of Blender.</p><p>And in <a href="https://towardsdatascience.com/blender-bot-part-2-the-transformer-2e4d960b149f">Part-2</a> we studied the more generic problem setting of “Multi-Sentence Scoring”, the Transformer architectures used for such a task and learnt about the Poly-Encoders in particular — which will be used to provide the encoder representations in Blender.</p><p>In this 3rd and final part, we return from our respite with Poly-Encoders, back to Blender. We shall go over the different Model Architectures, their respective training objectives, the Evaluation methods and performance of Blender in comparison to Meena.</p><h3>Model Architectures:</h3><p>The paper (Ref.[2]) discusses several variations of models, that vary in multiple factors (we’ll later discuss more on the perturbations involved). But at a high level, there are 3 different model architectures discussed.</p><ol><li>Retriever</li><li>Generator</li><li>Retrieve &amp; Refine</li></ol><h3>1. Retriever:</h3><p>Given a dialogue history (context) as input, retrieval systems select the next dialogue utterance by scoring a large set of candidate responses and output the highest scoring one. This is the exact same setting that we saw in the Multi-Sentence Scoring task using a Poly-Encoder, in Part-2 of this series. Two variations of the models are developed: with 256M and 622M parameters. The training objective here is to effectively rank the candidate responses. This is done by minimizing the Cross-Entropy loss, whose logits are given as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7xBIqfne8BSNRo3-nOm_IA.png" /></figure><p>where each ‘s’ is a score between the context embedding and one of the candidate responses’ embedding. The score can be a standard dot product similarity score between the context and candidate label encoder representations (when projected onto a common vector space), or more generally any non-linear function. Score can be given as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*48S-7rSi7FbsLDIp8pXN-Q.png" /></figure><p>The encoder representations of the context and candidate response are obtained using a Poly-Encoder — that undergoes 3 types of Attention mechanisms: 1) Self-Attention among the token embeddings of the Input context, 2) Learn ‘m’ codes by performing Self-Attention between the codes and the outputs of the previous Self-Attention, 3) Self-Attention between candidate embedding and ‘m’ global learned features. (Read Part-2 for an in-depth explanation).</p><h3>2. Generator:</h3><p>Here we use a standard Seq2Seq Transformer (Decoder) architecture to generate responses rather than retrieve them from a fixed set of candidates. Three variations of the model are developed with: 90M, 2.7B and 9.4B parameters.</p><h4>Maximum Likelihood Estimation:</h4><p>The training objective here is Maximum Likelihood Estimation — that is to minimize the negative log likelihood.</p><p>The Likelihood models the overall sequence probability distribution. The objective as given in the paper (Ref.[2]):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pO-nFWPIyRN76_8BfsfyOw.png" /><figcaption><strong>Screenshot from the paper in Ref.[2]</strong></figcaption></figure><p>where the likelihood is the probability of generating the token y_t at the time step ‘t’ given the input context ‘<strong>x</strong>’ and the tokens that were generated up to the time step ‘t’ (y_&lt;t). The gold next utterance ‘<strong>y</strong>’ refers to the ground-truth next utterance provided by humans, given the context.</p><h4>Un-Likelihood:</h4><p>In addition to maximizing the likelihood of getting the ground-truth token ‘y’ at time step ‘t’, here, we also try to minimize the probability of getting certain negative candidate tokens at that time step. This is called the Un-Likelihood objective and it helps decrease the occurrences of tokens (or n-grams) that are repeated. The Un-likelihood objective as given in the paper (Ref.[2]):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*THUReVVneWDfpqVW-oE_ZQ.png" /><figcaption><strong>Screenshot from the paper in Ref.[2]</strong></figcaption></figure><p>But how can we get the set of negative candidates at every time step ‘t’? Either we can maintain a static list of negative candidates (frequent n-grams generated by the model) and use the same at every time step. Or the more acceptable solution is where we keep the n-gram distribution of the tokens generated by the model at every time step. From this, whenever an n-gram count is greater than the corresponding n-gram count observed from the gold responses (that is, frequent n-grams used by humans), then we add that n-gram to the set of negative candidates maintained at that time step.</p><h4>Decoding: Beam Search:</h4><p>At the time of inferencing, the model has to select the best next response from among the available hypotheses, given an input context. This is called “Decoding”. The output (next response) is generated as a probability distribution over all the tokens of the vocabulary. Instead of taking the highest probability token at each time step (which is nothing but the “Greedy Search”), we can try to get the partial sentence that maximizes the joint probability up to that instant.</p><ul><li>In “Beam Search”, at each time step ‘t’, keep in memory, a list of top k partially formed hypotheses — whose joint probability is the maximum up to that time step.</li><li>Then at time t, append each token in the vocabulary to each of the top k hypotheses.</li><li>Compute the new joint probability.</li><li>Can also normalize the score by the length of the sequence formed so far up to time t.</li><li>Rank the hypothesis based on the joint probability score and then select the top k from among the new set of hypothesis. The remaining hypotheses are discarded.</li><li>In order to enforce a stopping condition, the &lt;EOS&gt; (End Of Sentence) token is also included in the vocabulary. So the procedure can be stopped when enough number of &lt;EOS&gt; tokens are reached.</li></ul><p>However, beam search heuristic has traditionally resulted in generating shorter responses — than actual human responses — therefore tend to be dull and less engaging. So we introduce a <strong>minimum length constraint</strong> — such that the &lt;EOS&gt; token will not be generated until we have partial hypotheses that satisfy a minimum length. This forces the model to generate long responses. Even though longer responses are considered more engaging (during human evaluation), they are also prone to more errors. So the minimal response length is a trade-off.</p><p>Another improvement that can be done in Beam Search is <strong>n-gram beam blocking</strong>. If a hypothesis in a beam contains more than 1 occurrence of an n-gram =&gt; that hypothesis is discarded. This is done to avoid repetition of sub-sequences or n-gram sequences.</p><h3>3. Retrieve &amp; Refine:</h3><p>The Retriever model gets the next response from a limited set of candidate responses and uses only the Input Context as its knowledge. The Generator model has no limitations on the candidate responses, but still no additional knowledge is used other than the context, in order to generate the next response. In the third alternative, external knowledge is incorporated into the model giving rise to =&gt; <strong>Retrieval before Generation</strong>.</p><h4>Dialog Retrieval:</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FxA5RlBfX4vM%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DxA5RlBfX4vM&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FxA5RlBfX4vM%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/9edf133cc7e2ab590a5c30822069d0d5/href">https://medium.com/media/9edf133cc7e2ab590a5c30822069d0d5/href</a></iframe><p>For a given Input Context, the Retrieval system (Poly-Encoder) gets the most probable next response from a fixed set of candidate responses. This is marked as “Retrieved Next Response” in the animation above. In the “Retriever” model, we stop at this point. But here, the response is appended to the Input Context via a separator and this combined sequence is fed as input to the Generator (Decoder block). The decoder generates a response for the given input sequence. The purpose of doing this is to improve the quality of responses that the generator could produce. Remember that the Candidate Labels are human generated responses. And even though the “Retrieved Next Response” need not be the same as the “golden response” for a given input context, we can assume that a good retriever will pick a candidate that closely aligns with the golden response. And human responses are generally considered to be more engaging than decoder generated responses. And the purpose here is for the Decoder to somehow learn when to simply use the “Retrieved Next Response” directly, without making any effort to generate anything on its own; and when to ignore the retrieved response and generate one based only on the context. And if the Decoder is able to learn this association it will be able to generate more human-like responses.</p><p><strong>Training Objective: alpha — blending: </strong>The ideal learning for the Decoder would be to simply use the retrieved response when it’s good and ignore it when it’s not. But in reality, more often than not, the Decoder would choose to ignore the retrieved next response and generate on its own. This is attributed to the fact alluded in the previous paragraph: the lack of understanding of the relationship between the retrieved response and the golden (human) response given the input context. To mitigate this, we do “alpha — blending”, where the retrieved next response is replaced with the golden response “alpha” % of the time. This is nothing but the more generic idea of “Teacher Forcing”.</p><h4>Knowledge Retrieval:</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FV32cRUs1dR4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DV32cRUs1dR4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FV32cRUs1dR4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6badb6760ae5cea94a478bdead253dc3/href">https://medium.com/media/6badb6760ae5cea94a478bdead253dc3/href</a></iframe><p>In this variant, an external knowledge base is used. An Information Retrieval (IR) System is built to store and retrieve the Wikipedia dump. A little aside on how the IR system works:</p><ul><li>The documents (Wikipedia articles in this case) are parsed and an inverted index is built that is of the form — {term: list of all documents in which the term appears}.</li><li>The inverted index can be searched by the “Query” and the output is the list of documents that contain any of the query terms.</li><li>Then we rank the documents thus returned by finding the similarity between the query and the document, both represented in a common vector space — whose coordinates are the TF-IDF scores of the terms in the query/document.</li></ul><p>Back to our Knowledge Retrieval System, the Input Context is used as the “Query” into the IR System in order to retrieve the most suitable Knowledge Candidates (i.e. Wiki articles that are relevant to the context). These candidates and the context are fed to the Retrieval system (Poly-Encoder) to get the best candidate — that is the best piece of external knowledge, on which our dialog next response is going to be based. This knowledge candidate is then given as input to the Generator model, that generates the next response conditioned on the knowledge sentence.</p><h3>Evaluation Methods:</h3><h4>Automatic Evaluation:</h4><p><strong>Retrieval Models:</strong> The Retrieval models are fine-tuned on the crowd-sourced clean Data Sets that we talked about in Part-1, namely, ConvAI2, ED, Wizard of Wikipedia and BST. The evaluation metric reported is Hits@1/K (which is similar in principle to the Top@N classification metric), on the corresponding dataset’s validation data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i8GhFGy9vYRpPNrIPhgDRg.png" /><figcaption><strong>Screenshot from the paper in Ref.[2]</strong></figcaption></figure><p><strong>Generator Models:</strong> Here we measure the perplexity of the underlying language model. <strong>Perplexity</strong> measures the uncertainty of a language model. The lower the perplexity, the more confident the model is in generating the next token (character, subword, or word). Conceptually, perplexity represents the number of choices the model is trying to choose from when producing the next token. From the graph below, we see that the larger model achieves a better performance in fewer steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQEMZB-cHlbjzm8swsM7dA.png" /><figcaption><strong>Screenshot from the paper in Ref.[2]</strong></figcaption></figure><h4>Human Evaluation:</h4><p>This kind of evaluation gives the leverage to arrive at comparisons between different versions of Blender as well as comparison between other chatbots in the field — as these chat logs are available in public domain for analysis purposes. Many different versions of Blender have been developed based on multiple factors like:</p><ul><li>Minimum beam length while using beam search in the generator models</li><li>Whether or not n-gram beam blocking is done</li><li>Smaller vs larger models (in terms of number of parameters learnt)</li><li>Whether a persona context was given or no persona context was given (during fine-tuning)</li><li>Using likelihood vs. combination of likelihood and unlikelihood</li><li>etc.</li></ul><p>Human evaluations were done for all kinds of variants and the detailed results are given in the paper (Ref.[2]), where you can go over them.</p><p><strong>ACUTE Eval:</strong></p><p>In this method, human evaluators are given pairs of complete conversations between a human and a chatbot. These conversations are generated by the 2 models/systems that are up for comparison. And the job of the evaluator is to compare the two dialogues and answer the following questions, as given in Ref.[2]:</p><ol><li>Engagingness question: “Who would you prefer to talk to for a long conversation?”</li><li>Humanness question: “Which speaker sounds more human?”</li></ol><p><strong>Self-Chat ACUTE Eval:</strong></p><p>This is the same type of evaluation as above, except that the conversations evaluated are between 2 models, instead of a human and a model.</p><p>A sample conversation pair as presented for a human evaluator is given below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QgjQvLET92mGEPsBDeKU5g.png" /><figcaption><strong>Screenshot from the paper in Ref.[2]</strong></figcaption></figure><h3>Comparisons:</h3><p>Finally, I’ll leave you with the human evaluation scores for Blender (and its variants) and Meena; as well as Blender and Humans — as reported in Ref.[2].</p><h4>Blender v. Meena:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w1FFz4s9J0yfJQ6Vgfa46A.png" /><figcaption><strong>* indicates statistical significance with p &lt; 0.05 and ** indicates statistical significance with p &lt; 0.01. Screenshot from the paper in Ref.[2]</strong></figcaption></figure><h4>Blender v. Human:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fy9qqKjTGK89rZcxqpFzOg.png" /><figcaption><strong>** indicates statistically significant. Screenshot from the paper in Ref.[2]</strong></figcaption></figure><p>The Blender paper is quite long and packed with information and it becomes easy to get bogged down by the details. The purpose of writing this series of posts is, basically, to be able to think out loud — identify and make the individual concepts and pieces more understandable, all the while maintaining the bigger picture as well as the ability to zoom into the specifics if required.</p><h3>References:</h3><ol><li>About Blender: <a href="https://www.kdnuggets.com/2020/05/facebook-open-sources-blender-largest-open-domain-chatbot.html">https://www.kdnuggets.com/2020/05/facebook-open-sources-blender-largest-open-domain-chatbot.html</a></li><li>Blender Bot Research: <a href="https://arxiv.org/abs/2004.13637">https://arxiv.org/abs/2004.13637</a></li><li>Blender Bot recipe: <a href="https://parl.ai/projects/recipes/">https://parl.ai/projects/recipes/</a></li><li>Poly-Encoder Transformer: <a href="https://arxiv.org/abs/1905.01969">https://arxiv.org/abs/1905.01969</a></li><li>About Meena: <a href="https://ai.googleblog.com/2020/01/towards-conversational-agent-that-can.html">https://ai.googleblog.com/2020/01/towards-conversational-agent-that-can.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6ebff0d75a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/blender-bot-part-3-the-many-architectures-a6ebff0d75a6">Blender Bot — Part 3: The Many Architectures</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[Blender Bot — Part 2: The Transformer]]></title>
            <link>https://medium.com/data-science/blender-bot-part-2-the-transformer-2e4d960b149f?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e4d960b149f</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Thu, 25 Jun 2020 20:46:16 GMT</pubDate>
            <atom:updated>2020-06-25T20:46:16.872Z</atom:updated>
            <content:encoded><![CDATA[<h3>Blender Bot — Part 2: The Transformer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ml1zhFpBFFWyfbjT99rOw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@codyengel?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Cody Engel</a> on Unsplash</figcaption></figure><p>Facebook’s open sourced chatbot “Blender” is breaking all records previously set by Google’s “Meena”. In this post, we will go over the <strong>Poly-Encoders</strong> Transformer architecture, that forms the crux of Blender.</p><p>You can read Part 1 of this series, where we have gone over the Data Sets on which the chatbot is trained, on <a href="https://towardsdatascience.com/blender-bot-part-1-the-data-524beaedde65">TDS</a>.</p><p>Assuming the reader has a prior understanding of Attention, Transformers, BERT and Generative Language Models, I shall march forth.</p><h3>Introduction:</h3><p>Before seeing how the Poly-Encoder is used in the context of Blender, we will first understand them independently. The datasets and (fake) training tasks employed in pre-training and fine-tuning the Blender (which are explained in detail in Part 1) should not be confused with the details am about to explain below. The experimental settings given here, are to understand a specific task called “<strong>Multi-Sentence Scoring</strong>” and the Encoder architectures trained for that task, in a generic setting. And then among the Encoder architectures trained for this task, we will see how the Poly-Encoders are superior.</p><h3>Task:</h3><p>Multi-Sentence scoring does pairwise comparison between the input and output sequences. Given an input sequence, we score a set of candidate labels.</p><p>From here on, we’ll represent the input-output pair by <strong>[INPUT, LABEL]</strong>.</p><p>The goal is to find the best label from among a finite list of candidate labels. The Encoder used is the BERT-Base with 12 Encoder blocks, 12 Attention heads and 768 hidden neurons in the Feed Forward Network.</p><h4>Pre-Training:</h4><p>Two versions of pre-training are done for this task:</p><ol><li>pre-trained like BERT, on the Toronto Book Corpus and Wikipedia. Here, the [INPUT, LABEL] can be thought of as [Sentence A, Sentence B].</li><li>pre-trained on the public domain social media conversations available from Reddit. Here, the [INPUT, LABEL] can be understood as [Context, Next Sentence]</li></ol><h4>Fake Training Tasks:</h4><p>The training tasks are the same ones used in the pre-training of BERT.</p><ol><li><strong>MLM: Masked Language Model:</strong> Here a certain percentage of the input tokens are masked at random (with [MASK] token). The task then is to learn to predict the masked tokens.</li><li><strong>NSP: Next Sentence Prediction:</strong> Here given 2 sentences A and B, the task is to say if B follows A? (with Negative Sampling). Negative Sampling is implemented by taking a random sentence from the dataset as B, 50% of the time.</li></ol><p>A little digression here. A trick that I use, to remember the nature of these pre-training tasks in BERT is to draw a direct comparison with the fake training tasks used in generating the Word2Vec embeddings, namely: 1) CBOW 2) Skip-Gram. If you could recall, in CBOW (Continuous Bag of Words), given a context the task is to predict the target word — similar to the MLM task. And in the Skip-Gram model, given the target word predict the context =&gt; but instead of predicting the context/neighbouring word, we change the dataset and the task becomes: given the target word and another word -&gt; predict if the other word is a neighbour of the target word or not (binary classification problem). Since the initial dataset was formed only with target words and words in their context, the modified dataset now contains only positive examples. So we introduce noise by negative sampling. Very very similar to the NSP task of BERT. (If you think there is any inconsistency in drawing such a comparison between the training tasks of BERT and Word Embeddings, do let me know in the comments. Thanks!)</p><h4>Fine-Tuning:</h4><p>The model is fine-tuned separately on the ConvAI2 dataset, thereby encouraged to learn the “Personality” trait and on the Ubuntu chat logs which would help them learn “Domain Knowledge/Expertise”.</p><h3>Architectures:</h3><p>We will see 3 Encoder architectures to solve the “Multi-Sentence Scoring” task, namely,</p><ol><li>Bi-Encoder</li><li>Cross-Encoder</li><li>Poly-Encoder</li></ol><p>The performance of an architecture during inferencing is measured both by the quality of the prediction and also by the prediction speed.</p><p>Before proceeding, it is important to remember that this is a <strong>Retrieval and NOT Generative task</strong>: we only need to retrieve a correct label from a fixed set of candidate labels.</p><h3>Bi-Encoder:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*Vc2OFos5MAlJsdGTWJ5JrQ.png" /><figcaption><strong>Bi-Encoder architecture from Ref [1]</strong></figcaption></figure><p>In Bi-Encoders, Self-Attention is performed over the Input and Label separately. This is nothing but the more generic concept of a Vector Space model. This architecture has the advantage of being faster during inferencing, because we can pre-compute &amp; cache encodings of large, fixed set of candidate labels. This is made possible as the labels are getting encoded separately and have no dependancy with that of the input context.</p><ul><li>Both the INPUT and LABEL are surrounded by a special token [S]. This is similar to the [CLS] token in BERT, which captures the features of the entire sentence.</li><li>The embeddings input to the Encoder is a combination of Token Embeddings + Segment Embeddings + Position Embeddings. The Segment Embedding is generally used to say if a token belongs to Sentence A or Sentence B (in the context of BERT). Since the INPUT and LABEL are encoded separately here, the Segment Embedding is ‘0’ in both the cases.</li><li>Map the input and candidate label separately to a common feature space. In the formula shown, T1 and T2 are two separate Transformers (Encoders).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JnZ8PZ2_hUbzIIyzf1A9lw.png" /></figure><ul><li>The Encoder, after performing Self-Attention on the Input token embeddings, gives the encoder representations for every token like:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*I59GNRD3sbT4cccwyXk6_Q.png" /></figure><ul><li>A reduce function (<strong>red</strong>) is then used to reduce this to a single embedding representation. The <strong>reduce</strong> function can be any of the following:</li></ul><p>-&gt; it can either take the representation of the first token. This is the representation corresponding to the special token [S]</p><p>-&gt; or we can take the average over all the output embeddings</p><p>-&gt; or we can take the average over the first ‘m’ (m&lt;N; where N — token length) output embeddings</p><ul><li>Once the INPUT and LABEL are represented thus in a common vector space, measure the similarity between them using standard dot product or any other non-linear function.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*kU-8h1JkHHMMg-fN7cBkjw.png" /></figure><ul><li>We then minimize the Cross Entropy loss function, where the logits look like:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7xBIqfne8BSNRo3-nOm_IA.png" /></figure><h3>Cross-Encoder:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*IAb1AGON_5WWWb3SQkiI5w.png" /><figcaption><strong>Cross-Encoder architecture from Ref [1]</strong></figcaption></figure><ul><li>Here, the INPUT and the LABEL are concatenated and Full Self Attention is performed between the entire sequence of input and label.That is, every token of the input would attend to every token of the label and vice versa. This gives rise to rich interactions between the input and label.</li><li>Even here, both the INPUT and LABEL are surrounded by a special token [S].</li><li>Again, the embeddings input to the Encoder is a combination of Token Embeddings + Segment Embeddings + Position Embeddings. Since the INPUT and LABEL are combined, the Segment Embedding is ‘0’ for a INPUT token and ‘1’ for a LABEL token.</li><li>Cross-Encoders give higher accuracy than the Bi-Encoder, because of the full bi-directional attention between the input and the label. At the same time, they are extremely slow during inferencing — because, as each of the candidate labels are supposed to be concatenated with the input context, and cannot be encoded separately like in the case of Bi-Encoders. Therefore candidate embeddings cannot be pre-computed and cached. When the number of candidate labels is huge (as it is in most real scenarios), cross-encoders do not scale.</li><li>After Self-Attention, the Transformer gives the encoder representations for all the input tokens. We reduce this to a single representation, by taking the embedding corresponding to the first token (i.e. the special token [S]). This embedding vector is then converted to a scalar score by doing a linear projection. These two steps are shown below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*DsgLnxdsE8WAmVKTw_xYYg.png" /></figure><ul><li>The training objective here too is to minimize the Cross-Entropy loss function given by the logits:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7xBIqfne8BSNRo3-nOm_IA.png" /></figure><ul><li>where ‘<em>cand1’</em> is the correct candidate and the others are negatives taken from the training set. One problem here is that, in the bi-encoder we could use the other labels in the batch as negative training samples- here we cannot do that. we use external negatives provided in the training set. Because it is computation heavy, the in memory batch size of the cross encoder is also very small.</li></ul><h3>Poly-Encoder:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*80fapGuuD18__Q2KNPflIQ.png" /><figcaption><strong>Poly-Encoder architecture from Ref [1]</strong></figcaption></figure><ul><li>Poly-Encoder take the best qualities of Bi- and Cross-Encoders. Therefore, it is faster during inferencing than the Cross-Encoders and have better accuracy than Bi-Encoders.</li><li>The Candidate Label is encoded separately.</li><li>Given the input context like:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*oFEQPs0Vo4NpuCM1Vl_1Xw.png" /></figure><p>we perform 3 types of Attention, as explained below:</p><ul><li>Self-Attention over the Input Context’s tokens and we get:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*ZjEx9xL24mchlt8MZJaqhA.png" /></figure><ul><li>Second, we learn ‘m’ codes (or queries in the parlance of Self-Attention), where m &lt; N (N being the length of the INPUT). The number of codes to be learnt, ‘m’, is a hyperparameter. Each code Ci attends over all the outputs of the previous Self-Attention. The ‘m’ codes are randomly initialized.</li><li>We first get the Attention weights (w’s) by performing a dot-product attention (or a multiplicative attention in general) between the ‘m’ codes — which serve as the “Queries”, and the previous Self-Attention outputs (Out’s)—which serve as the “Keys”. Then use these attention weights to get a weighted sum of the previous Self-Attention outputs(Out’s) — which serve as the “Values”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZGjKRnXebD102EZtzdatjw.png" /></figure><ul><li>Think about why we are doing this kind of an Attention mechanism here. In a Bi-Encoder, the candidate label does not attend over the tokens of the input context. A Cross-Encoder on the other extreme, makes the candidate label attend over every token of the input context. Somehow in the Poly-Encoder we are trying to find a middle ground, by making the candidate label embedding attend over not the entire input context, but over a subset of features learnt from the input context.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oCyEkKCCKCX2B-G6xl0gZQ.png" /></figure><ul><li>The third kind of attention (alluded to in the previous paragraph) is between the ‘m’ global features of the Input Context and the embedding of the Candidate Label.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w1gO64sQtnbIABQ3Kx-sog.png" /></figure><ul><li>Now we compute the Similarity score between the Input Context embedding and the Candidate Label embedding as:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*48S-7rSi7FbsLDIp8pXN-Q.png" /></figure><ul><li>Once again, the training objective here too is to minimize the Cross-Entropy loss function given by the logits as before.</li></ul><p>We saw three different Encoder architectures for the task of “Multi-Sentence Scoring” and saw how the Poly-Encoders were better. In the next part, we will see how the Poly-Encoders are used in the Blender and also about the different Model Architectures and training objectives. We will also touch upon the Evaluation methods used to compare the performance of Blender with that of the other Chatbots.</p><p><strong>Note:</strong> All the notations, formulae and the Encoder block diagrams above are the same as used in the original paper mentioned in Ref.[1].</p><h3>References:</h3><ol><li>Poly-Encoder Transformer : <a href="https://arxiv.org/abs/1905.01969">https://arxiv.org/abs/1905.01969</a></li><li>BERT : <a href="https://arxiv.org/abs/1810.04805">https://arxiv.org/abs/1810.04805</a></li><li>Transformers : <a href="https://arxiv.org/abs/1706.03762">https://arxiv.org/abs/1706.03762</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e4d960b149f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/blender-bot-part-2-the-transformer-2e4d960b149f">Blender Bot — Part 2: The Transformer</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[Blender Bot — Part 1: The Data]]></title>
            <link>https://medium.com/data-science/blender-bot-part-1-the-data-524beaedde65?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/524beaedde65</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Sun, 21 Jun 2020 14:39:11 GMT</pubDate>
            <atom:updated>2020-06-21T14:59:45.255Z</atom:updated>
            <content:encoded><![CDATA[<h3>Blender Bot — Part 1: The Data</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sB4Nh9pOyCQquCpxgxXJ7Q.jpeg" /><figcaption>Image Source: <a href="https://unsplash.com/@austindistel">Austin Distel at Unsplash</a></figcaption></figure><blockquote>“I’m good at the art of assimilation. I have watched &amp; listened &amp; learned. I knew nothing, but I studied the ways of men and slowly learnt how to ruin, how to hate, how to debase, how to humiliate. And at the feet of my master, I learnt the highest of human skills, the skill that no other creature owns. I finally learnt how to lie!”</blockquote><p>Can you guess who uttered those lines? Let me give you 2 options:</p><p><strong>A)</strong> A ChatBot <strong>B)</strong> The Creature from Frankenstein.</p><p>I’ll reveal the answer at the end of this article.</p><h3>Introduction:</h3><p>The purpose of a good chatbot is to observe and listen and learn and study the ways of men (and women!), and to learn many different human skills, in order to engage in a good conversation. Chatbots serve in 2 different settings within the purview of conversational agency.</p><ol><li><strong>Goal Oriented Dialog:</strong> These are the ones engaged in Online Ticket / Restaurant booking and other customer services. They usually have a fixed set of “intents” and corresponding “responses” (as well as “actions” mapped to the intents, that are taken in the background). They also have a knowledge base (database) at their disposal which they can access by way of API calls.</li><li><strong>Open Domain Dialog:</strong> These are the ones that can engage in open ended chit chat in a wide range of topics. Recent advancements in open domain chatbots have been vastly due to scaling neural network models — by having more parameters and training on huge corpora. Eg: Meena from Google. Meena has 2.6B parameters and is trained on 341GB of text from social media conversations. And compared to OpenAI GPT-2, Meena has 1.7x greater model complexity and was trained on 8.5x more data.</li></ol><p>But the researchers from FAIR attempt to show that scaling alone is insufficient and there is a lot more to be accounted for to generate a good conversation — for the chatbot to display human-like traits, like:</p><ol><li>Personality</li><li>Engaging-ness</li><li>Empathy</li><li>Domain knowledge/expertise</li></ol><p>Enter “Blender Bot”, FAIR’s champion conversational agent which they have open sourced recently.</p><p>In this 3 part series about Blender, I will try to explain the data sets used, the evaluation methods, the workings of the transformer architectures used and the model architecture with their training objectives, one by one. In the first part, let us discuss in detail about the data sets used and also see an overview of the limitations and failure cases. The paper is a bit system-heavy, so prior understanding of Attention, Transformers, BERT and Language Models in general would help tie all the pieces together seamlessly (not required for Part-1).</p><h3>Data Sets:</h3><p>Different data sets and (fake) tasks are used during the pre-training and fine-tuning stages of the model.</p><h4>Pre-training:</h4><p>BERT is pre-trained on the Toronto Book Corpus and Wikipedia. Such a training will not help in this case, because we are dealing with dialog generation and not just sentence associations. Therefore public domain data from Reddit and subreddits are used as the source of truth. Around 1.5B training examples are generated. The goal here is to generate a comment, conditioned on the full thread leading up to the comment. Cleaning the reddit data is a challenging process. A particular comment is not-used in the following cases:</p><ol><li>if the author is a known bot</li><li>if it is from a non-English subreddit</li><li>if it is longer than 2048 characters or fewer than 5 characters</li><li>if it contains a URL</li><li>if it starts with a non-ASCII character</li><li>if it is at a depth &gt; 7 in the thread</li><li>if it is a removed/deleted comment</li></ol><p>In spite of cleaning it, the data still suffers from toxicity, noise and the fact that they are not 2-way conversations but group discussions.</p><h4>Fine-Tuning:</h4><p>Fine tuning of transformer models are usually done on data sets that are more relevant and closer to the downstream tasks. In the same line, fine-tuning for Blender is done on crowd-sourced, cleaner, smaller, 2-way conversational datasets. Let’s see about each of them in detail.</p><ol><li><strong>ConvAI2:</strong> This is the dataset from the ConvAI2 Challenge in NeurIPS-2018. It is based on the Persona Chat dataset. Here, each of the 2 speakers is given a role to play based on sentences describing their persona, which were also separately crowdsourced (both speakers can see their own persona description, but cannot see their partner’s persona). The task thus involves getting to know the other speaker and engaging them in friendly conversation, both asking and answering questions. The use of a “persona” gives improved consistency for the bot.</li><li><strong>Empathetic Dialogues (ED):</strong> This dataset was benchmarked in “<em>Towards empathetic opendomain conversation models: A new benchmark and dataset”, Rashkin et al., 2019. </em>Here, in each dialogue, one speaker describes a personal situation and the other plays a “listener” role, displaying empathy during the discussion. Fine-tuning models on this dataset helps them display more empathy in human evaluations.</li><li><strong>Wizard of Wikipedia (WoW):</strong> The task here involves discussing a given topic in depth, where the goal is to both engage the partner as well as display expert knowledge. The two participants, however, are not quite symmetric: one will play the role of a knowledgeable expert (which we refer to as the wizard) while the other is a curious learner (the apprentice). One of them will choose a topic. The wizard has access to an information retrieval system that shows them paragraphs from Wikipedia possibly relevant to the conversation, which are unobserved by the apprentice. Before each conversation turn the wizard can read these paragraphs and then potentially base their next reply on that observed knowledge. The goal of collecting this dataset is to then replace the human wizard with a learned agent that will speak to a human apprentice instead.</li><li><strong>Blended Skill Talk (BST):</strong> A small crowdsourced dataset of about 5k conversations, where the participants were asked to display all 3 qualities — personality, empathy and expertise — during a conversation, whenever appropriate. They provide responses from models that have been trained towards a specific skill, as inspiration to one of the two workers in the conversation. That worker is free to either use and modify or ignore those responses. Thus, each conversation involves an “unguided” speaker and a “guided” speaker, with the unguided speaker talking first. Whenever it is the guided speaker’s turn to respond, they are shown three suggested responses, one each from three single-task poly-encoder models (more on this in the next part) trained on the ConvAI2, ED, and WoW datasets. All the conversations in BST are fully annotated on the skill represented. Once the dataset is collected, an oracle model is trained by combining models trained towards individual capabilities. There are 2 variants of it: <strong>a)</strong> The poly-encoder is first pre-trained on the Reddit dataset and then fine-tuned on individual datasets. <strong>b)</strong> Pre-trained on reddit dataset then fine tuned on BST dataset itself. Given below is an example conversation between 2 crowd-workers from the BST dataset.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*25iAJygniSg4t5BbNgiP8w.png" /><figcaption>Sample conversation between a Guided and Unguided speakers from the BlendedSkillTalk dataset.</figcaption></figure><p>Sample conversation from the BlendedSkillTalk dataset, annotated with four conversation mode types: PB: personal background; K: knowledge; S: personal situation; E: empathy. The guided (G) and unguided (U) workers are given personas and a topic. The conversation has been seeded with two utterances from a conversation sampled from WoW. When the guided worker selected one of the suggestions, it is shown in shaded grey.</p><h4>Safety:</h4><p>BST and the other datasets on which fine tuning is done are all crowdsourced, where the crowd-workers were given explicit instructions to not use toxic / biased language, and hence are generally safer to train on. But remember pre-training is done on Reddit data — which is prone to contain negative training samples in abundance. A classifier, which is trained to identify toxic language, is used at the time of inferencing to help mitigate this problem.</p><h3>Model Limitations &amp; Failure Cases:</h3><ol><li><strong>Vocabulary Usage:</strong> Generative Transformer Models that employ Beam Search decoding show an inclination towards generating common words too frequently and rarer words too infrequently. For example, most commonly occurring 3-grams (in the dataset) like “do you like”, “have any hobbies”, “lot of fun” are repeated over and again.</li><li><strong>Nontrivial repetition:</strong> The models often repeat what is said to them. For instance, they’ll say that they had a pet dog if a conversation partner mentions a pet dog, or that they like the same bands as the person they’re speaking with.</li><li><strong>Contradiction and forgetfulness:</strong> Blender models contradict themselves, albeit to a lesser degree in the larger models. They also fail to make the logical link that they shouldn’t ask questions they’ve asked before (to avoid the appearance of “forgetting”).</li><li><strong>Knowledge and factual correctness:</strong> It’s relatively easy to manoeuvre Blender models into making factual errors, particularly when exploring a topic deeply.</li><li><strong>Conversation length and memory:</strong> Blender conversations would likely be dull and repetitive over the course of several days or weeks of conversation, — especially considering Blender can’t remember earlier conversations.</li><li><strong>Deeper understanding:</strong> The Blender models lack the ability to learn concepts through further conversation, and they have no way of grounding to entities, actions, and experiences in the real world.</li></ol><p>In the image below, you can find examples of failure cases:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T9AD4nz52IgUE09lv2KgWQ.png" /><figcaption>Example of Failure Cases.</figcaption></figure><p><strong>Issue Identified:</strong></p><ol><li>Example 1: non-trivial repetition</li><li>Example 2: forgetfulness</li><li>Example 3: contradiction, Georgia is not in the MidWest</li><li>Example 4: hallucinating knowledge, wrongly connecting games with the makers</li></ol><p>In the next part, we will explore the Transformer architecture used in Blender, known as, Poly-Encoder and how it is superior to the other variants like Bi- or Cross-Encoder used for the same task of Multi-Sentence Scoring.</p><p>And finally, the answer to the question we saw at the beginning of the article: B) The Creature from Frankenstein! If you guessed it as A) A ChatBot, well you are almost close, for it won’t be long before we could chat about the vileness of humans to a well-rounded conversational agent!</p><h3>References:</h3><ol><li>About Blender : <a href="https://www.kdnuggets.com/2020/05/facebook-open-sources-blender-largest-open-domain-chatbot.html">https://www.kdnuggets.com/2020/05/facebook-open-sources-blender-largest-open-domain-chatbot.html</a></li><li>Blender Bot Research: <a href="https://arxiv.org/abs/2004.13637">https://arxiv.org/abs/2004.13637</a></li><li>Blender Bot recipe : <a href="https://parl.ai/projects/recipes/">https://parl.ai/projects/recipes/</a></li><li>Blended Skill Talk : <a href="https://arxiv.org/abs/2004.08449">https://arxiv.org/abs/2004.08449</a></li><li>Wizard of Wikipedia : <a href="https://arxiv.org/abs/1811.01241">https://arxiv.org/abs/1811.01241</a></li><li>About Meena : <a href="https://ai.googleblog.com/2020/01/towards-conversational-agent-that-can.html">https://ai.googleblog.com/2020/01/towards-conversational-agent-that-can.html</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=524beaedde65" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/blender-bot-part-1-the-data-524beaedde65">Blender Bot — Part 1: The Data</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[The Linear Algebraic Love for ML: Or How Change of Basis, EigenDecomposition & PCA all come…]]></title>
            <link>https://medium.com/analytics-vidhya/the-linear-algebraic-love-for-ml-or-how-change-of-basis-eigendecomposition-pca-all-come-f3d37715978c?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f3d37715978c</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Wed, 03 Jun 2020 04:55:46 GMT</pubDate>
            <atom:updated>2020-06-10T16:10:22.281Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Linear Algebraic Love for ML: Or How Change of Basis, EigenDecomposition &amp; PCA all come together beautifully!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*lifBC7GN5ugoZFc_6G7pDA.png" /><figcaption>Image Source: <a href="https://mathconceptions.wordpress.com/2013/06/12/word-clouds-indicate-retention/">Mathconceptions</a></figcaption></figure><p>When we deal with Vector Spaces, more often than not we use the concepts of Vectors and Co-ordinates of the vectors interchangeably. But they are two very different ideas. The co-ordinates of a vector is always with respect to a basis.</p><p>And if we omit the basis, we naturally assume it to be the standard basis {(0,1), (1,0)}. For the purpose of this article, let us call the standard basis co-ordinate system as CS-1. A vector in CS-1, is usually written as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/428/1*Pz4U-w2QMKbqSgEbj2cmrg.png" /></figure><p>It can also be written in the matrix form as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*GyTQm0yPPjR9UnrEao4KHw.png" /></figure><p>So the above actually represents the co-ordinates of the vector <strong>a</strong>, and can be written as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*w0nYllRTuL0Q16Kovsinew.png" /></figure><h3>Change of Basis:</h3><p>Now, let us consider a second co-ordinate system CS-2 whose basis vectors are given as follows, w.r.t. that co-ordinate system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*-dEBKWODE4x2Cs-6DoAx1A.png" /></figure><p>An alternate co-ordinate system can be thought of as a Vector Space spanned by its own basis vectors. If you have your default vector space represented by the standard co-ordinate system CS-1 as your anchor point, you can think of this 2nd vector space as something that resulted after applying one or more transformations (translation, rotation, etc.) on the default vector space.</p><p>And consider a vector in the CS-2, whose co-ordinates w.r.t. CS-2 are given. This written as a linear combination of its basis vectors will look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*gjKVk1R0PbTBYvV_P2oKZA.png" /></figure><p>But the last equation is how the vector is represented in CS-2. We understand CS-1 better, right? So in order to translate this vector in CS-1, we first have to represent CS-2’s basis vectors in CS-1. From a transformations perspective, this is like saying, how the standard basis vectors, <strong>i</strong> and <strong>j</strong> got transformed to <strong>b1</strong> and <strong>b2</strong>. Let us say that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*nMOev2ciIHjRwr-9k-qiGQ.png" /></figure><p>The matrix in the last equation above, is what is called as a <strong>Change of Basis matrix</strong>. And we get the vector represented in CS-1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*RMOV5Pvly6str8H5I86L5g.png" /></figure><p>In a generic form, we can say:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g1MepxHbI3HWjH14qKKZ8w.png" /></figure><p>In plain English, we can say, the transformation matrix (change of basis matrix) gives the new coordinate system’s (CS-2) basis vectors — represented in original coordinates CS-1.</p><h3>Decomposing a Transformation:</h3><p>Before moving onto eigendecomposition, we need to understand that a transformation can be broken down into multiple transformations applied one after the other and that will produce the same effect as the original transformation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/576/1*ISCQkmBnS9RlDpdmiJCGpw.png" /></figure><p>That is instead of applying the original complex transformation <strong>A</strong>, we try to apply an equivalent simpler transformation (<strong>B</strong>) by taking it to a different vector space (represented by another set of basis (<strong>M</strong>)) and then bring the transformed vector back to our original vector space (<strong>M^-1</strong>).</p><p>Where:</p><p><strong>M</strong> : change of basis matrix</p><p><strong>B</strong> : simpler transformation on the alternate</p><p><strong>M^-1</strong> : inverse change of basis matrix</p><h3>EigenDecomposition:</h3><p>An interesting property of a real symmetric transformation matrix has to be quoted here: an <em>n×n real </em>symmetric matrix has<em> n</em> linearly independent and orthogonal eigenvectors (that is, the eigenvectors are perpendicular to each other), and it has <em>n</em> real eigenvalues corresponding to those eigenvectors. So the eigenvectors also span the whole <em>n</em> dimensional space. In other words, the eigenvectors can be used as the basis vectors for the same <em>n</em>-dim space.</p><p>Also, a real symmetric matrix is said to be orthogonally diagonalizable. This is the so-called <strong><em>“Spectral Theorem”</em></strong>. Fun Fact: the name is because, the eigenvalues of a matrix are called its “spectrum” — explaining why this is so, requires touching upon Banach spaces, functional analysis, eigenstates in Quantum mechanics, etc. — all of which are out of the scope of this author!</p><p>So coming backto where we were, by orthogonal diagonalization, the matrix <strong>A</strong> can be decomposed as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*LRERexgEAZehgt62OMwqrg.png" /></figure><p>Where <strong>D</strong> is a diagonal matrix, whose diagonal elements are nothing but the eigenvalues of <strong>A</strong>. And this equation is called the <strong><em>“EigenDecomposition”</em></strong> of A.</p><p>To quote directly from the [Ref.] <em>“That is to say, A acts like a diagonal matrix, when we change coordinates: more precisely, the mapping x -&gt; Ax in standard basis is the same as [xm] -&gt; D[xm] when written in M’s coordinates.”</em></p><p>Combining the above ideas, therefore, we can say that when a transformation matrix is real symmetric, the corresponding transformation can be decomposed into 3 simpler transformations: rotation, scaling, reverse-rotation. That is, it transforms a vector by: taking it to the eigenbasis coordinates, stretching or shrinking the vector along its eigenvectors (the amount of stretching or shrinking is proportional to the corresponding eigenvalues), and then bringing it back to our standard coordinates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qLWiHoYZUT00rK3mz47sRA.png" /></figure><h3>Principal Component Analysis (PCA):</h3><p>PCA can be explained from multiple frames of reference — as maximizing the variance or minimizing the reconstruction errors. Here we will see PCA explained as the EigenDecomposition of the Covariance matrix. Let the Data Matrix and the Transformation Matrix be defined as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*0OsEeVbshjGrVxNN2VovDg.png" /></figure><p>The transformation is given as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*hJ5HdzJOQOxPVnXAy1srLQ.png" /></figure><p>Find the Covariance matrix of this transformed matrix:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*DT5Hz48wcREE5y454Lc6LQ.png" /></figure><p><strong>V</strong> is the Covariance Matrix of the original Data Matrix before transformation.</p><p>The best transformation <strong>W</strong> will reduce the covariance (after transformation) to a Diagonal matrix (meaning, there is no correlation between the variables, after the transformation)</p><p>For <strong>WVW^T</strong> to be a diagonal matrix,</p><p><strong>W</strong> : Eigenbasis: eigenvectors of <strong>V</strong> as the basis.</p><p>So the data points are transformed from Rd to Rk where Rk is the subspace spanned by the k Eigenvectors of the original Covariance matrix <strong>V</strong>.</p><p>From the above flow of ideas, you can see how several seemingly unrelated concepts all amalgamate to help understand a specific Machine Learning construct.</p><h3>References:</h3><p><a href="https://www.math.wustl.edu/~freiwald/309orthogdiag.pdf">https://www.math.wustl.edu/~freiwald/309orthogdiag.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f3d37715978c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/the-linear-algebraic-love-for-ml-or-how-change-of-basis-eigendecomposition-pca-all-come-f3d37715978c">The Linear Algebraic Love for ML: Or How Change of Basis, EigenDecomposition &amp; PCA all come…</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Git to Colab, via SSH]]></title>
            <link>https://medium.com/data-science/using-git-with-colab-via-ssh-175e8f3751ec?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/175e8f3751ec</guid>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[google-colab]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Tue, 05 Jun 2018 16:32:51 GMT</pubDate>
            <atom:updated>2019-01-09T13:55:56.016Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to integrate Git with Colab, so you can clone your public/private repositories.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Sd8UcWKMXw6F5jsV" /></figure><p>When you are using Google’s Colaboratory (Colab) for running your Deep Learning models the most obvious way to access the large datasets is by storing them on Google Drive and then mounting Drive onto the Colab environment. But a lot of open sourced large datasets that are available for research purposes, are hosted on Github/Gitlab. Fortunately, Colab provides an easy way to integrate your Github and access your repositories. So, let us see the steps in detail.</p><h3>Colab — Git — Integrate:</h3><p>I will explain the integration in case of two scenarios:</p><ol><li>using a Public Git repository (without SSH)</li><li>using a Private Git repository (using SSH)</li></ol><h3>Clone a Public Git Repo: (without SSH)</h3><p>The integration is just a couple of lines — when the git repository you want to clone is a public one.</p><ul><li>Mount Google Drive on to your Colab environment.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*AKgBDN1y-8os1ycc" /></figure><p>On executing the above 2 lines, you will be prompted to go to the Google Accounts URL as shown, for authenticating. Click on the URL displayed in the Output section of the notebook cell. This takes you to a page like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/0*rHQSODqEZVxqgLbr" /></figure><p>Click on Allow button. This will take you to the next page where an Authorization code is displayed (where I have struck in red).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/342/0*an5XAU3xPbec9v1q" /></figure><p>Copy this code and paste it in the cell (as shown in the first image) in the place where it says ‘Enter your authorization code’, and then click Enter. Google Drive is now mounted and you get the message confirming that.</p><ul><li>Clone your public Git repo into your Drive folder. After executing the above steps, the Drive files will be present in the path <em>“/content/drive/My Drive”</em> and you can browse through them using the panel on the left side.</li></ul><p>You can then set any of your Drive folders as your working directory. Then clone the public git repo in to your working directory. These two steps are implemented as below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZzfVERI62S-b_nIK" /></figure><h3>Clone a Private Git Repo: (using SSH)</h3><p>Unfortunately, you cannot clone your private repositories as easily. As a matter of fact, you can pull off a one-liner in that case as well as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*urnt7l3xzVH8U08_" /></figure><p>That is, provide your <em>username:password</em> along with the repository link to clone a private repository. This works, but the catch is that the password gets stored in git/config and in your bash history logs. Therefore it is not advisable to clone your private repos in the above manner. Instead we will be using the SSH protocol to connect your private github/gitlab repo to colab.</p><ul><li>The first step is to generate ssh key pairs (private-public) on your local machine. You can go through <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2">this excellent article</a> (Step 1 and Step 2 of the article) on how this can be done. But I’m providing the necessary steps right away:</li></ul><blockquote>ssh-keygen -t rsa -C “your_email@youremail.com”</blockquote><blockquote>#Enter the name of the file when prompted: ~/.ssh/id_rsa_&lt;some_name&gt;</blockquote><blockquote>#Enter a passphrase: just press ‘Enter’ (for no passphrase)</blockquote><ul><li>The private key is saved in the file: <em>~/.ssh/id_rsa_&lt;some_name&gt;</em> and the public key is saved in the file: <em>~/.ssh/id_rsa_&lt;some_name&gt;.pub </em>Copy these two files in a folder. I have put a copy of these 2 files in a folder and named it <em>‘ssh-colab’</em>.</li><li>Next create a config file</li></ul><blockquote>touch config</blockquote><blockquote>edit config</blockquote><ul><li>The contents of the config file should be as below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/414/0*lHo03TYmTC9xms7a" /></figure><ul><li>Now place the config file also in the folder created before <em>‘ssh-colab’</em>. Then archive it as <em>‘ssh.tar.gz’</em>:</li></ul><blockquote>tar -czvf ssh.tar.gz ssh-colab</blockquote><ul><li>This archived folder containing the private key, public key and the config file has to be uploaded to Colab. We shall see this in a minute. But before that, let us place the public key on the server (Github/Gitlab).</li><li>Copy to clipboard the contents of your public key from the file <em>id_rsa_&lt;some_name&gt;.pub</em></li><li>Log in to Github</li><li>Click on your <em>profile &gt; Settings &gt; SSH and GPG Keys &gt; New SSH Key</em></li><li>Paste the contents of the clipboard and Save</li><li>Now for the steps to be executed on Colab. First let’s upload the archive <em>‘ssh.tar.gz’.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZKViEL_umXFG9m56" /></figure><ul><li>Now we need to move the key pair files and config file into the /root/.ssh folder. The shell commands to be executed are given in detail in the image below:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P8m5TMZn2685SCWH" /></figure><ul><li>The next step is to load the private key into the local ssh-agent. The reasoning behind this is clearly explained in the marked answer in <a href="https://stackoverflow.com/questions/10054318/how-to-provide-username-and-password-when-run-git-clone-gitremote-git?noredirect=1&amp;lq=1">this stackoverflow post</a>. I will give a gist of it below:</li></ul><blockquote>“You want to be running ssh-agent in the background as you log in. Once you log in, the idea is to run ssh-add once and only once, in order to give the agent your passphrase, to decode your key. The agent then just sits in memory with your key unlocked and loaded, ready to use every time you ssh somewhere. All ssh-family commands1 will then consult the agent and automatically be able to use your private key.”</blockquote><ul><li>So to run your ssh-agent use the following command</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/341/0*8a7tLxS2UD6tb-hc" /></figure><ul><li>In the Output section of the cell, you get a warning message and the ssh-agent starts running. You get a prompt where you can execute shell commands. See the image below, where we add the private key and then check if the new key is saved:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d9bhBtcpJW6iRDK1" /></figure><ul><li>Set your Git account in the next step</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*juRy9YRgnTvtX3sWF9ixKg.png" /></figure><ul><li>We can now clone our private git repository. Change the working directory to a folder inside your Drive. Then run git clone.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xpPeotusE-HErSyceyXjqA.png" /></figure><p>That’s all! We have SSH-ed into our Git account from Colab and cloned our private repository.</p><p>References:</p><ol><li><a href="https://stackoverflow.com/questions/48350226/methods-for-using-git-with-google-colab">https://stackoverflow.com/questions/48350226/methods-for-using-git-with-google-colab</a></li><li><a href="https://stackoverflow.com/questions/10054318/how-to-provide-username-and-password-when-run-git-clone-gitremote-git?noredirect=1&amp;lq=1">https://stackoverflow.com/questions/10054318/how-to-provide-username-and-password-when-run-git-clone-gitremote-git?noredirect=1&amp;lq=1</a></li></ol><p><em>Images of the Logos are Googled. Copyrights belong to Colaboratory and Github respectively. Other images are screenshots of my work.</em></p><p><em>Originally published at </em><a href="https://techsupportallbugs.wordpress.com/2018/06/05/using-git-with-colab-via-ssh/"><em>techsupportallbugs.wordpress.com</em></a><em> on June 5, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=175e8f3751ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/using-git-with-colab-via-ssh-175e8f3751ec">From Git to Colab, via SSH</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[Install LightGBM on Mac OSX 10.9]]></title>
            <link>https://medium.com/@m.chellaa/install-lightgbm-on-mac-osx-10-9-9524a475ac0d?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9524a475ac0d</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[homebrew]]></category>
            <category><![CDATA[mac]]></category>
            <category><![CDATA[mac-osx]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Sat, 26 May 2018 16:18:58 GMT</pubDate>
            <atom:updated>2018-12-09T05:50:58.774Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/554/0*Q1DUD6HIeksecpPq" /></figure><p>I am documenting the tiring process of installing LightGBM on my ancient Mac with OSX 10.9. From OSX 10.8 onwards, the GCC that comes shipped with is only a GCC front-end with LLVM backend. But LightGBM depends on OpenMP for compiling which is not supported by Apple Clang. So we need to install GCC on the machine. We can install GCC-7 by following the steps below, using the package manager Homebrew:</p><blockquote>brew install gcc@7 –without-multilib</blockquote><p>This installs gcc-7 on the system but the default version is still the Apple Clang compiler. If you want to set this version as the default then we need to do the following:</p><p>Edit the ~/.bash_profile to include the gcc directory to the PATH variable.</p><blockquote>export PATH=/usr/local/bin:$PATH</blockquote><p>But typing the which gcc command still points to /usr/bin/ which is the path for the clang compiler. So if we want to use gcc to invoke the compiler we have to create a symbolic link in addition. But before that we need to save the system’s clang version in some other name.</p><blockquote>cd /usr/bin</blockquote><blockquote>sudo mv gcc orig_gcc_mavs</blockquote><blockquote>cd /usr/local/bin</blockquote><blockquote>sudo ln -s gcc-7 gcc</blockquote><blockquote>sudo ln -s g++-7 gcc</blockquote><p>You can find the other options for using the installed gcc compiler and the system’s clang in <a href="https://stackoverflow.com/questions/28970935/osx-replace-gcc-version-4-2-1-with-4-9-installed-via-homebrew/28982564#28982564">this stackoverflow post</a>.</p><p>Now we can install LightGBM by following the instructions given <a href="https://github.com/Microsoft/LightGBM/blob/master/docs/Installation-Guide.rst#macos">here</a> and reproduced below for ease:</p><blockquote>git clone –recursive <a href="https://github.com/Microsoft/LightGBM">https://github.com/Microsoft/LightGBM</a> ; cd LightGBM</blockquote><blockquote>export CXX=g++-7 CC=gcc-7</blockquote><blockquote>mkdir build; cd build</blockquote><blockquote>cmake ..</blockquote><blockquote>make -j4</blockquote><p>and then</p><blockquote>pip3 install –no-binary :all: lightgbm</blockquote><p>Check if the installation was successful by opening a python interpreter and typing <em>import lightgbm</em>.</p><p>You can un-install LightGBM by simply typing the following:</p><blockquote>pip3 uninstall lightgbm</blockquote><p>Other useful references:</p><ol><li><a href="https://github.com/Microsoft/LightGBM/issues/1369">https://github.com/Microsoft/LightGBM/issues/1369</a></li><li><a href="https://apple.stackexchange.com/questions/99077/how-to-set-gcc-4-8-as-default-gcc-compiler/99157#99157">https://apple.stackexchange.com/questions/99077/how-to-set-gcc-4-8-as-default-gcc-compiler/99157#99157</a></li><li><a href="https://github.com/Microsoft/LightGBM/issues/710">https://github.com/Microsoft/LightGBM/issues/710</a></li><li><a href="https://github.com/Microsoft/LightGBM/issues/118">https://github.com/Microsoft/LightGBM/issues/118</a></li></ol><p><em>Originally published at </em><a href="https://techsupportallbugs.wordpress.com/2018/05/26/install-lightgbm-on-mac-osx-10-9/"><em>techsupportallbugs.wordpress.com</em></a><em> on May 26, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9524a475ac0d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setting up GPU & Installing CUDA on Google Cloud]]></title>
            <link>https://medium.com/@m.chellaa/setting-up-gpu-installing-cuda-on-google-cloud-ae9731a5cdad?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae9731a5cdad</guid>
            <category><![CDATA[gpu]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[cuda]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Mon, 12 Mar 2018 07:13:08 GMT</pubDate>
            <atom:updated>2018-12-09T05:46:35.520Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/578/0*qyJqxMlGjmZqJN4m" /></figure><p>This post assumes that you are familiar with using Google Cloud and that you already have created a VM. Now many times you can be well off using the multi-core CPU setup on GCloud. But for several machine learning and deep learning applications GPU support is mandatory. The purpose of this post is to help you set up GPUs on your GCloud VM and install CUDA on it.</p><h3>Setting up GPU on your Google Cloud VM:</h3><ul><li>On the <strong>Compute Engine</strong> page of Google Cloud (the page where you see the VM instances of your project), from the left side panel, choose <strong>Quotas</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/0*0sFrlcVM-JQjUF3-" /></figure><ul><li>On the next page you get to see this message below. Click on the <strong>IAM &amp; Admin Quotas page</strong> link.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/0*eW6qu0DP_h-lxkrS" /></figure><ul><li>In the <strong>Quotas</strong> page of IAM, select the <strong>Region</strong> as the region of your VM.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/0*20LwTdvoYlfW5Sh8" /></figure><ul><li>Then you can see the available GPUs in your region in the available <strong>Services</strong> below.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/0*x71ocSWdm9URiQxE" /></figure><ul><li>Select the type of GPU you need and click on the <strong>Edit Quotas</strong> button at the top of the page.</li><li>A short form appears on the right side panel, where you need to enter your name, email and phone number and click on <strong>Next</strong>.</li><li>In the next screen, you need to enter the <strong>Quota Limit</strong> (the number of GPUs you require) and a description of why you need them (like a short description of your project-what you will be using the GPU for) and click on <strong>Submit Request</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/366/0*ZROYUMURDU4ybFJG" /></figure><ul><li>You will receive an email from <strong>Google Compute Engine Quota Support</strong>, with the subject like <strong>“Quota Increase Request For &lt;your project name&gt;”</strong>. In this email they tell you to pay upfront an amount of $35 USD (at the time I wrote this post) and then reply to the mail once the payment clears through. You can make a manual payment by following the instructions <a href="https://cloud.google.com/billing/docs/how-to/manual-payment?visit_id=1-636564333758839498-2981741044&amp;rd=1">here</a>.</li><li>After making the payment, reply to the email by specifying the transaction id or by attaching a screenshot of the payment confirmation email that you received after making the $35 USD payment.</li><li>After this you will further receive intimations from the Quota Support people telling you that your quota of GPU has been increased.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/0*7SqiDTcm94N7SaE5" /></figure><h3>Installing CUDA on your GCloud VM:</h3><ul><li>Installing CUDA on Google Cloud is extremely simple unlike doing it on your individual OS installs.</li><li>First create a <strong>install_cuda.sh</strong> script on your VM by typing</li></ul><blockquote>nano install_cuda.sh</blockquote><ul><li>Now copy and paste the following lines of command into the script. (This script is taken from the Google Cloud Documentation <a href="https://cloud.google.com/compute/docs/gpus/add-gpus#install-driver-script">here</a>).</li></ul><blockquote><em>#!/bin/bash<br> echo “Checking for CUDA and installing.”<br> # Check for CUDA and try to install.<br> if ! dpkg-query -W cuda-8–0; then<br> # The 16.04 installer works with 16.10.<br> curl -O </em><a href="https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb"><em>https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb</em></a><em><br> dpkg -i ./cuda-repo-ubuntu1604_8.0.61–1_amd64.deb<br> apt-get update<br> apt-get install cuda-8–0 -y<br> fi<br> # Enable persistence mode<br> nvidia-smi -pm 1</em></blockquote><ul><li>Run the script by typing</li></ul><blockquote>sudo bash install_cuda.sh</blockquote><ul><li>Now open the bash profile script and add the following line for the PATH environmental variable</li></ul><blockquote>nano ~/.profile</blockquote><blockquote>export PATH=$PATH:/usr/local/cuda-8.0/bin</blockquote><blockquote>export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH</blockquote><ul><li>Now verify that the drivers are all installed by typing the following commands</li></ul><blockquote>nvidia-smi</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*E3xbfKy8VJD2N82N" /></figure><blockquote>nvcc –version</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/0*EbttRJRhWIky3Suz" /></figure><p>That’s it! You have successfully requisitioned GPU for your Google Cloud instance and installed CUDA on it.</p><h3>Making Kaldi work with CUDA:</h3><p>Since I installed CUDA mainly to run the Kaldi DNN scripts, I would like to provide the last puzzle piece that will make kaldi use the CUDA compiler. After doing all of the above steps, before running the DNN scripts in Kaldi do the following:</p><blockquote>cd ~/kaldi/src</blockquote><blockquote>./configure –shared</blockquote><blockquote>make depend</blockquote><blockquote>make</blockquote><p><em>(NVIDIA-CUDA Image Copyrights belongs to NVIDIA)</em></p><p><em>Originally published at </em><a href="https://techsupportallbugs.wordpress.com/2018/03/12/setting-up-gpu-installing-cuda-on-google-cloud/"><em>techsupportallbugs.wordpress.com</em></a><em> on March 12, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae9731a5cdad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install Kaldi (ASR) on Ubuntu]]></title>
            <link>https://medium.com/@m.chellaa/install-kaldi-asr-on-ubuntu-830418a800b5?source=rss-465e2a8d715c------2</link>
            <guid isPermaLink="false">https://medium.com/p/830418a800b5</guid>
            <category><![CDATA[rsa]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <category><![CDATA[kaldi]]></category>
            <category><![CDATA[ubuntu]]></category>
            <dc:creator><![CDATA[Chella Priyadharshini]]></dc:creator>
            <pubDate>Wed, 28 Feb 2018 16:40:20 GMT</pubDate>
            <atom:updated>2018-12-09T05:31:26.968Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/945/0*qbI15In_UIOZXQ-A" /></figure><p>This is going to be a concise post giving just the exact steps to install Kaldi on a fresh instance of Ubuntu 16.0.4 LTS:</p><p>Installing Necessary Packages:</p><ul><li>sudo apt-get update</li><li>sudo apt-get upgrade</li><li>sudo apt-get install git</li><li>sudo apt-get install bc</li><li>sudo apt-get install g++</li><li>sudo apt-get install zlib1g-dev make automake autoconf bzip2 libtool subversion</li><li>sudo apt-get install libatlas3-base</li></ul><p>Install Kaldi:</p><ul><li>git clone <a href="https://github.com/kaldi-asr/kaldi.git">https://github.com/kaldi-asr/kaldi.git</a> kaldi –origin upstream</li><li>cd kaldi/tools</li><li>extras/check_dependencies.sh</li><li>make</li><li>To install the irst language model:</li><li>cd kaldi/src</li><li>./configure –shared</li><li>make depend</li><li>make</li><li>Inorder to install the language model kaldi_lm:</li><li>cd kaldi/tools</li><li>extras/install_kaldi_lm.sh</li></ul><p>(Image Copyrights belong to kaldi-asr.org)</p><p><em>Originally published at </em><a href="https://techsupportallbugs.wordpress.com/2018/02/28/install-kaldi-asr-on-ubuntu/"><em>techsupportallbugs.wordpress.com</em></a><em> on February 28, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=830418a800b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>