<?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 Mandar Deshpande on Medium]]></title>
        <description><![CDATA[Stories by Mandar Deshpande on Medium]]></description>
        <link>https://medium.com/@razzormandar?source=rss-d08a98ebec56------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3wtisulz173E0hk6ncHP1A.jpeg</url>
            <title>Stories by Mandar Deshpande on Medium</title>
            <link>https://medium.com/@razzormandar?source=rss-d08a98ebec56------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:04:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@razzormandar/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[The Transformer: A Quick Run Through]]></title>
            <link>https://medium.com/data-science/the-transformer-a-quick-run-through-ce9b21b4f3ed?source=rss-d08a98ebec56------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce9b21b4f3ed</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-translation]]></category>
            <dc:creator><![CDATA[Mandar Deshpande]]></dc:creator>
            <pubDate>Sat, 02 May 2020 17:11:33 GMT</pubDate>
            <atom:updated>2020-05-03T23:04:44.023Z</atom:updated>
            <content:encoded><![CDATA[<h4>Explore the best of natural language modeling enabled by the Transformer. Understand its architecture and internal working.</h4><blockquote>This is Part 3 of the <a href="https://towardsdatascience.com/language-modelingii-ulmfit-and-elmo-d66e96ed754f?source=friends_link&amp;sk=8419eea77e21bb3f93b91a0f6447ca92">5 part series</a> on language modeling.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nH_g5TTDBEs79y2M0lk6Fg.png" /><figcaption>Seq2seq task of machine translation solved using Transformer-like architecture (BERT) (<a href="https://translate.google.com/?hl=en&amp;tab=TT">translate.google.com</a>)</figcaption></figure><h3>Introduction</h3><p>In the<a href="https://medium.com/p/d66e96ed754f"> previous post</a>, we looked at how ELMo and ULMFiT boosted the prominence of language model pre-training in the community. This blog assumes that you have read through the <a href="https://medium.com/p/d66e96ed754f">previous two parts</a> of this series and thus builds upon that knowledge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*jA32Yzo7dXRDIWXhBMBy6A.png" /><figcaption>English input being translated to German output using the Transformer model <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><p><a href="https://arxiv.org/pdf/1706.03762.pdf">The Transformer</a> has been seen as the model which finally removed the limitations of sequence model training through recurrent neural networks. The idea picked up in language modeling and machine translation around the use of encoder-decoder stacking turned out to be valuable learning in the process of building this architecture. The Transformer is a simple network architecture solely based on attention mechanism and giving away any kind of recurrence and convolutions entirely. It has been shown to generalize well to other language understanding and modeling tasks, with large and limited training data. It also achieved the state of the art results on the English-to-German translation task and anchored itself as the go-to architecture for future advancements in model pre-training in NLP.</p><h4>Encoder-Decoder Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*AOQlFGXhx_ojDcEX1stg2g.png" /><figcaption>The 6 encoder-decoder architecture used in the Transformer <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><p>In this model, multiple encoders are stacked on top of each other, and similarly, decoders are stacked together. Usually, each encoder/decoder comprises recurrent connections and convolution, and the hidden representation from each encoder stage is passed ahead to be used by the next layer. Most seq2seq tasks can easily be solved using such a stack of encoders-decoders which processes each word in the input sequence in order.</p><h4>Attention Mechanism</h4><p>Since attention mechanism has become an integral part of sequence modeling and transduction models in various tasks allow modeling dependencies without regard to their distance in the input or output sequences. To put it in simple terms; the attention mechanism helps us tackle long-range dependency issues in neural networks without the use of recurrent neural networks (RNN). This solves the exact purpose addressed by hidden state shared across all time steps in RNN, through the use of encoder-decoder based architecture. The attention model focuses on the relevant part of the input text sequence or image as per the task being solved.</p><p>In a regular RNN, context is passed in terms of the final hidden state produced by the encoders and uses it to produce the next token of the translation or text.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*znX_iUkc3TVNplPN3ukUFQ.png" /><figcaption>Regular seq2seq models without Attention Mechanism only uses the last hidden state as the context vector <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><p><strong>Steps involved in generating the Context Vector:</strong></p><ol><li>Initialize the context vector of random values and size as per the task (eg 128, 256, 512)</li><li>Process one token from the input sequence through the encoder</li><li>Use the hidden state representation in the encoder to update the context vector</li><li>Keep repeating Step 2 and 3 until the entire input sequence is processed</li></ol><p>Once the context vector has been fully updated, it is passed to the decoder as an additional input to the word/token being translated. The <strong>context vector is a useful abstraction, except that it acts as a bottleneck for the representation </strong>of the entire meaning of the input sequence.</p><p>Instead of passing a single context vector to the decoder, the <strong>attention mechanism passes all the intermediate hidden states within a stack of encoders to the decoder</strong>. This enables the decoder to focus on different parts of the input sequence as per the relevance of the current word/token being processed.</p><p>Unlike the previous seq2seq models, attention models perform 2 extra steps:</p><ol><li><strong>More data is passed from the encoder to the decoder</strong></li><li><strong>The decoder in an attention model uses this additional data </strong>to focus on a particular word from the input sequence and <strong>uses the hidden state with the highest softmax score as the context vector</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*8W4HbTBuIYTtCBFyn8q1Rw.png" /><figcaption>Attention Mechanism used to create the context vector passed to the decoder <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><h4>Peek Inside the Transformer</h4><p>The Transformer consists of 6 stacked encoders and 6 stacked decoders to form the main architecture of the model. This number can be variable as per the use-case, but 6 has been used in the <a href="https://arxiv.org/pdf/1706.03762.pdf">original paper</a>.</p><p>Let us consider a single encoder and decoder stack to simplify our understanding of the working.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*8expO2YnpyCR18OgnnHSoA.png" /><figcaption>Components inside the Encoder and Decoder in the Transformer <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><h4>Architecture</h4><p>Each encoder consists of a Self-Attention layer followed by the Feed Forward network. Usually in attention mechanisms, hidden states from the previous states are utilized for the calculation of attention. Instead, self-attention uses trained embeddings from the same layer to compute the attention vector. To elucidate, self-attention could be thought of as a mechanism for coreference resolution within a sentence:</p><p>“The <strong>man</strong> was eating his meal while <strong>he</strong> was thinking about his family”</p><p>In the above sentence, the model needs to build an understanding of what he refers to, and that it is a coreference to the man.This is enabled by the self-attention mechanism in the Transformer. A detailed discussion on self-attention (using multiple heads) is beyond the scope of this blog and can be found in the original paper.</p><p>The decoder also has the same two layers as the encoder, except that additional encoder-decoder attention is introduced in between to help the model extract relevant features from attention vectors from the encoder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DSRCXsde9_8dvbxq5ktUnw.png" /><figcaption>Simplified 2 encoders stacked together with 2 decoders to explore internal architecture <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><p><strong>Point-wise Feed-Forward Networks<br></strong>It is important to notice that each word in the input sequence shares the computation in the self-attention layer, but each word flows through a separate feed-forward network. The output from the feed-forward network is passed on to the next encoder in the stack which utilizes this learned context from previous encoders.</p><p><strong>Positional Encoding<br></strong>To embed a sense of time in the input sequence, each word is concatenated with a positional encoding. This augmented input word embedding is passed as input to Encoder 1. Since the model doesn’t use any recurrence or convolution, positional encodings encode some information about the relative position in the input sentence.</p><p><strong>Residual Connections with Normalization<br></strong>The output from the self-attention layer is added with the original word embedding using residual connections and layer normalization. A similar scheme is followed by the feed-forward layer.</p><p><strong>Fully Connected Linear with Softmax <br></strong>Once a point vector is given out by the final decoder in the stack, it needs to be converted into the translated word. Now that we already have all the required information embedded as floats in this output vector, we just need to convert it to a probability over possible next word in the translation.</p><p>The fully connected linear network converts the float vector into scores which are transformed into probability values using the softmax function. The index with the highest softmax value is chosen and retrieved from the output vocabulary learned from the training set.</p><h3>Transformer Training Explained</h3><p>The training is supervised i.e. uses labeled training dataset which can be used as a benchmark for comparison and correction of output word probabilities.</p><p>Essentially, each word in the translated output vocabulary is converted into a one-hot vector that is 1, only at the index where the word is present and 0 everywhere else. Now, once we receive the softmax output vector comprised of normalized probability values, we can compare it with the one-hot vectors to improve model parameters/weights.</p><p>These two vectors can be compared by using some similarity metrics like <strong>cosine similarity, cross-entropy, and/or Kullback-Leibler divergence</strong>. At the beginning of the training process, the output probability distribution is much further off than the ground truth one-hot vector. As training proceeds and the weights get optimized, the output word probabilities closely track the ground truth vectors.</p><p>I hope this blog helped you understand how the Transformer works, and I plan to explore the BERT model in the next post.</p><p><a href="https://towardsdatascience.com/language-modeling-c1cf7b983685">Link to Part I</a>: Language Modeling I<a href="https://towardsdatascience.com/language-modelingii-ulmfit-and-elmo-d66e96ed754f"><br>Link to Part II</a>: Language Modeling II: ELMo and ULMFiT<br><a href="https://towardsdatascience.com/the-transformer-a-quick-run-through-ce9b21b4f3ed">Link to Part III</a> : The Transformer: A Quick Run Through</p><p>Keep learning and growing till then!</p><p>Connect with me on Twitter: <a href="https://twitter.com/mandroid_6">https://twitter.com/mandroid_6</a></p><blockquote><em>All images above have been created by me and I have the rights to use them. I have taken inspiration from </em><a href="http://jalammar.github.io/"><em>Jay Alammar’s blog </em></a><em>for the visualizations</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce9b21b4f3ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/the-transformer-a-quick-run-through-ce9b21b4f3ed">The Transformer: A Quick Run Through</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[Language Modeling II: ULMFiT and ELMo]]></title>
            <link>https://medium.com/data-science/language-modelingii-ulmfit-and-elmo-d66e96ed754f?source=rss-d08a98ebec56------2</link>
            <guid isPermaLink="false">https://medium.com/p/d66e96ed754f</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Mandar Deshpande]]></dc:creator>
            <pubDate>Wed, 29 Apr 2020 02:20:14 GMT</pubDate>
            <atom:updated>2020-05-03T23:03:28.267Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This is Part 2 of the 5 part series on language modeling.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nCJtttoDKHtc-r46Ov034w.png" /><figcaption>Language models actively used in search engines</figcaption></figure><h3>Introduction</h3><p>In the previous <a href="https://towardsdatascience.com/language-modeling-c1cf7b983685">post</a>, we understood the concept of language modeling and the way it differs from regular pre-trained embeddings like word2vec and GloVe.</p><p>On our journey to towards REALM (Retrieval-Augmented Language Model Pre-Training), we will briefly walk through these seminal works on language models:</p><ol><li><a href="https://arxiv.org/abs/1802.05365"><strong>ELMo</strong></a><strong>:</strong> Embeddings from Language Models</li><li><a href="https://arxiv.org/abs/1801.06146"><strong>ULMFiT</strong></a><strong>: </strong>Universal Language Model Fine-Tuning method</li></ol><h3>ELMo: Embeddings from Language Models (2018)</h3><p>Pre-trained word embeddings like word2vec and GloVe are a crucial element in many neural language understanding models. If we stick to using GloVe embeddings for our language modeling task, then the word ‘major’ would have the same representation irrespective of whether it appeared in any context. <strong>Context plays a major role for humans to perceive what a said word means.</strong></p><p>Eg. ‘major: an army officer of high rank’ and ‘major: important, serious, or significant’ would have the same embedding for the word ‘major’ being used according to GloVe vectors.</p><p>The task of creating such high-quality representations is hard. To make it concrete, any word representation should model:</p><ol><li><strong>Syntax and Semantics:</strong> complex characteristics of word use</li><li><strong>Polysemy</strong>: the coexistence of many possible meanings for a word or phrase across linguistics contexts</li></ol><p>ELMo introduces a <strong>deep contextualized word representation</strong> that tackles the tasks we defined above while still being easy to integrate into existing models. This achieved the state of the art results on a range of demanding language understanding problems like question answering, NER, Coref, and SNLI.</p><p><strong>Contextualized word embeddings<br></strong>Representations that capture both the word meaning along with the information available in the context are referred to as contextual embeddings. Unlike word2vec or GloVe which utilizes a static word representation, ELMo utilizes bi-directional LSTM for specific tasks to look at the whole sentence before encoding a word.</p><p>Much like we observed in the [previous article](insert link), ELMo’s LSTM is trained on an enormous text dataset (in the same language as our downstream task). Once this <a href="https://towardsdatascience.com/language-modeling-c1cf7b983685">pre-training</a> has been done, we can reuse these distilled word embeddings as a building block for another language or NLP task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VDcfDSx8YdkngET38sSvXA.png" /><figcaption>Unrolled Forward Language Model used in ELMo <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><p><strong>How do we train the model on this huge dataset?<br></strong>We simply train our model to predict the next word given a sequence words i.e. language modeling itself. Furthermore, we can easily do this because we already have this dataset without needing explicit labels as needed in other supervised learning tasks.</p><p><strong>ELMo Architecture<br></strong>Consisting of one forward and one backward language model, ELMo’s hidden states have access to both the next word and the previous world. Each hidden layer is a bidirectional LSTM, such that its language model can view hidden states from either direction. You can look at the figure above to understand how this LSTM has access to other hidden states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MrVUve0VaUGgOFWQBuSEvw.png" /><figcaption>Hidden Layer Concatenation and Summation for (kth) token specific embedding in ELMo (<a href="https://www.linkedin.com/in/mandardeshpande1995/">Mandar Deshpande)</a></figcaption></figure><p>Once the forward and backward language models have trained, ELMo concatenates the hidden layer weights together into a single embedding. Furthermore, each such weight concatenation is multiplied with a weight based on the task being solved.</p><p>As you can see above ELMo takes a summation of these concatenated embeddings and assigns it to a particular token being processed from the input text. ELMo represents a token t_k as a linear combination of corresponding hidden layers (including its embedding). This means that <strong>each token in the input text has a personalized embedding being assigned by ELMo.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qvkmjcoZQ8qILtVELfuRfA.png" /><figcaption>Integrating EMLo into other NLP tasks by concatenation to embeddings <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><p>Once ELMo’s biLMs (bi-directional language models) have been trained on a huge text corpus, it can be integrated into almost all neural NLP tasks with simple concatenation to the embedding layer.</p><p>The higher layers seem to learn semantics while the lower layer probably captures syntactic features. Additionally, ELMo-enhanced models can make use of small datasets more efficiently.</p><p>You can read more about ELMo <a href="https://arxiv.org/abs/1802.05365">here</a>.</p><h3>ULMFiT (2018)</h3><p>Before ULMFiT, inductive transfer learning was widely being used in computer vision, but existing approaches in NLP still required task-specific modifications and training from scratch. ULMFiT proposed an effective transfer learning method that can be applied to any NLP task and further demonstrated techniques that are key to fine-tuning a language model.</p><p>Instead of random initialization of model parameters, we can reap the benefits of pre-training and speed up the learning process.</p><p>Regular LSTM units are used for the 3 layer architecture of ULMFiT, taking a cue from <a href="https://arxiv.org/pdf/1708.02182.pdf">AWD-LSTM</a>.</p><p>The <strong>three stages</strong> of ULMFiT comprise of:</p><ol><li><strong>General Domain LM Pre-Training:</strong> The language model is trained on a general-domain corpus to capture general features of language in different layers</li><li><strong>Target task Discriminative Fine-Tuning: </strong>The trained language model is fine-tuned on a target task dataset using <em>discriminative fine-tuning</em> and learning rate schedules (slanted triangular learning rate) to learn task-specific features</li><li><strong>Target task Classifier Fine-Tuning: </strong>Fine-tuning the classifier on the target task using <em>gradual unfreezing</em> and repeating stage 2. This helps the network to preserve low-level representations and adapt to high-level ones.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FsUjFMzusadyNmCfr3AS1w.png" /><figcaption>Three Stages of ULMFiT <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><p>As we can see above Stage 1 uses the same learning rate across all layers, whereas Stage 2 and 3 have layer-wise triangular learning rate schedules. Also, note how the layer weights are gradually reaching the optimal values across the three-stage process. (the darker color is optimal for representation purposes)</p><p><strong>Discriminative fine-tuning </strong>(learning schedule for stage 2/3 with slanted triangular learning rate)<strong> </strong>is a major revelation of this paper as it draws from the intuition that different layers in a model capture different types of features. Therefore it makes sense to have different learning rates for each of them. Like computer vision, even in language modeling tasks, the initial layers capture the most general information about the language, and hence once pre-trained would require the lowest amount of fine-tuning.</p><p>After Stage 2 of the process, the model is already very close to the optimal weights needed for the specified task, hence target task classifier fine-tuning is said to be very sensitive. If the fine-tuning process changes the weights significantly at this stage, then all the benefits of model pre-training would be lost. To take care of this issue, <strong>gradual unfreezing</strong> is proposed in the paper:</p><ul><li>To start, the last LSTM layer is unfrozen and model is fine-tuned just for one epoch</li><li>Next, layer before the last is unfrozen and fine-tuned</li><li>A similar process is repeated for each layer until convergence</li></ul><p>You can read the paper <a href="https://arxiv.org/abs/1801.06146"><strong>here</strong></a><strong>.</strong></p><p>Hopefully, this blog was useful for you to build a basic understanding of this exciting field of pre-trained language models!</p><p>In the next blog, we will be discussing Transformers and BERT for learning fine-tunable pre-trained models.</p><p><a href="https://towardsdatascience.com/language-modeling-c1cf7b983685">Link to Part I</a>: Language Modeling I<a href="https://towardsdatascience.com/language-modelingii-ulmfit-and-elmo-d66e96ed754f"><br>Link to Part II</a>: Language Modeling II: ELMo and ULMFiT<br><a href="https://towardsdatascience.com/the-transformer-a-quick-run-through-ce9b21b4f3ed">Link to Part III</a> : The Transformer: A Quick Run Through</p><p>Keep learning and growing till then!</p><p>Connect with me on Twitter: <a href="https://twitter.com/mandroid_6">https://twitter.com/mandroid_6</a></p><blockquote><em>All images above have been created by me and I have the rights to use them</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d66e96ed754f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/language-modelingii-ulmfit-and-elmo-d66e96ed754f">Language Modeling II: ULMFiT and ELMo</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[Language Modeling]]></title>
            <link>https://medium.com/data-science/language-modeling-c1cf7b983685?source=rss-d08a98ebec56------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1cf7b983685</guid>
            <dc:creator><![CDATA[Mandar Deshpande]]></dc:creator>
            <pubDate>Fri, 24 Apr 2020 20:53:02 GMT</pubDate>
            <atom:updated>2020-05-03T23:03:00.471Z</atom:updated>
            <content:encoded><![CDATA[<h3>Language Modeling — I</h3><blockquote>This is Part 1 of the <a href="https://link.medium.com/ITCbLzQL55">5 part series</a> on language modeling.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jb1fPBc4bbFSiOnMD4MBVw.png" /><figcaption>Next word prediction using language modeling in keyboards<a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><h3>Introduction</h3><p>As you might have guessed by now, language modeling is a use-case employed by us daily, and still, its a complicated concept to grasp. REALM (Retrieval-Augmented Language Model Pre-Training) is the latest addition to the growing research in this domain. It is a great step ahead and that’s exactly why it makes this a challenging paper to read and review.</p><p>This blog assumes that you have a fundamental understanding of deep learning, word vectors, and embeddings space, as these are a prerequisite to master language models.</p><p>The principle method of training (deep) computer vision models has gradually reached the doors of natural language processing as well. We are talking about transfer learning.</p><p>Once we understand the landscape of model pre-training in NLP, we would be in a comfortable yet confusing spot to grasp what REALM does and how!</p><p>To walk us through the field of language modeling and getting a hold over the relevant concepts we will cover the following in this series of blogs:</p><ul><li>Transfer learning and its relevance to model pre-training</li><li>Open Domain Question answering (Open-QA)</li><li>BERT (bidirectional transformers for language understanding)</li><li>Roberta ( robustly optimized BERT pre-training approach)</li><li>Google T5</li><li>REALM: Retrieval-Augmented Language Model Pre-Training</li></ul><p>This post will specifically try to explain the following:</p><ul><li>Transfer learning</li><li>Language Model Pre-training</li></ul><h3>Transfer learning</h3><p>When we have a huge dataset of images for which we want to solve an image classification and/or localization task, we explicitly utilize the image pixels as the features. Training deep neural networks to solve such tasks requires us to utilize humongous amounts of computing power and data. Usually, big tech companies and research labs working in this domain have already trained many such networks from scratch and released their pre-trained weights online. How can we utilize this?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*itwiuj_HVMA-oxoOnuso1w.png" /><figcaption>Transfer Learning using a convolution neural network <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><p>Let’s consider a simple convolutional neural network (shown above) with 4 convolution layers (conv + relu + max pool) followed by a fully connected (FC) layer which terminates with a loss function like softmax or sigmoid. We are training this model on the ImageNet dataset, which is a collection of over ~1 million images belonging to ~1000 classes.</p><p>Now the task of deep neural networks is to progressively extract features and combine these features to learn even more complex features. Each of the layers shown in the above figure is doing the following tasks:</p><ul><li><strong>Conv1</strong> — extracts simple edges, curves, and lines</li><li><strong>Conv2</strong> — uses these learned features to extract shapes and geometrical segments in the image</li><li><strong>Conv3</strong> — learns to detect textures like mesh patterns or smooth cloth or roads</li><li><strong>Conv4</strong> — learns even more complex features like eyes, ears, chairs, doors and other fundamental cues which help us understand what the object might be</li><li><strong>FC layer </strong>— uses the previously learned features to find out combinations which work out well together to give a coherent picture of the object to be classified</li><li><strong>Loss Function</strong> — this combination given out by the FC layer is converted to a score and the high score/probability class is returned as prediction</li></ul><p>Now if we observe closely, features learned by the model in the first few layers are quite generic to any image and can be seen as redundant across a range of image classes. The only layer that helps us explicitly differentiate between objects is the fully connected layer with the loss function.</p><p>Generally, when we talk about training a deep neural network, we mean we are going to<strong> freeze the weights</strong> of most of the convolution layers (`marked in pink`) and we just <strong>modify the weights of the fully connected layers</strong> with the loss function (`marked in the green`). Essentially we can change the entire network after the frozen layers and make it suitable to a similar image-based learning task. Only the part of the weights which are allowed to change is modified through training on new use-case specific data. This update to the weights of a pre-trained model is called<strong> fine-tuning</strong>.</p><blockquote>Eg, we have a pre-trained model for image classification with a particular loss function and we want to solve the task of image segmentation. So we freeze the conv layers and modify the FC layers to optimize the loss function relevant to segmentation, such that our model learns to predict the bounding box (location) along with the object class prediction.</blockquote><p>The use of models trained on a particular domain of learning tasks and repurposing the learned weights to solve another similar learning task is called <strong>transfer learning.</strong></p><p>Since the model trained using transfer learning doesn’t need to learn from scratch, it can easily be trained to a equal or higher performance metric (eg accuracy) without much computational cost and time.</p><h3>Language Model Pre-Training</h3><p>When we work with a huge corpus of textual data, it helps to know the probability with which a sequence of words will follow each other and what particular features are needed to understand this dependence.</p><p><strong>Language modeling</strong> is the task of understanding this probability distribution over a sequence of words. This helps us create features that can distinguish between sentences and phrases, as per the context in which they appear.</p><p><strong>Comparison with Word Embeddings<br></strong>Whenever we want to utilize words or textual data as features in our model, we usually convert them into sparse vectors like one-hot encoding or else dense vectors called <strong>embeddings</strong>. Though pre-trained embeddings have been widely used in NLP tasks earlier as well, the novelty of language model pre-training is the fact that they are fine-tuned for a particular downstream task and not as widely generalized like embeddings are for texts. Embeddings like word2vec and GloVe are a vector representation of words or sentence which capture the context and semantic features of each word. Pre-trained language models further distill these embeddings to task-specific representation such the specific goal is achieved through training on tasks specific datasets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*NmM9J_34HWvNt2idYEkGMQ.png" /><figcaption>Pre-trained language model usage pipeline <a href="https://www.linkedin.com/in/mandardeshpande1995/">(Mandar Deshpande)</a></figcaption></figure><p>In effect, we feed huge corpus (Wikipedia, Quora) of unlabelled/unannotated texts to a language model and expect it to learn the inherent word and sentence level relationships between varying contexts and subjects. Once the model is trained, this essentially means the model has learned the structure of the language i.e. the language has been modeled in some latent vector/embedding space. Once we have a pre-trained language model we can utilize it for any downstream tasks such as text classification, text generation, and sentiment classification.</p><p>The use of pre-trained language models has been the most exciting news in natural language processing in a long time and a lot of upcoming research is building upon this concept. This domain can be highlighted by through the following seminal works in pre-trained language models:</p><ol><li><a href="https://arxiv.org/abs/1801.06146"><strong>ULMFiT</strong></a><strong> : </strong>Universal Language Model Fine-Tuning method</li><li><a href="https://arxiv.org/abs/1802.05365"><strong>ELMo</strong></a><strong>:</strong> Embeddings from Language Models</li><li><strong>Transformer: </strong><a href="https://arxiv.org/abs/1706.03762"><strong>Attention is All You Need</strong></a></li><li><a href="https://arxiv.org/abs/1810.04805"><strong>BERT</strong></a><strong>: </strong>Bidirectional Encoder Representations from Transformers</li></ol><p><a href="https://towardsdatascience.com/language-modelingii-ulmfit-and-elmo-d66e96ed754f">We will review a few of these</a> and continue our discussion on language modeling specifically for REALM in the <a href="https://towardsdatascience.com/language-modelingii-ulmfit-and-elmo-d66e96ed754f">follow-up posts</a>.</p><p><a href="https://towardsdatascience.com/language-modeling-c1cf7b983685">Link to Part I</a>: Language Modeling I<a href="https://towardsdatascience.com/language-modelingii-ulmfit-and-elmo-d66e96ed754f"><br>Link to Part II</a>: Language Modeling II: ELMo and ULMFiT<br><a href="https://towardsdatascience.com/the-transformer-a-quick-run-through-ce9b21b4f3ed">Link to Part III</a> : The Transformer: A Quick Run Through</p><p>Keep learning and growing till then!</p><p>Connect with me on Twitter: <a href="https://twitter.com/mandroid_6">https://twitter.com/mandroid_6</a></p><blockquote>All images above have been created by me on my iPad and I have the rights to use them</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c1cf7b983685" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/language-modeling-c1cf7b983685">Language Modeling</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[Convolutional Neural Network — II]]></title>
            <link>https://medium.com/data-science/convolutional-neural-network-ii-a11303f807dc?source=rss-d08a98ebec56------2</link>
            <guid isPermaLink="false">https://medium.com/p/a11303f807dc</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[basics]]></category>
            <dc:creator><![CDATA[Mandar Deshpande]]></dc:creator>
            <pubDate>Mon, 26 Mar 2018 21:27:47 GMT</pubDate>
            <atom:updated>2020-04-24T02:39:05.465Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/511/0*0MOpPcp99wIevuSk.png" /></figure><p>Continuing our learning from the <a href="https://towardsdatascience.com/cnn-part-i-9ec412a14cb1">last post</a> we will be covering the following topics in this post:</p><ul><li>Convolution over volume</li><li>Multiple filters at one time</li><li>One layer of convolution network</li><li>Understanding the dimensional change</li></ul><p>I have tried to explain most topics through illustrations as much as possible. If something isn’t easy to understand please ping me.</p><blockquote><em>Let’s get started!</em></blockquote><h3>Convolution over volume</h3><p>Don’t be scared to read ‘volume’, its just a way of saying images with more than one channel i.e. RGB or any other channels.</p><p>Up until now we just had just a single channel so we were just concerned about the height and width of the image. But with the addition of more than one channel we need to take care of the filters involved, as they should also encompass convolution across all channels (3 here).<br> So if the image dimension is n x n x #channels, so the filter which was earlier f x f would also now be required to be of dimension f x f x #channels.</p><p>Intuitively our input data is no more 2 dimensional but in fact 3 dimension if you consider the channels, and hence the name <strong>volume</strong>.</p><p>Below is a simple example of convolution over volume, of an image having dimension 6 x 6 x 3 with 3 denoting the 3 channels R, G and B. Similarly the filter is of dimension 3 x 3 x 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*1FIYBBMDsTRkiGus.png" /><figcaption>Fig 1. Convolution over volume (colour image — 3 channels) with filter of dimension 3 x 3</figcaption></figure><p>In the given example the purpose of the filter is to detect vertical edges. If the edge needs to be detected only in the R channel,then only the weights in R channel need to set for the requirement. If you need to detect vertical edges across all channels, then all filter channels will have the same weight as demonstrated above.</p><h3>Multiple filters at one time</h3><p>There is a high chance that you may need to extract alot of different features from an image, for which you will use multiple filters. If individual filters are convolved separately,it will increase the computation time and so its more convenient to use all required filters at a time directly.</p><p>Convolution is carried out individually as is the case with a single filter, and then results of both convolutions are merged together in a stack to form an output volume with a 3rd dimenion representative of the numbers of filters.</p><p>Below example considers a 6 x 6 x 3 image as above, but we are using 2 filters ( for vertical edge and horizontal edge) of dimension 3 x 3 x 3. The resultant images of 4 x 4 each are stacked together to get a output volume of 4 x 4 x 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/0*gJRce3rd3yLaBD7H.png" /><figcaption>Fig 2. Convolution over volume with multiple filter of dimensions 3 x 3</figcaption></figure><p>The output dimension can be calculated for any general case using the following equation :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/0*R04xglXO-7dN29Fr.png" /><figcaption>Fig 3. Equation governing the output image/signal dimension wrt input and filter dimension</figcaption></figure><p>Here, nc is the number of channels in the input image and nf are the number of filters used.</p><h3>One layer of convolution network</h3><p>If we consider one layer of a convolution network without the pooling layer and flattening, then it will appear close to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/0*Tx-3BjReqdJRnYtJ.png" /><figcaption>Fig 4. Single layer of convolution network only with Relu activation</figcaption></figure><p>It is important to understand that like in any other neural network, a convolutional neural network also has the input data x which is an image here and model weights given by the filters F1 and F2 i.e. W. Once the weights and the input image is convolved we get the weighted output W * x and then we add the bias b.</p><p>One of the key functions here is the RELU activation function, which is rectified linear unit. Relu helps us add non-linearity to the learning model and helps us better train/ learn the model weights for the generalized case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9VX8eHwA2-Gf3MAB.png" /><figcaption>Fig 5. Relu activation function</figcaption></figure><p>For values which are below a certain threshold ( here 0), the relu function doesn’t update the parameters at all. It simply dies. For a particular training example to be considered for training, it needs to have a set minimum value for the neuron to be activated. Also Relu helps us reduce the vanishing and exploding gradient problem faced in most deep neural network, as Relu provides efficient gradient propagation.</p><h3>Understanding the dimensional change</h3><p>Now that we have got a conceptual understanding of what is happening in a single layer, lets formulize a outline for a any given layer l of a convolution network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/0*-zjHFGVymDMb9XAZ.png" /><figcaption>Fig 6. Equations governing change in input dimensions based on filters, padding and stride</figcaption></figure><p>After computing individual components dimension, the final dimension n of layer l can be calculated using:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/0*b9TiY4V7RetCkTpn.png" /><figcaption>Fig 7. Dimensions of last layer <strong>l </strong>with filter size <strong>f</strong>, padding <strong>p </strong>and a stride of <strong>s</strong></figcaption></figure><h3>Conclusion</h3><p>We started this post by exploring convolution over volume and then continued the discussion with multiple filters at once. It easy to understand that the <em>volume </em>here is simply refers to the 3 color channels of the image data. The discussion about a single layer of a convolution network is very vital for grasping the entire network architecture, so make sure these concepts (relu, activation functions) are clear. The final section spoke about how we can assess our model’s layer dimension according to the amount of padding and stride used in the convolution with a filter.</p><blockquote>In the next post, I will be explaining various CNN architectures in details and assessing its unique features</blockquote><p><em>Originally published at </em><a href="https://mandroid6.github.io/2017/11/18/Convolutional-Neural-Networks-II/"><em>mandroid6.github.io</em></a><em> on November 18, 2017.</em></p><p><a href="https://twitter.com/mandroid_6">https://twitter.com/mandroid_6</a></p><h4>Checkout my other posts on machine learning and deep learning : <a href="https://medium.com/@razzormandar">https://medium.com/@razzormandar</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a11303f807dc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/convolutional-neural-network-ii-a11303f807dc">Convolutional Neural Network — II</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[Convolutional Neural Network — I]]></title>
            <link>https://medium.com/data-science/cnn-part-i-9ec412a14cb1?source=rss-d08a98ebec56------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ec412a14cb1</guid>
            <category><![CDATA[foundation]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Mandar Deshpande]]></dc:creator>
            <pubDate>Fri, 10 Nov 2017 00:00:00 GMT</pubDate>
            <atom:updated>2020-04-24T02:38:31.349Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/511/0*_HLNQtiIwBbUqZsz.png" /></figure><p>Before we jump into the full convolutional neural network, lets first understand the basic underlying concept and then build up on that.</p><p>This post will explain the following:</p><ul><li>Convolution Concept</li><li>Convolutional Neural Network</li><li>Strided Convolutions</li></ul><h3>Convolution Concept</h3><p>For those of you who have taken a class/course on digital signal/image processing, would be comfortable with the concept of covolution. For the rest of us, let quickly run through the concept, so that we can dive into the actual cnn implementation.</p><p>If you have an image of a city with alot of buildings as below, and you would like to extract all the edges from the image, how would you do it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/0*jc_pFe9xVWlJ12n3.jpg" /><figcaption>Fig 1. Edge detection on an image using convolution. Note how all the edges separating different colours and brightness levels have been identified</figcaption></figure><p>Whenever one signal (S) needs to be modified to extract only a set of desired features from it, the process is known as <strong>filtering</strong>. Now to carryout filtering, another set of signals are required which we somehow imposed/applied over the original signal, S, called <strong>filters</strong> (F). These filters can also be called <strong>masks</strong>, as they help us “mask” all image features except the ones we want!</p><p>Now all the <strong>masks</strong> can show the required effect on the image if they are convolved with the images pixels in a manner demonstrated by the below animation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/0*jLoqqFsO-52KHTn9.gif" /><figcaption>Fig 2. GIF demonstrating result of filter convolution on an image. <a href="https://www.coursera.org/learn/convolutional-neural-networks/home/">Source</a></figcaption></figure><p>For a better understanding of convolution please refer to this <a href="http://aishack.in/tutorials/image-convolution-examples/">post</a>.</p><h3>Convolutional Neural Network</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dRoTSJpPGk51uQe-.png" /><figcaption>Fig 3. Architecture of LeNet a Convolutional Neural Network here for digits recognition. Each plane is a feature map ie a set of units whose weights are constrained to be identical. <a href="https://www.google.co.in/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=3&amp;ved=0ahUKEwj1htDahv_ZAhXMuY8KHT4DAa4QFgg2MAI&amp;url=http%3A%2F%2Fvision.stanford.edu%2Fcs598_spring07%2Fpapers%2FLecun98.pdf&amp;usg=AOvVaw1r5QRjS6yPaYsenIJ6-SLm">Source</a></figcaption></figure><p>The above illustration from the original paper by <a href="http://yann.lecun.com/">Prof Yann Lecun</a> shows all the basic components and data flow in a convolutional network.</p><p>To put it in a quantifiable form, every CNN has the following components/layers:</p><ul><li>Input image</li><li>Convolution layer</li><li>Pooling Layer (max pooling or avg pooling)</li><li>Flattening</li><li>Fully connected Layer (default neural network)</li></ul><p>We will dive deeper into the details of each of the above layers in subsequent posts.</p><h3>Strided Convolutions</h3><p>When we are dealing with convolution on images of very large size, its not always required to convolve over each and every pixel of an image. So we can set the subsequent convolutions to be shifted by more than one pixel in either the vertical or horizontal axis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/0*DU3pvh2EMSKOEABx.png" /><figcaption>Fig 4. Effect of strided convolutions on an image dimensions</figcaption></figure><p>This shift in subsequent convolutions is called the stride, and hence the name strided convolutions.</p><p>If we have an image of dimension n x n with a padding p, which is convolved with filter of dimension f x f witha stride of s, then the output dimensions can be determined using the below general equation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/0*ymKZ_icKyF_MDw03.png" /><figcaption>Fig 5. Equation governing the resultant image/signal dimension after applying a filter (f x f) with padding (p) and stride (s)</figcaption></figure><p>PS: In the mathematical convolution operation we flip one of the signals being convolved i.e. like viewed in a mirror. The operation we are using above is actually cross-correlation, but generally in deep learning convolution is the term used for it!</p><h3>Conclusion</h3><p>In this post we have understood the basic concepts which help us in building the entire convolution neural network. We covered how convolution works with image data, using different filters or masks. Further we touched upon the various building blocks of a CNN, and how strided convolutions affect the image/data dimensions.</p><blockquote>In the next post I will be covering convolution in more detail and how it is applied across volumes with many filters.</blockquote><p><em>Originally published at </em><a href="https://mandroid6.github.io/2017/11/10/Convolutional-Neural-Networks-I/"><em>mandroid6.github.io</em></a><em> on November 10, 2017.</em></p><p>Follow me on Twitter: <a href="https://twitter.com/mandroid_6">https://twitter.com/mandroid_6</a></p><h4>Checkout my other posts on machine learning and deep learning : <a href="https://medium.com/@razzormandar">https://medium.com/@razzormandar</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ec412a14cb1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/cnn-part-i-9ec412a14cb1">Convolutional Neural Network — I</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[Essential Machine Learning Libraries — I]]></title>
            <link>https://medium.com/hackernoon/essential-machine-learning-libraries-i-ad346949adea?source=rss-d08a98ebec56------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad346949adea</guid>
            <category><![CDATA[ml-libraries]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[matplotlib]]></category>
            <category><![CDATA[numpy]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Mandar Deshpande]]></dc:creator>
            <pubDate>Fri, 23 Jun 2017 00:00:00 GMT</pubDate>
            <atom:updated>2020-04-24T02:39:50.531Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*XyEHnYFgKg83Wnc7.JPG" /></figure><blockquote>This post is part 1 of the Essential Machine Learning libraries series</blockquote><p>Hello guys,</p><p>Now that you have covered the some basics of the theory behind <a href="https://mandroid6.github.io/2017/04/03/Machine-Learning-Classification/">Machine</a> <a href="https://mandroid6.github.io/2017/04/15/Machine-Learning-Regression/">learning</a> through the previous posts(<a href="https://mandroid6.github.io/2017/04/03/Machine-Learning-Classification/">1</a> ,<a href="https://mandroid6.github.io/2017/04/15/Machine-Learning-Regression/">2</a>), it’s time to jump into some essential python libraries used for implementing ML and/or data science projects.</p><p><a href="https://hackernoon.com/tagged/python">Python</a> being the choice of most developers, major data science and ml/deep <a href="https://hackernoon.com/tagged/learning">learning</a> libraries used have been developed in Python. Though R is also be by many industry researchers for analytics and data science, my experience in this domain is limited to python.</p><p>This post will encompass only the libraries majorly used for data importing, preprocessing and visualization. The libraries used for ml model creation will be covered in the next post.</p><h3>1. Numpy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*s47qlN1PL5hG9I_L.jpg" /></figure><p>Numpy library adds support for multidimentional arrays and matrices in a manner similar to MATLAB. Along with a large collection of high-level mathematical functions to operate on these arrays. The core functionality of NumPy is its “ndarray”, for n-dimensional array, data structure.</p><h3>Sample Operations:</h3><h4>Array creation</h4><pre>import numpy as np x = np.array([1, 2, 3]) x</pre><p>Output — array([1, 2, 3])</p><pre>y = np.arange(10) # like Python&#39;s range, but returns an array y</pre><p>Output — array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])</p><h4>Basic operations</h4><pre>a = np.array([1, 2, 3, 6]) b = np.linspace(0, 2, 4) # create an array with four equally spaced points starting with 0 and ending with 2. c = a - b c</pre><p>Output — array([ 1., 1.33333333, 1.66666667, 4.])</p><p>Output — array([ 1, 4, 9, 36])</p><h4>Universal Functions</h4><pre>a = np.linspace(-np.pi, np.pi, 100) b = np.sin(a) c = np.cos(a)</pre><h4>Linear Algebra</h4><pre>from numpy.random import rand from numpy.linalg import solve, inv a = np.array([[1, 2, 3], [3, 4, 6.7], [5, 9.0, 5]]) a.transpose()</pre><p>Output — array([[ 1. , 3. , 5. ], [ 2. , 4. , 9. ], [ 3. , 6.7, 5. ]])</p><p>Output — array([[-2.27683616, 0.96045198, 0.07909605], [ 1.04519774, -0.56497175, 0.1299435 ], [ 0.39548023, 0.05649718, -0.11299435]])</p><pre>b = np.array([3, 2, 1]) solve(a, b) # solve the equation ax = b</pre><p>Output — array([-4.83050847, 2.13559322, 1.18644068])</p><pre>c = rand(3, 3) * 20 # create a 3x3 random matrix of values within [0,1] scaled by 20 c</pre><p>Output — array([[ 3.98732789, 2.47702609, 4.71167924], [ 9.24410671, 5.5240412 , 10.6468792 ], [ 10.38136661, 8.44968437, 15.17639591]])</p><pre>np.dot(a, c) # matrix multiplication</pre><p>Output — array([[ 53.61964114, 38.8741616 , 71.53462537], [ 118.4935668 , 86.14012835, 158.40440712], [ 155.04043289, 104.3499231 , 195.26228855]])</p><p>For more detailed examples and tutorials follow this <a href="http://cs231n.github.io/python-numpy-tutorial/">link</a>.</p><h3>2. Scipy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*ZyhbZru6NfF39cNz.jpg" /></figure><p>SciPy is a Python-based ecosystem of open-source software for mathematics, science, and engineering. It has a lot of packages for scientific computing including but not exhaustive — optimization, integration, fast fourier transform, ODE and signal and image processing.</p><p>SciPy is organized into subpackages covering different scientific computing domains. These are summarized in the following table:</p><p><strong>Subpackage</strong> <strong>Description</strong> cluster Clustering algorithms constants Physical and mathematical constants fftpack Fast Fourier Transform routines integrate Integration and ordinary differential equation solvers interpolate Interpolation and smoothing splines io Input and Output linalg Linear algebra ndimage N-dimensional image processing odr Orthogonal distance regression optimize Optimization and root-finding routines signal Signal processing sparse Sparse matrices and associated routines spatial Spatial data structures and algorithms special Special functions stats Statistical distributions and functions</p><p>Since there are a lot of examples to be covered under scipy, I will be writing a seperate post after I have tried working with most of them. Till then you can check out the following <a href="https://docs.scipy.org/doc/scipy/reference/tutorial/index.html">link</a></p><h3>3. Matplotlib</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Lqc3dRZbcAijmtyw.png" /></figure><p>Matplotlib is a Python plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shell, the jupyter notebook, web application servers, and four graphical user interface toolkits.</p><p>It provides an object-oriented API for embedding plots into applications using general-purpose GUI toolkits like Tkinter, wxPython, Qt, or GTK+. There is also a procedural “pylab” interface based on a state machine (like OpenGL), designed to closely resemble that of MATLAB.</p><h3>Line Plot</h3><pre>import matplotlib.pyplot as plt import numpy as np a = np.linspace(0,10,100) b = np.exp(-a) plt.plot(a,b) plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*ZjxolYX1xnvPkota.png" /></figure><h3>Histogram</h3><pre>import matplotlib.pyplot as plt from numpy.random import normal,rand x = normal(size=200) plt.hist(x,bins=30) plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*iXzLmr8WCyLB8_XG.png" /></figure><h3>Scatter Plot</h3><pre>import matplotlib.pyplot as plt from numpy.random import rand a = rand(100) b = rand(100) plt.scatter(a,b) plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*q83_MPd47cf-VKjr.png" /></figure><p>For more detailed examples and tutorials follow this <a href="https://matplotlib.org/users/pyplot_tutorial.html">link</a>.</p><h3>4. Pandas</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/0*4DiTYn3z7BkpN1T4.png" /></figure><p>Pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipulating numerical tables and time series.</p><p>Few of the important features of pandas are :</p><ul><li>DataFrame object for data manipulation with integrated indexing.</li><li>Tools for reading and writing data between in-memory data structures and different file formats.</li><li>Data alignment and integrated handling of missing data.</li><li>Reshaping and pivoting of data sets.</li><li>Label-based slicing, fancy indexing,and subsetting of large data sets.</li><li>Data structure column insertion and deletion.</li><li>Group by engine allowing split-apply-combine operations on data sets.</li><li>Data set merging and joining.</li></ul><p>Some sample examples:</p><h4>Creating data</h4><pre>from pandas import DataFrame, read_csv import pandas as pd from numpy.random import rand names = [&#39;Bob&#39;,&#39;Jessica&#39;,&#39;Mary&#39;,&#39;John&#39;,&#39;Mel&#39;] births = [968, 155, 77, 578, 973]</pre><h4>Merging 2 lists using zip function</h4><pre>BabyDataSet = list(zip(names,births)) BabyDataSet</pre><p>Output — [(&#39;Bob&#39;, 968), (&#39;Jessica&#39;, 155), (&#39;Mary&#39;, 77), (&#39;John&#39;, 578), (&#39;Mel&#39;, 973)]</p><h4>Creating dataframe object for storing data in a manner similar to sql</h4><pre>df = pd.DataFrame(data = BabyDataSet, columns=[&#39;Names&#39;, &#39;Births&#39;])</pre><h4>Importing and dividing dataset</h4><pre>dataset = pd.read_csv(&#39;Dataset_name.csv&#39;) #modified as per need X = dataset.iloc[index of input values].values y = dataset.iloc[index of target/ouput values].values</pre><p>For more detailed examples and tutorials follow this <a href="https://pandas.pydata.org/pandas-docs/stable/10min.html">link</a>. Also <a href="https://www.datacamp.com/community/tutorials/pandas-tutorial-dataframe-python#gs.cfJ29OY">this</a> is a great article for a quick walkthrough.</p><p>Till now we have covered major python libraries required for importing and preprocessing data before actual machine learning model creation.</p><blockquote><em>In the next post I will be covering ml and deep learning libraries essential for creating, training and testing various models. So stay tuned!</em></blockquote><p><em>Originally published at </em><a href="https://mandroid6.github.io/2017/06/23/Essential-Machine-learning-Libraries-I/"><em>mandroid6.github.io</em></a><em> on June 23, 2017.</em></p><p>Follow me on Twitter: <a href="https://twitter.com/mandroid_6">https://twitter.com/mandroid_6</a></p><h4>Checkout my other posts on machine learning and deep learning : <a href="https://medium.com/@razzormandar">https://medium.com/@razzormandar</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad346949adea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/essential-machine-learning-libraries-i-ad346949adea">Essential Machine Learning Libraries — I</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Setup Python Environment for ml and Deep Learning]]></title>
            <link>https://medium.com/hackernoon/setup-python-environment-for-ml-and-deep-learning-c57ea54818ec?source=rss-d08a98ebec56------2</link>
            <guid isPermaLink="false">https://medium.com/p/c57ea54818ec</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[python-environment-for-ml]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Mandar Deshpande]]></dc:creator>
            <pubDate>Fri, 12 May 2017 00:00:00 GMT</pubDate>
            <atom:updated>2020-04-24T05:05:23.951Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Originally Published 12 May 2017</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/539/0*yUmYHb1U2hmII9Fd.png" /></figure><blockquote><em>This page gives quick and easy steps to setup your machine for machine learning and deep learning.</em></blockquote><p>Hi guys, In python there are many prebuilt libraries which can be used for machine learning and deep <a href="https://hackernoon.com/tagged/learning">learning</a>. But one major problem lies in setting up the environment for development using these libraries (especially for Windows based machines).</p><p>Since most of these libraries were built to be used on Linux (Ubuntu etc), its easier to setup the working environment in <a href="https://hackernoon.com/tagged/linux">Linux</a>. At the same time its a very confusing and lengthy procedure on Windows machine.</p><p>So below are the steps to get you up and running for ml and deep learning development on Windows:</p><h3>Step 1: Download Anaconda Distribution</h3><p>For your version of system 32bit or 64bit from <a href="https://www.continuum.io/downloads">here</a> Its better to select the version for Python 3.6 or 3.5.x since Tensorflow is yet only available for Python 3.5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/0*MQ-pxR6Fw_PsyIZU.JPG" /><figcaption>Fig 1. Anaconda Navigator download page</figcaption></figure><h3>Step 2: Install Anaconda</h3><p>Follow through the on-screen instructions Next-&gt;Next-&gt;Next-&gt; then :</p><ul><li>check the box to add python to environment variables path.</li><li>also make Anaconda as the default python checkbox to maintain uniformity.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/0*ONbWO3FbZE4CINi5.JPG" /><figcaption>Fig 2. Installation step for Anaconda 3</figcaption></figure><p>The following packages will be preinstalled in the Navigator:</p><ul><li>Spyder (IDE of choice)</li><li>Jupyter Notebook (for interactive programming)</li><li>Qt console ( for inline figures and graphics)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5vbFJcMsEpOrkjEH.JPG" /><figcaption>Fig 3. Initial view of the Anaconda Navigator Panel</figcaption></figure><h3>Step 4: Now go to the Environments tab</h3><p>on the left side of the Navigator</p><ul><li>Here click on <strong>Create</strong> new environment button, and</li><li>type in the Environment name you want (say environment)</li><li>Check only the Python check box ( uncheck R)</li><li>In the Python version tab select Python 3.5, since Tensorflow currently only works for 3.5</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/0*RmvyDzQMo4_F8lAx.JPG" /><figcaption>Fig 4. Environment selection and creation page</figcaption></figure><p>Once your new environment for Python 3.5 has been created it would appear like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gqMgB-PceJkdfOrM.JPG" /><figcaption>Fig 5. Installed packages in a given environment</figcaption></figure><p>Now from the search packages box, type-in and download the following packages:</p><ol><li>Jupyter</li><li>Scikit-learn</li><li>qtconsole</li><li>matplotlib</li><li>numpy</li><li>pandas</li><li>pip</li><li>scipy</li></ol><h3>Step 5:</h3><p>Once all above packages are installed, open up a terminal from your newly created Environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/0*Em082OKsIQNtENhW.JPG" /><figcaption>Fig 6. Steps to open a terminal in given environment</figcaption></figure><p>Once the terminal opens up type in the following for installing Theano:</p><p>conda install theano pygpu</p><p>Let the download and installation finish. After this type in the following for installing Tensorflow:</p><p>For CPU</p><p>pip install --ignore-installed --upgrade <a href="https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl">https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.1.0-cp35-cp35m-win_amd64.whl</a></p><p>For GPU</p><p>pip install --ignore-installed --upgrade <a href="https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl">https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.1.0-cp35-cp35m-win_amd64.whl</a></p><p>Once tensorflow has been successfully installed, type the following for installing Keras:</p><p>pip install git+git://github.com/fchollet/keras.git</p><p>Once everything has been installed,go to next Step. If not search for your specific error on Google, you will find numerous discussions and answers on StackOverflow. Otherwise ping me.</p><h3>Step 6: Testing</h3><p>Now to test whether scikit-learn, Theano , Tensorflow and Keras are working properly; open up a terminal just like the previous step but with python</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/0*-K8uqRrv3l-a6a15.JPG" /><figcaption>Fig 7. Opening a python shell in a given environment</figcaption></figure><p>Once the terminal opens up, it should appear like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/0*VGf-FGy9cggk9GmE.JPG" /><figcaption>Fig 8. Python Shell showing the installed version 3.5.3</figcaption></figure><p>Now type the following commands to test their working</p><p>import tensorflow as tf import theano import keras</p><p>If there are no errors, then Congratulations you have successfully setup your Environment for machine learning and deep learning.</p><p>If some errors pops up, copy the error content as search for solution on Google and stack overflow. This will only help you later in fixing other such minor issue.</p><blockquote><em>Otherwise ping me :D</em></blockquote><p><em>Originally published at </em><a href="https://mandroid6.github.io/2017/05/12/Environment-Setup/"><em>mandroid6.github.io</em></a><em> on May 12, 2017.</em></p><p>Follow me on Twitter: <a href="https://twitter.com/mandroid_6">https://twitter.com/mandroid_6</a></p><h4>Checkout my other posts on machine learning and deep learning : <a href="https://medium.com/@razzormandar">https://medium.com/@razzormandar</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c57ea54818ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/setup-python-environment-for-ml-and-deep-learning-c57ea54818ec">Setup Python Environment for ml and Deep Learning</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning — II]]></title>
            <link>https://codeburst.io/machine-learning-ii-20a372d9e081?source=rss-d08a98ebec56------2</link>
            <guid isPermaLink="false">https://medium.com/p/20a372d9e081</guid>
            <category><![CDATA[regression]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[basics]]></category>
            <dc:creator><![CDATA[Mandar Deshpande]]></dc:creator>
            <pubDate>Sat, 15 Apr 2017 00:00:00 GMT</pubDate>
            <atom:updated>2020-04-24T02:40:22.455Z</atom:updated>
            <content:encoded><![CDATA[<p>15 Apr 2017</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/0*x9-QUTP_-4iTwKdS.JPG" /></figure><p>Now after considering the <a href="https://mandroid6.github.io/2017/04/03/Machine-Learning-Classification/">previous example of classification</a>, let’s explore regression.</p><p>Assume you have some labelled training data consisting of various housing prices based on their square footage. Now if we plot our data we may get something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/0*Nt_WDS9AOgwoppzB.JPG" /></figure><p>Each x’s represents a unique house with its corresponding price and square footage.</p><p>Even though our data is scattered over the space of the graph, still it follows some basic pattern: here the prices increase as the size does. So we want our learning algorithm to do this prediction for us i.e. we supply the square footage and the algorithm gives out prices.</p><p>The generally visible trend would be a diagonal passing through the mean (x, y) positions of the data. Every such line which give a sufficiently good fit to the data, is called a predictor.</p><blockquote><em>You can call regression as a form of glorified curve fitting.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/0*PVDhPMTtiUk0v9z1.JPG" /></figure><p>Once we get this predictor, we can guess with a bit more conviction that a house of size ‘a’ will have prices xxxx. Most houses in our training data are at the lowest possible distance from the predictor. This simply implies that all houses will have a high probability of lying on the diagonal learned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/0*XUICpIYOlvTlCGMC.JPG" /></figure><p>We can have a number of linear trends to map our data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/0*KZqwLHku0c4f5yQK.JPG" /></figure><p>So any house which is not adhering to this predictor is either an outlier or doesn’t actually exist!</p><p>Now how we decide which is the best predictor, based on some <strong>quantized metric</strong>?</p><blockquote><em>Error metric: absolute difference (L1 norm), squared difference (L2 norm)</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*WPbKUi9Cog3M_EHE.JPG" /></figure><p>Once we get an error metric for each such possible predictor, we need to optimize it and then compare it with other alternatives.</p><p>For optimizing there are various techniques and algorithms possible to be implemented. More on that in another detailed post.</p><p>Also to add it’s not necessary for a predictor to be linear in nature. It can be of any degree. Quadratic, sinusoidal and even random unknown function work well.</p><p>Now if we look back at our housing price example, we just considered a single parameter — square footage. Why not extend our model by including more parameters like floor, parking space availability, amenities and age of house. Including most factors which influence the price of a house, will help us achieve higher accuracy of our predictor.</p><p>If you are not used to visualizing a multi-axis plot, then it appear a bit confusing at the start.</p><p>Just to spur your imagination, consider our simple square footage based estimator vs price. Here we had the prices along the y-axis and the square footage along the x-axis. Now as you keep increasing the dimensions (parameters) of your model, then subsequently more mutually orthogonal planes would start being added to our plot.</p><p>We consider a 2 parameter model, for which the graph will appear something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/0*WvzT78jh93cB8MgZ.png" /></figure><p>Again in this case we can have a predictor fit to our training data, but instead of a line, we need to draw a plane through the data because</p><p>plane = f(size, age) and equivalently our previous example was line = f(size)</p><p>Simply put, it has 2 input variables. There are a lot of other machine learning use cases which take into account hundreds or even around 1000s of variables. Sadly we can’t easily visualize any higher than 3 dimension, still can apply the above concepts to such systems.</p><p><em>Originally published at </em><a href="https://mandroid6.github.io/2017/04/15/Machine-Learning-Regression/"><em>mandroid6.github.io</em></a><em> on April 15, 2017.</em></p><p>Follow me on Twitter: <a href="https://twitter.com/mandroid_6">https://twitter.com/mandroid_6</a></p><h4>Checkout my other posts on machine learning and deep learning : <a href="https://medium.com/@razzormandar">https://medium.com/@razzormandar</a></h4><figure><a href="http://bit.ly/codeburst"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3hPOj27LTt0ZPn5TQuhZg.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20a372d9e081" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/machine-learning-ii-20a372d9e081">Machine Learning — II</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machine Learning — I]]></title>
            <link>https://codeburst.io/machine-learning-i-29ed226d51f6?source=rss-d08a98ebec56------2</link>
            <guid isPermaLink="false">https://medium.com/p/29ed226d51f6</guid>
            <category><![CDATA[linear-regression]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[basics]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Mandar Deshpande]]></dc:creator>
            <pubDate>Mon, 03 Apr 2017 00:00:00 GMT</pubDate>
            <atom:updated>2020-04-24T02:42:00.852Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/617/0*tC7w9oQs-mXWyw_j.JPG" /></figure><p>Computers which can think like humans or intelligent life, robots who can automatically search for objects as humans or animals do! Woah all this sounds like a scene out of the sci-fi movies like Minority Report. Autonomous cars and what not are all results of the recently emerging field of machine learning.</p><p>If you consider the past 7–8 years, ML has garnered serious attention from academia and industries alike. There is a very strong rationale behind revolutionizing our century (or maybe decade: P) old technologies ranging from healthcare to travel.</p><p>If one needs to understand ML through its scientific explanation, here you go:</p><blockquote><em>“A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P if its performance at tasks in T, as measured by P, improves with experience E.”</em></blockquote><p>Very academic for the lay mind? This post aims to address the issue of making machine learning easily understandable by anyone wanting to learning about it.<br> Because ML is a field which already has got countless API(application programming interfaces) which can be used without understanding the mathematical logic running the learning algorithms, but if you also possess this skill set your journey into ML will be much more smooth and clear.</p><p>At the ground level, machine learning is not at all a difficult concept to catch. Most ML algorithms involve the rudimentary task of drawing lines (but through data). <br> By drawing lines, it doesn’t only mean creating a line using a Paint job, but using these lines(straight, curves, zig-zag almost anything) for separating or classifying data based on related parameters.</p><p>Better to understand this through examples!</p><h3>Classification</h3><p>Let’s consider a hypothetical experiment. You have got a bag full of 3 different types of toys:</p><ul><li>Toy X (a red coloured ball)</li><li>Toy Y (a square shaped Rubix Cube)</li><li>Toy Z (a doll)</li></ul><p>Now if I tell you to separate all the toys into different groups, how would you do it? Think about even the most basic steps involved in doing this task.</p><ol><li>You have an image of a ball, a rubix cube and a doll in your brain from an earlier experience</li><li>Using your past experience you know, how a ball is spherical in shape and how the color red would appear on ball, and so you create a mental image of the same for all the toys involved</li><li>Now one by one you pick up the toy and identify it as Toy x, y or z based on how closely it matches your mental image</li><li>Once all the 20 toys have been identified as being either once of the 3 categories(x, y and z), you place them into separate groups</li><li>So in machine learning terms, you have accomplished the task of object classification</li></ol><blockquote><em>Cheers to you!</em></blockquote><p>Now just for a moment consider how the same task can be accomplished by a robot?</p><p>Quit complex right?</p><p>Now lets imagine from the point of view of a computer, which has images of oranges (orange colour) and guavas(green colour) of different sizes. Most machine learning algorithms begin by first getting your hands on labeled training data to feed to our model.</p><p>For our case, we would require a large number of images of guavas and oranges of various sizes which are labelled according to their type. So now if we plot our collected images, we might get a graph like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*zbbiSpjJ_m04EZcn.PNG" /></figure><p>Here the green x’s are guavas and the orange x’s are well oranges. As it can be easily noticed from the graph, there is an underlying pattern.</p><p>All the oranges seem to group on the right side of our plot while the guavas are all placed on the left side. Much as we humans can infer these patterns through observations, computers can learn the same using algorithms.</p><p>Now for separating the two fruits, we require to develop a algorithm which segregates them using a simple line in between. This line can be called the decision boundary.</p><p>So if we are considering the simplest decision boundary, our graph would appear as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*tv8XUxgolmeNi0HG.PNG" /></figure><p>You might say this is just a straight line, and what if we have a more mixed shapes of fruits which can’t be separated using straight lines?</p><p>No issue at all! Simply increase the complexity of your learning algorithm and you might end up getting a more non-linear boundary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*DoZcISCDgpqac9Ln.PNG" /></figure><p>While our algorithm does a good job at classifying the set of fruit images we give it into the 2 categories, we are assuming that the same will work for any image. Also it needs to be considered that as we increase the complexity we are also paving way for overfitting, but more about it later.<br> So to rephrase it:</p><blockquote><em>Once our algorithm has learnt from the given set of orange and guava images, it has the ability to generalize its experience to images of guava and oranges it hasn’t yet encountered</em></blockquote><p>For instance if we give the algorithm another image of fruit represented by the violet x, based on our decision boundary we could classify it as an orange!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/0*pKKHoIieHdBz5HU_.PNG" /></figure><p>Using this small example, we have now seen the power of machine learning, which uses some training data to generate a decision boundary. And the results of what we have learned are extrapolated to totally new portions data.</p><p><em>Originally published at </em><a href="https://mandroid6.github.io/2017/04/03/Machine-Learning-Classification/"><em>mandroid6.github.io</em></a><em> on April 3, 2017.</em></p><p>Follow me on Twitter: <a href="https://twitter.com/mandroid_6">https://twitter.com/mandroid_6</a></p><h4>Checkout my other posts on machine learning and deep learning : <a href="https://medium.com/@razzormandar">https://medium.com/@razzormandar</a></h4><figure><a href="http://bit.ly/codeburst"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i3hPOj27LTt0ZPn5TQuhZg.png" /></a></figure><blockquote>✉️ <em>Subscribe to </em>CodeBurst’s<em> once-weekly </em><a href="http://bit.ly/codeburst-email"><strong><em>Email Blast</em></strong></a><strong><em>, </em></strong>🐦 <em>Follow </em>CodeBurst<em> on </em><a href="http://bit.ly/codeburst-twitter"><strong><em>Twitter</em></strong></a><em>, view </em>🗺️ <a href="http://bit.ly/2018-web-dev-roadmap"><strong><em>The 2018 Web Developer Roadmap</em></strong></a><em>, and </em>🕸️ <a href="http://bit.ly/learn-web-dev-codeburst"><strong><em>Learn Full Stack Web Development</em></strong></a><em>.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29ed226d51f6" width="1" height="1" alt=""><hr><p><a href="https://codeburst.io/machine-learning-i-29ed226d51f6">Machine Learning — I</a> was originally published in <a href="https://codeburst.io/">codeburst</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>