<?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 Ankita Das on Medium]]></title>
        <description><![CDATA[Stories by Ankita Das on Medium]]></description>
        <link>https://medium.com/@ad2013?source=rss-909b99cc1cf3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KnQU45YpDrwN926s8IZShg.jpeg</url>
            <title>Stories by Ankita Das on Medium</title>
            <link>https://medium.com/@ad2013?source=rss-909b99cc1cf3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 08:05:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ad2013/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[Generating TV Scripts with LSTM]]></title>
            <link>https://medium.com/data-science/generating-tv-scripts-with-lstm-e94be65a179?source=rss-909b99cc1cf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e94be65a179</guid>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[udacity-nanodegree]]></category>
            <category><![CDATA[lstm]]></category>
            <dc:creator><![CDATA[Ankita Das]]></dc:creator>
            <pubDate>Sat, 22 Aug 2020 17:44:22 GMT</pubDate>
            <atom:updated>2020-08-22T17:44:22.891Z</atom:updated>
            <content:encoded><![CDATA[<h4>A beginner project with LSTMs</h4><p>Hello friends, I just completed this project as a part of the Deep Learning Nanodegree at Udacity.</p><p>The project is about predicting the next word in the script, given the previous context using LSTM.</p><p>I’ll be explaining the major and the very basic concepts that will be required while doing the project. The sections which I’ve covered include:</p><p><strong>How our data can be transformed into a form that the model can work with?</strong></p><ul><li>Preprocessing the data</li><li>Batching the data</li></ul><p><strong>How the model architecture works with the batched data, passing it from one layer to the other and how it finally leads to predicting the next word in the sequence.</strong></p><h3>Targeted Audience and Prerequisites</h3><p>This is a fundamental project done with LSTM, anyone having basic knowledge about neural networks and RNNs can easily understand this. I have tried breaking the project down to the very basic details as simply as possible.</p><p>I have put a good amount of focus on the model architecture, the input shapes, output shapes, and parameters that each layer considers. I have compiled and explained what each of these input/output shapes mean and why they are shaped in a particular way, for you to visualize better.</p><p>Note: The project has been coded in Pytorch. However, there is not much difference in the parameters that the LSTM model layers consider. So, anyone trying to do it in Keras too can refer to my explanation.</p><p><strong>What I have not covered?</strong></p><p>The theoretical details of what an LSTM is, or why it works though I’ve touched a part of why it works better than Neural Networks for this case.I have attached a link to the main project, but I haven’t explained the whole of it line by line.</p><p>However, I have covered the parts that I felt would be sufficient for understanding the main working so that you can generalize the concept to use it for other similar projects.</p><h3>Let’s jump right in 🐬</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2UlTmdofZSzH6QyM" /><figcaption>Photo by <a href="https://unsplash.com/@wilhelmgunkel?utm_source=medium&amp;utm_medium=referral">Wilhelm Gunkel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Text preprocessing</h3><p>We have the text, we first batch the data in a form that it can be fed into the LSTM.</p><p>An important part of which is Text preprocessing, we have applied a few very basic <em>necessary but not sufficient</em> preprocessing to the text:</p><ol><li>Lower-casing the text</li><li>Tokenizing the text: A step that splits longer strings of text<strong> </strong>into smaller pieces, or tokens.</li><li>Tokenizing the punctuations i.e. replacing “great!” by a “great”, “|| exclamation ||” so that “great!” and “great” are not considered as different words.</li><li>Creating two lookup tables mapping words to integers(because a neural network understands the language of numbers only) and vice versa.</li></ol><p>Some other text processing techniques might be Stemming, lemmatization. <a href="https://www.kdnuggets.com/2017/12/general-approach-preprocessing-text-data.html"><em>This</em></a> is a good read on text processing.</p><p>After having preprocessed the text and converted it to integers, the text data is batched in a way that LSTM can consider it as an input.</p><p>Now before moving further, a very basic yet important question:</p><h4>Why RNN/LSTM and not a normal neural network?</h4><p>The two most important terms in RNN/ LSTMs are recurrent units and hidden units. Both of which play a part in considering the context of the text. For example, if you join a discussion in between it is difficult for you to converse, you need to know the context of the discussion before you say something. That is made possible with the help of hidden units, the hidden units carry forward the information from the previous context, so the LSTM/RNN unit considers 2 inputs: the input word and the hidden unit.</p><p>The normal neural network could have worked as well, but it will work in a way without considering the previous context, just giving the probability of the occurrence of a word as the next word, given the previous word.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9qZIup2xv1V8KxBm5pzOHg.jpeg" /><figcaption>Input batch:[What,are,you,thinking] Target: [‘asked’] (Image by Author)</figcaption></figure><p>In the image above “h” is the hidden unit, “o” denotes output from each LSTM unit, the final output is matched for similarity with the target.</p><h3>Batching with an example:</h3><p>Let’s consider a piece of text, this is an extract from quora:</p><blockquote>“ “What are you thinking?” asked the boss. “We didn’t ask anyone any question here. By asking a few questions we won’t be able to assess the skills of anyone. So our test was to assess the attitude of the person. We kept certain tests based on the behavior of the candidates and we observed everyone through CCTV.”</blockquote><p>After selecting a suitable sequence length and batch size, 4 &amp; 3 here respectively, an input to the <strong>LSTM </strong>cells looks like as follows (I am ignoring punctuations here):</p><blockquote>First batch:</blockquote><blockquote>[what, are, you,thinking] -&gt; [asked]</blockquote><blockquote>[are, you, thinking,asked] -&gt; [the]</blockquote><blockquote>[you, thinking, asked, the] -&gt;[boss]</blockquote><blockquote>Second batch:</blockquote><blockquote>[thinking,asked,the,boss] -&gt; [we]</blockquote><blockquote>[asked,the,boss,we] -&gt; [didnt]</blockquote><blockquote>[the,boss,we,didnt] -&gt; [ask]</blockquote><p>Of course, converted to <em>integers</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c_x8532G_Ki_aCVw" /><figcaption>Batching (Photo by <a href="https://unsplash.com/@jannerboy62?utm_source=medium&amp;utm_medium=referral">Nick Fewings</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a>)</figcaption></figure><p>If instead, we would have used a normal<strong> Neural Network</strong>, the batches would have looked something similar to this (batch size: 3):</p><blockquote>First batch:</blockquote><blockquote>[what] -&gt; [are]</blockquote><blockquote>[are] -&gt; [you]</blockquote><blockquote>[thinking] -&gt; [about]</blockquote><p>So that it’s quite clear that the Neural Network does not consider the previous context.</p><h3>Model Architecture and Working:</h3><p>Coming on to how these batches are processed by the LSTMs.</p><blockquote>Note:</blockquote><blockquote>Below is a picture of the architecture of our model with the parameters</blockquote><blockquote>Batch_size:2 ,sequence_len:3, embedding_dim:15 ,output_size=vocab_size:20, hidden_dim:10</blockquote><blockquote>Please refer to it for better understanding of the architecture, I have used smaller numbers for the ease of representation.</blockquote><h4>1.The Embedding Layer</h4><p>So if these <em>integers </em>(words mapped to integers in the vocab_to_int dictionary) are passed into the LSTM unit it might uncover a biased meaning thinking of these integers as some weights, in order to avoid this problem we sometimes <em>one-hot encode</em> these integers. But, when the vocabulary dictionary is large, the encodings take up a lot of unnecessary space.</p><blockquote>Suppose vocab dictionary size=3</blockquote><blockquote>The vectors occupy a space of 3*3 cell size i.e. 9</blockquote><blockquote>[1,0,0]</blockquote><blockquote>[0,1,0]</blockquote><blockquote>[0,0,1]</blockquote><p>Now imagine this for a vocabulary size of 10000. That would mean a 10¹⁰ cell size of space.</p><p>Therefore comes the concept of <strong><em>Embedding Layer</em></strong>.</p><p>Instead of replacing these words by one-hot encodings, this time we replace it with some fixed-length vectors filled with a random choice of numbers. This matrix of values gets trained along with the model over time and learns a close vector representation of the words, which can help add meaning to them and help in increasing the overall accuracy.</p><p>The torch.nn.Embedding layer takes in the parameters:</p><ul><li><em>num_embeddings </em>(size of the dictionary ) which is equal to the<em> vocab_size</em></li><li><em>embedding_dim</em>(size of the embedding vectors used for the word representations)</li></ul><p>The input to this layer is shaped as <em>(batch_size,seq_length) </em>and<em> </em>output from this layer is of shape <em>(batch_size,seq_length,embedding_dim).</em></p><p><em>For a vocab size of 25000, the embedding vector of 300 works well which is considerably smaller than each vector size of 25000 in case of one-hot encoded vectors.</em></p><p>Some pre-trained word representations models like fastText, GloVe are available and can be directly used instead of generating these representations with the Embedding Layer.</p><h4>2.The LSTM layer</h4><p>The <a href="https://pytorch.org/docs/stable/generated/torch.nn.LSTM.html#torch.nn.LSTM">torch.nn.LSTM</a> expects the parameters <em>input_size,hidden_dim, num_layers</em>. <em>Input_size &amp; hidden_dim</em> are the number of features in the input and hidden state respectively.</p><p><em>Note: For someone who is familiar with CNN&#39;s can relate to it as input_size as the </em><strong><em>in_channels</em></strong><em> and hidden_dim as </em><strong><em>out_channels</em></strong><em> of the CNN layer.</em></p><p>Since we have used an embedding layer, the embedding vector length is the number of input features.Therefore, <em>input_size</em> = <em>embedding_dim</em>.The parameters <em>hidden_dim</em> and <em>num_layers</em>(number of layers of the LSTM, generally has a value 1 or 2) can be chosen arbitrarily.</p><p>The nn.LSTM layer returns an output and a hidden state, the output has the shape <em>(batch_size,sequence_length,hidden_dim).</em></p><h4>3.The Linear layer</h4><p>This output is <strong>reshaped </strong>to <em>(batch_size*sequence_length , hidden_dim)</em> and passed on to the Linear Layer with <em>in_features = hidden_dim</em> and <em>out_features = output_size</em> .</p><p>In our case,<em> output_size = vocabulary size</em>, i.e. the number of output nodes is equal to the total number of words present in the vocabulary, so that the network can choose the most probable next word from the whole vocabulary of words.</p><p>The output from the Linear layer is shaped as <em>(batch_size*sequence_length,output_size)</em> which is further <strong>reshaped</strong> to have a shape <em>(batch_size,sequence_length,output_size)</em> and though we train the model on the whole corpus for predicting the <em>next word for </em><strong><em>every</em></strong><em> word </em>of the sequence, we need only <em>the next word after the </em><strong><em>last</em></strong><em> word</em> of the sequence, so the returned output from our model considers just that.</p><p>Thus the final output layer is shaped as <em>(batch_size,output_size)</em>.</p><p>The output from our model gives us the most probable next word for each sequence for the given batch. 💁</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*7SoGu4SGqpH0cPgmy17OIA.jpeg" /><figcaption>Example Architecture with Batch_size:2 ,sequence_len:3, embedding_dim:15 ,output_size=vocab_size:20, hidden_dim:10 (Image by Author)C</figcaption></figure><h4>CODE:</h4><p>The full code for this project can be found here:</p><p><a href="https://github.com/Ankita-Das/Deep-Learning-Nanodegree/blob/master/TV_script_generation/dlnd_tv_script_generation_copy.ipynb">Ankita-Das/Deep-Learning-Nanodegree</a></p><h4>Try this out! 💻</h4><p>I have tried to cover all the important and necessary concepts for doing this project, yet if you face difficulty anywhere and if you feel I have missed a point, do let me know in the comments below.</p><p>I’ll be eagerly waiting to see you’ll complete this project. 🙌</p><p>Best Wishes.</p><p>Adieu 😁</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GNxOyOc4hWGpMOHe" /><figcaption>Photo by <a href="https://unsplash.com/@jupp?utm_source=medium&amp;utm_medium=referral">Jonathan Kemper</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e94be65a179" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/generating-tv-scripts-with-lstm-e94be65a179">Generating TV Scripts with LSTM</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[Mistakes I made while beginning my Data science journey: My story of learning to Learn.]]></title>
            <link>https://medium.com/@ad2013/mistakes-i-made-while-beginning-my-data-science-journey-my-story-of-learning-to-learn-f1c009df7f56?source=rss-909b99cc1cf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1c009df7f56</guid>
            <category><![CDATA[journey]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[lessons-learned]]></category>
            <dc:creator><![CDATA[Ankita Das]]></dc:creator>
            <pubDate>Fri, 05 Jun 2020 05:03:35 GMT</pubDate>
            <atom:updated>2020-06-05T05:03:35.195Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey guys, I am Ankita Das, a final year undergraduate of Computer Science and a Deep Learning Enthusiast.</p><p>I started with Machine Learning 2 years back. I remember the day when the term “Machine Learning” had first crossed my ears, it was in my second year. The term Machine Learning was a little misleading though because I had pictured it consisting of robots/machines, I couldn’t relate how it intersected with Computer Science.</p><p>I returned home and started searching for this term, then while doing so I came across the term “Artificial Intelligence”, now this explained better, I looked at the wonders that it could perform and back then it all sounded like magic.</p><p>And quite naturally while searching for all this, I stumbled upon the course “Machine Learning by Andrew Ng.” so I consulted with a senior and started the course, the course was really good, Andrew Ng is an excellent instructor. I was excited and decided that I would do it no matter what, however hard it may seem. And I decided that to complete the course, that was my aim. But looking back, I know I went wrong, that was a big course with lots of algorithms and remembering all of them wasn’t necessary, I just needed to know how they worked given a dataset. Instead, I tried revising and learning all the algorithms, I waited for the course to complete to start a project.</p><p>After that when I started a project I decided to code the algorithms from scratch so that I understand it well. I wasn’t completely wrong because, that did give a better understanding of the algorithms but, of course, my algorithms didn’t work very well. I have always had this urge of trying to code everything from scratch, but I have wasted a lot of time, energy trying to do so. How it(the algorithms) can be worked with the part is easy but, trying to code it from scratch needs some real amount of study and research.</p><p>And I am not asking you to completely throw away this idea of learning everything in depth, I just know now that everything has a time. We should keep small stepping stones, otherwise, there’s a good chance that we might get frustrated and end up declining to do what we had started with.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x8Rk5oekeQrjxp33rfs_wA.jpeg" /></figure><p>I feel a good way to learn is to fix time slot for whatever you’re starting to learn, keep a wider slot for whatever you want to learn in-depth, keep trying until the time isn’t over, after that you must leave it even if temporarily and if you need to use it for a project(so that you can’t completely throw that away) just try to learn how to use it(for the time being), I’m sure that won’t be as hard(most of the time we are to use functions from the frameworks like Keras, PyTorch).</p><p>I am still in my journey of learning to learn. I’ll keep sharing, my experiences my story might be helpful to some of my beginner friends.</p><p>And for those of you still would want to learn in-depth, I’d suggest you do the same as a good friend of mine suggested me to do: Do something (maybe writing an article, making a video, share your knowledge online) so that whatever you learn doesn’t go to waste.</p><p><em>A small piece of advice from me would be to:</em></p><p><em>Start it, do it. You cannot jump to a mountain top, you have to take small steps, and with consistency and hard work, you’ll make it to the top.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1c009df7f56" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>