<?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 Manikanta Munnangi on Medium]]></title>
        <description><![CDATA[Stories by Manikanta Munnangi on Medium]]></description>
        <link>https://medium.com/@manimannu93?source=rss-f3e4af2eac13------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*HWKXhCqVZDJn3qzBeq7_ew.jpeg</url>
            <title>Stories by Manikanta Munnangi on Medium</title>
            <link>https://medium.com/@manimannu93?source=rss-f3e4af2eac13------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 21:21:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manimannu93/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[Clear the Fundamentals of NLP with Code.]]></title>
            <link>https://medium.com/data-science/clear-the-fundamentals-of-nlp-with-code-7d419daefccf?source=rss-f3e4af2eac13------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d419daefccf</guid>
            <category><![CDATA[namaste-with-nlp]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[spacy]]></category>
            <dc:creator><![CDATA[Manikanta Munnangi]]></dc:creator>
            <pubDate>Mon, 18 Nov 2019 16:38:41 GMT</pubDate>
            <atom:updated>2019-11-21T15:09:38.869Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://medium.com/tag/namaste-with-nlp/archive">NLP with Spacy </a>(Part 2)</h4><blockquote>Getting hands-on experience in the basics of NLP using spacy.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xs0usEQJ_QGg6qrvWJ0SDg.jpeg" /></figure><blockquote>This is the continuation of the previous article “<a href="https://medium.com/@manimannu93/nlp-with-spacy-part-1-beginner-guide-to-nlp-4b9460652994">A Comprehensive guide to NLP”</a>.</blockquote><p>In the previous article, I have gone through what exactly is Natural Language Processing, What are the subsets (NLU and NLG) of NLP and applications.</p><p>In this article, I will demonstrate the fundamentals of NLP in code by using the increasingly popular<a href="https://spacy.io/"> spaCy</a> package and also the implementation of a few applications.</p><h3>Why spaCy?</h3><p>As we all know the most famous NLTK library from Stanford university is used by people for decades. It was built by researchers and scholars to serve as a tool for the NLP system. NLTK was created to support education and help students to explore ideas. Although, it works great for NLP systems. it is a string processing library it returns string as a result.</p><p>spaCy is built for “Industrial strength NLP in Python” developed by Matt Honnibal at <a href="https://explosion.ai/">Explosion AI.</a> It is mainly used for the production environment and its extreme user-friendliness. it is an object-based approach it returns objects instead of strings and arrays.</p><h4>Advantages over NLTK:</h4><ul><li>It’s incredibly fast because it is written in Cython language.</li><li>Dependency parsing.</li><li>It also offers access to larger word vectors that are easier to customize.</li><li>Integrated word vectors.</li><li>Supports GPU acceleration.</li><li>Supports user-defined Deep Learning networks.</li><li>But, very slow in Sentence tokenization compared to NTLK</li></ul><h3>What you will be Learning.</h3><ol><li>Tokenization.</li><li>Stop words.</li><li>Stemming and Lemmatization.</li><li>Dependency parsing.</li><li>Part-of-speech tagging.</li><li>Chunking.</li><li>Entity Recognition.</li><li>Word Vectors Similarity.</li></ol><h3>Prerequisites</h3><p>Before starting, you need to install it in your environment with the help of pip or conda(if you are installed already). I like to use pip, so I installed with pip.</p><pre># Using pip<br>sudo pip install spacy</pre><pre># Using conda<br>conda install -c conda-forge spacy</pre><p>You need to install language-specific models manually as they don’t come bundled with the spaCy library.</p><ul><li><strong>en_web_core_sm =&gt; </strong>Small</li><li><strong>en_web_core_md =&gt; </strong>Medium</li><li><strong>en_web_core_lg =&gt; </strong>Large</li></ul><p>where “en” refers to the English language and size varies with the applications it can perform in our case small and medium package is ok. Download and installation of statistical models with the below command. It is better to create a virtual environment for your projects.</p><pre># Download Models<br>python3 -m spacy download en_web_core_[any size]</pre><h4>Data Types: Doc, Span, Tokens.</h4><ul><li>Doc object contains all the information about the text. The attributes, methods, and properties that give access to the requested linguistic information of the text.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zka-glHjGyEro7BXFAIPlw.png" /><figcaption>Source: spaCy.io</figcaption></figure><ul><li>Slice of the doc is called span objects and Elements are called Token objects. they just contain the address and point the data in doc object .they act as a pointer.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*WWRIKg9kVRpKGnKwy73lTw.png" /><figcaption>Source: Datacamp.com</figcaption></figure><h3>1. Tokenization.</h3><p>It is a fundamental step in NLP tasks the word “tokenize” describes splitting the text into words, punctuations..etc into tokens, After processing it, the result is stored in <strong>Doc object.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f273f7794186df95ba571f9a4655a6b/href">https://medium.com/media/8f273f7794186df95ba571f9a4655a6b/href</a></iframe><ul><li>This is Word tokenization. it is performed in a way by separating the words with whitespaces, punctuation, symbols and other elements.</li><li>From isn’t==&gt; ‘is’, “n’t” and separated ‘!’==&gt;Exclamation, ’ .’==&gt;Period this all belongs to the Punctuation category.</li></ul><h3>2. Stop Words.</h3><p>Stop words like<strong> “a, is, on, for, my, also, any, only, now..etc”</strong> as they don’t contribute meaning to the sentence which we want to discards them before processing, they are some situations when performing <strong>Machine Translation &amp; Text Summarization, Question-Answering problems </strong>where stopwords need not discarded.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fae74ee645aa5b51c32deacd0ecac8f/href">https://medium.com/media/1fae74ee645aa5b51c32deacd0ecac8f/href</a></iframe><ul><li>Punctuation remains the same</li><li>Newline characters(\n), Special characters and punctuation should remove manually.</li></ul><h3>3. Stemming and Lemmatization.</h3><p>Stemming and Lemmatization both refer to text normalization where we downscaling every word into its root or base form.</p><blockquote><strong>Example:</strong> Plays Playing Played ==&gt; Play (root form)</blockquote><p><strong>==&gt; Stemming </strong>outputs the word by chopping off suffixes or prefixes used with a word, which is worse and doesn’t provide the correct base form but sometimes it does but most of the time <strong>it returns the invalid word. </strong>Unfortunately, spacy doesn’t provide stemming functionality.</p><blockquote><strong>Example: Studies</strong> yields into <strong>studi</strong> suffix removed.</blockquote><blockquote>In some ocassions,<strong> Studying</strong> yields to<strong> study .</strong></blockquote><p><strong>==&gt; Lemmatization </strong>provides the actual root word because it uses vocabulary and morphological analysis of words for downscaling the input text. it returns<strong> lemma</strong> an actual language word.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ccb533e8d5057c3d1772cdf7fad1b70/href">https://medium.com/media/8ccb533e8d5057c3d1772cdf7fad1b70/href</a></iframe><ul><li>As you can see “has”==&gt; “have” and “launched” ==&gt; “launch” is done.</li></ul><h3>4. Dependency Parsing</h3><p>It results in the syntactic dependency labels to each word for a better understanding of relationships between each word like the subject, object, verb.</p><ul><li>The spaCy library provides a wonderful visualization tool called <strong>dispaCy </strong>for<strong> </strong>displaying dependency labels as a graph.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d65d7a84a26c1c35a2f76f749bb98393/href">https://medium.com/media/d65d7a84a26c1c35a2f76f749bb98393/href</a></iframe><ul><li>It is used in the semantic analysis also used checking for grammatical errors.</li></ul><h3>5. Part-of-Speech tagging</h3><p>It assigns the parts of speech tag like a noun, adverb, adjective..etc to each word in a sentence. It is necessary to assign tags because it helps in distinguishing the meaning of the same token or word in a different context.</p><blockquote><strong>Example: </strong>What <strong>next</strong>? and other sentence She was sitting <strong>next </strong>her,</blockquote><blockquote>Both have common word <strong>next </strong>but first one is a adverb and second is a preposition.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a067cc5da01926fd2e5a1d640b682931/href">https://medium.com/media/a067cc5da01926fd2e5a1d640b682931/href</a></iframe><p>We can output POS tags in two different ways, either by <strong>.pos_ attribute</strong> which shows coarse-grained POS tag meaning full word or <strong>.tag_ attribute </strong>shows acronym of the original tag name.</p><h3>6. Chunking</h3><p>Chunking is a process of adding the syntactical structure and meaning to the sentences while POS tags describe verb, adverb, adjective…etc but they don’t provide the meaning,<strong> chunking is performed by taking POS tags </strong>as input and returning chunks as an output. it helps in extracting the group of noun and verb phrases that are<strong> used for Named Entity Recognition.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ade9373a9671f4a459ddb7fc6b6b513/href">https://medium.com/media/7ade9373a9671f4a459ddb7fc6b6b513/href</a></iframe><h3>7. Named Entity Recognition</h3><p>Named entity recognition is also known as Ner used for labeling real-world objects into pre-defined categories <strong>like names, place, things, organization, quantities, numbers…etc.</strong> The spacy statistical model capable of recognizing a wide range of named or numerical entities. you can add your custom categories by training on huge data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a958554c1ea88b6d1cb2c4f68b914ae/href">https://medium.com/media/2a958554c1ea88b6d1cb2c4f68b914ae/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9K_eGx-3AGJcNhT8QgQ-Q.png" /><figcaption>NER Output.</figcaption></figure><ul><li>Its Applications are in search engines utilizing the NER tags that are recognized for efficient searches.</li></ul><h3>8. Word Vector Similarity</h3><p>It is a process of converting word to vectors for<strong> finding similarity between words of the same tree</strong>. for humans, it is easy to know the similarity between “dog” and a “cat” cause they belong to the animal category. for machines, they find similarity with vectors. it is also used with sentences and documents for finding similarity between each sentence. It is also known as word embedding</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e98131d61f31abe116fcb8cd599e5f0/href">https://medium.com/media/6e98131d61f31abe116fcb8cd599e5f0/href</a></iframe><ul><li>This is just a sample, we can do a lot more with different statistical models for the word embeddings.</li><li>Applications of word vector similarity are the Recommendation system and Machine translation.</li></ul><h3>Conclusions:</h3><ul><li>Many NLP libraries are performing well the intention to use spacy it makes process quick and simplifies the tasks, has built-in word vectors and provides the results with good accuracy.</li><li>Spacy has capable of performing tasks in no time but a basic understanding is needed.</li><li>Try tweaking out the pre-trained models</li><li>Write your own custom pipeline classes for your tasks if they fail to perform well.</li></ul><p>We have seen basics of some NLP tasks, but they are more, we just scratched the surface with a deep understanding of process under the hood, you can do a lot of interesting things.</p><blockquote>Happy Learning :)</blockquote><h3>References:</h3><ol><li>Yuriy Guts,<a href="https://www.slideshare.net/YuriyGuts/natural-language-processing-nlp">https://www.slideshare.net/YuriyGuts/natural-language-processing-nlp</a>.</li><li>Lahiru Liyanapathirana, <a href="https://heartbeat.fritz.ai/nlp-chronicles-intro-to-spacy-34949f1bc118">https://heartbeat.fritz.ai/nlp-chronicles-intro-to-spacy-34949f1bc118</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d419daefccf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/clear-the-fundamentals-of-nlp-with-code-7d419daefccf">Clear the Fundamentals of NLP with Code.</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[A Comprehensive Guide To NLP.]]></title>
            <link>https://medium.com/data-science/nlp-with-spacy-part-1-beginner-guide-to-nlp-4b9460652994?source=rss-f3e4af2eac13------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b9460652994</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[namaste-with-nlp]]></category>
            <category><![CDATA[spacy]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[nlp]]></category>
            <dc:creator><![CDATA[Manikanta Munnangi]]></dc:creator>
            <pubDate>Sat, 16 Nov 2019 12:36:48 GMT</pubDate>
            <atom:updated>2019-11-22T03:57:46.707Z</atom:updated>
            <content:encoded><![CDATA[<h4><a href="https://medium.com/tag/namaste-with-nlp/archive">NLP with spaCy.</a> (Part 1)</h4><blockquote>Natural Language Processing is the one widely used in almost every domain, somewhat depth knowledge is required before hands-on.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*57SCvwUycvzPPepeXl80jQ.png" /><figcaption>Applications of NLP.</figcaption></figure><p><em>This is the first part of a series of Natural Language Processing (NLP) with spaCy. The next post gives a Basics of NLP with code using spaCy.</em></p><h3>Introduction:</h3><p>we all know the evolving technologies generating enormous raw data in the form of Structured which has a Pre-defined format can be used to search in databases like the number, texts, etc. on the other hand, Unstructured has no Pre-defined format that can’t be found easily making it much more difficult to collect, process and analyze for example Images, Videos, Files, etc. these types of data is generating every day and the number is too big <strong>2.5 quintillion bytes of data </strong>and it’s just started pacing up .<strong> </strong>I have never heard the<strong> word “Quintillion”</strong> unless it was pointed out on the web.</p><blockquote>Did you know ??</blockquote><blockquote>The number of zeros for Million is 6 and the number of zeros for Quintillion is 18.</blockquote><blockquote>Million -&gt; 1000000</blockquote><blockquote>Quintillion -&gt;1000000000000000000</blockquote><p>It is equivalent to<strong> 1 billion gigabytes </strong>of data is generated per day. You may be wondering that’s a big number. it because data comes from everywhere sensors used to gather shopper information, posts to social media sites, digital pictures, and videos purchase transactions, and cell phone GPS signals and the list goes on.</p><p>The question is how do we process, analyze and convert this data that are meaningful to us which helps in addressing our own needs and solve new technical problems.</p><p><strong>Natural Language Processing</strong> will help to analyze text-related problems. As this article is about NLP we will be looking only on it. Leaving other categories of data beyond this article.</p><h3>What you will be learning from this article:</h3><ol><li>What is Natural Language Processing?</li><li>Subsets of Natural Language Processing.</li><li>What are the Applications of NLP?</li></ol><h3>1. What is Natural Language Processing?</h3><p>With the help of a Bunch of Algorithms and rules the computer able to understand and communicate with humans in vast human languages and scales other language-related tasks. With NLP, it is possible to perform certain tasks like Automated Speech and Automated Text Writing in less time. Due to the evolving of large data (text), why not to use the computers which have high computing power, capable of working all day and ability to run several algorithms to perform tasks in no time.</p><blockquote>After getting success in speech recognition and vision research, natural language processing is the most targeted research area in artificial intelligence.</blockquote><p>Although it is started decades ago, most people lack the NLP experience. Because it’s hard to teach a machine with the challenges listed below:</p><ul><li><strong>Ambiguity: </strong>it is the challenge when a Single word has different meanings or a sentence that has different meanings in the context and even a sentence refers to sarcasm.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*zJbhg4Ix-nsJCv4TrEgJYg.png" /><figcaption>Lack of clarity in meaning.</figcaption></figure><ul><li>It comprises Ambiguity which is divided into two types: <strong>Lexical and Syntactic ambiguity</strong></li></ul><blockquote><strong>Lexical Ambiguity</strong> is the presence of two or more possible meanings within a single word.</blockquote><blockquote><strong>Syntactic Ambiguity</strong> is the presence of two or more possible meanings within a single sentence or sequence of words.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*m4eeKWSfZV0NvZh8WGmRsA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*lg9QKJyvwc2TCOTFF-11Mw.jpeg" /><figcaption>Source: ThoughtCo.</figcaption></figure><ul><li><strong>Syntax: </strong>Think of how a sentence is valid, it based on two things called syntax and semantics where <strong>syntax </strong>refers to the <strong>grammatical rules</strong>, on the other hand, <strong>semantics</strong> is the <strong>meaning</strong> of the vocabulary symbols within that structure. People change the ordering of sentences it is valid in some cases but not all.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*Y05c5BKhjNPpdJx6IYvHSQ.jpeg" /></figure><ul><li><strong>Co-reference: </strong>Referring to the same person, thing, country..etc that were mentioned earlier in a sentence or phrase with pronouns.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*01WT4Cwe-a_LxR-kpNBXDg.jpeg" /><figcaption>Coreference.</figcaption></figure><ul><li><strong>Normalization: I</strong>t is a well-known technique that is used in Machine Learning and Deep Learning. This step is done because data have different unit scales and convert those values back to the same unit scale. wherein Natural Language Processing we convert from informal words to standard form and make suitable for further processing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*OvfGyeTfz_RkDU-vTjcdpQ.jpeg" /><figcaption>Source: Slideshare.net</figcaption></figure><p>It involves normalizing text from social media, URLs, text-emojis, Company names with special characters e.g. Yahoo!, also includes misspellings words, hashtags, new words, and terminologies. There is no single best way to do normalization.</p><p>To do this task we use the <strong>Morphology part of NLU.</strong></p><ul><li><strong>Sarcasm: </strong>Same words different meaning refers to the Ambiguity topic. Suppose when someone does something wrong you reply as very good or well done. it’s also a challenge for a computer to understand the sarcasm because it’s a way more different than a normal conversation.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/269/1*0u1hcSk8GSlGNx9UKwSBNQ.jpeg" /><figcaption>Your Machine asks.</figcaption></figure><h3>2. Subsets of Natural Language Processing.</h3><p>when I talk about NLP it isn’t just one. It comprises the two topics embedded in it. Natural Language Understanding(NLU) and Natural Language Generation (NLG).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*7E8LARXZ0CyLg-SSpstdtg.png" /><figcaption>Source: Sciforce</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k6TIhTH1YEqIXsElwczzrg.png" /><figcaption>Classification of NLP.</figcaption></figure><h4>==&gt; Natural Language Processing (NLP):</h4><ul><li>It’s a process of converting the input (unstructured) text data into a human-readable format and process the text using statistical techniques.</li></ul><h4>==&gt; Natural Language Understanding (NLU):</h4><ul><li>As the name says it all Understanding the raw text before any modeling and analysis, the machine should have to get its underlying terms only then it starts processing it.</li></ul><ol><li><strong>Phonology: </strong>It’s the study of organizing sound systematically.</li><li><strong>Morphology: </strong>It is a study of the structure of words, formation, the relationship between words, forming things, analyze the meaning and lexical function.</li><li><strong>Pragmatics: </strong>It is the study of how words are used, signs, symbols and inferred meaning</li><li><strong>Syntax: </strong>It Refers to arranging words or phrases to form meaningful sentences,<strong> </strong>it follows grammatical rules.</li><li><strong>Semantics: </strong>It concerned about the meaning of words and how to combine words to form meaningful phrases and sentences.</li></ol><h4>==&gt; Natural Language Generation (NLG):</h4><ul><li>when a computer writes the data into meaningful phrases or sentences from some internal representation.</li><li>It involves — Text planning, Sentence planning, Text Realization</li></ul><p><strong>Text Planning:</strong> Reserving relevant information from the knowledge base.</p><p><strong>Sentence Planning: </strong>Helps in Choosing required words for complete meaningful sentences.</p><p><strong>Text Realization: </strong>According to Wikipedia, Realization is also a subtask of natural language generation, which involves creating an actual text in a human language (English, French, etc.) from a syntactic representation.</p><h3>3. What are the Applications of NLP?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*ZjbDOb7foCcHxfG4r2yTuA.png" /><figcaption>Sentiment Analysis.</figcaption></figure><blockquote>Sentiment Analysis helps the companies to understand their pros and cons and insights from their data,also able to make necessary changes in business stratagies .</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dzFyu4ElBCl--6EsdrSxSA.png" /><figcaption>Chatbots.</figcaption></figure><blockquote>Chatbots provides standard solutions to customer common problems and also personalized assistance to customers.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fwR6WajQLM66pQDheZnTXQ.jpeg" /><figcaption>Virtual Assistants.</figcaption></figure><p>and to name a few applications like text classification, information extraction, semantic parsing, question answering, paraphrase detection, language generation, multi-document summarization, machine translation, and speech and character recognition and a lot more.</p><h3>Conclusions:</h3><ol><li>Natural Language Processing is a subset of AI which deals with teaching a <strong>computer to understand the human-level language</strong> and act upon it.</li><li>It has<strong> challenges</strong> that are lacking the process and also in performance as well.</li><li>NLP comprises two subsets Called <strong>Natural Language Understanding and Natural Language Generation </strong>which helps in processing the text to the next level.</li><li>It involves a lot of study and understanding of<strong> linguistics.</strong></li><li>A vast number of<strong> applications </strong>like Sentiment analysis, Chatbots, virtual assistants and more that benefit us using NLP.</li><li>By leveraging the <strong>power of data and high-level computing hardware</strong> we can train the models in no time.</li></ol><p>That’s it, Hope you guys like the summarization of NLP. The next part follows the coding of NLP basics using spaCy.</p><blockquote>Happy Learning :)</blockquote><h3>References:</h3><ol><li>Yunyao Li, Research Manager and Research Staff Member at IBM ”<a href="https://www.slideshare.net/YunyaoLi/adaptive-parsercentric-text-normalization">https://www.slideshare.net/YunyaoLi/adaptive-parsercentric-text-normalization</a>”.</li><li>Sigmoider, get started with NLP <a href="https://medium.com/@gon.esbuyo/get-started-with-nlp-part-i-d67ca26cc828">https://medium.com/@gon.esbuyo/get-started-with-nlp-part-i-d67ca26cc828</a></li><li>Amar Jukuntla, the title is Learning, ”<a href="https://www.slideshare.net/amarjukuntla/learning-93260612">https://www.slideshare.net/amarjukuntla/learning-93260612</a>”.</li><li><a href="https://www.upgrad.com/blog/5-applications-of-natural-language-processing-for-businesses/">https://www.upgrad.com/blog/5-applications-of-natural-language-processing-for-businesses/</a></li><li><a href="http://michealaxelsen.com/blog/?p=347">http://michealaxelsen.com/blog/?p=347</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b9460652994" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/nlp-with-spacy-part-1-beginner-guide-to-nlp-4b9460652994">A Comprehensive Guide To NLP.</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[Everything After Training Your Deep Learning Model to a web app.]]></title>
            <link>https://medium.com/data-science/everything-from-your-deep-learning-model-to-a-web-app-279cd733f3d4?source=rss-f3e4af2eac13------2</link>
            <guid isPermaLink="false">https://medium.com/p/279cd733f3d4</guid>
            <category><![CDATA[git-lfs]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[bootsrap]]></category>
            <dc:creator><![CDATA[Manikanta Munnangi]]></dc:creator>
            <pubDate>Sun, 10 Nov 2019 17:46:17 GMT</pubDate>
            <atom:updated>2019-11-21T04:14:21.337Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Using the popular web framework Flask + Heroku is a cloud platform to help you deploy without much hassle.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*QcIhLKlpZtz8BCIrSEc_Dg.png" /><figcaption>Frameworks For Deploying Any Model.</figcaption></figure><blockquote>A routine Life cycle of a data science project is to starting with a use case, picking up data from all sources needed for the type of problem we want to solve, analyse data and performing some feature engineering and building a statistical model to make good generalization on future data and deploy into production and monitoring often for perform measures and in case to retrain the model with new data <strong>.</strong></blockquote><p>But, most of the time people end up at the stage of building a statistical model, they won’t involve in putting their model over the internet for real-world testing because of<strong> <em>new technical skills like front-end, back-end developing</em></strong> needs to learn to deploy a model into a web.</p><p>Of course, there are some easy ways to do it, that gonna make our work simpler even though you should have to know a few basics not even 20% for your first deployment. In this article, you will learn how to do a deployment part form basics.</p><p>Before starting this article let me motivate you guys with my project build with flask and Heroku, You are welcome to have a demo.</p><p><a href="https://cropify.herokuapp.com/">Crop: A Plant Disease Identifier</a></p><h3>What you will be learning from this article.</h3><ol><li>Save model weights to disk after training.</li><li>What are the skills required for deployment?</li><li>Setup and installing Flask.</li><li>Download a nice html5 templates for front-end.</li><li>Write code and upload it to Github.</li><li>Deploying to Heroku.</li></ol><h3>1. Save Model weights.</h3><p>Most of the folks know about this step and often call this as serializing. After training the model of some problem-solving use cases. Every one usually saves their entire model(architecture + weights + optimizer state) or just weights with python or API library (Pickle, Keras) of their choice to prevent the training model again. One thing you should know if you want to save only weights you need to have its architecture as a JSON or YAML file before loading or it shows you an error “Read mode only”.</p><p>Suppose you have done training and want to predict after few days at that time-saving model to an object will be a good idea because there no need to train again, you can simply load weights and make predictions.</p><h3>2. What Types of Skills required for deployment.</h3><h4>2.1 Web frameworks.</h4><p>You should know some fundamentals of web framework there are plenty to choose over the internet like Angular.js, Node.js, and ASP.net, PHP many frameworks but data scientist folks love python and R(used for statistical analysis often) as well, we can also write web app with python using most popular web frameworks like Django and Flask.</p><blockquote>Flask and Django are two choices to build web apps.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*XCy_L7Ylk6JbGCA-GQTfvw.jpeg" /><figcaption>Flask vs Django.</figcaption></figure><p><strong>Flask </strong>is, of course, a lightweight full flexibility with WSGI and easy to learn and also in implementing but only used for both small and large scale projects but often used for small scale projects, every one love it’s simplified version. You can start your web app with just 5 lines of code.</p><p><strong>Django </strong>is a full-stack framework everyone’s favorite often used for developing large applications almost you can do plenty of things but it takes time when you get used for it. it involves some of the concepts that are interconnected. so, you need to learn those before writing your code.</p><p><strong>Conclusion:</strong> Flask and Django have some similar concepts. <strong>Start with the flask</strong> it covers basics and be familiar with concepts like (templates and rendering) after developing few applications through flask you can make a transition towards Django.</p><p><strong>2.2 Some basic knowledge of HTML+ CSS+ Java Script.</strong></p><p>Yeah, front-end and back-end development but we won’t write much code for the UI part and background operations. It’s completely optional if you don’t want your web app with good UI, in that case, you won’t be tackling with this markup and styling much, for a good looking website with fully responsive and exception handling you need to learn some concepts. but, trust me it gonna be simple. we just download a nice looking template from bootstrap websites or html5 sites.</p><p>Just make some changes with the code and you will be up and running a nice website with all your stuff. we will be looking this part down below after a few sections.</p><h3>3. Set up &amp; Installing Flask.</h3><p>To Install Flask you need to have either pip or conda (if you installed already). Before installing flask<strong> you need to create a virtual environment for your flask project</strong> because not to conflict with the libraries. we only use whatever library required for our project with their preferred version. so, creating a virtual env will be pretty useful.</p><pre>Pip install Flask</pre><p>After you have done installing check if it’s installed properly by importing flask libraries in jupyter notebook (or) in the terminal.</p><h3>4. Get a good UI template for your project.</h3><p>You may want to showcase your project as a professional one in UI. then you need to do a front-end part. <strong>luckily we have all bunch of readymade code available over the internet</strong> some of them listed below completely free.</p><ul><li><a href="https://html5up.net/">HTML5 UP</a></li><li><a href="https://themes.getbootstrap.com/">Bootstrap Themes Built &amp; Curated by the Bootstrap Team.</a></li></ul><p>Twitter <strong>Bootstrap</strong> is a toolkit that uses CSS and Javascript / jQuery. It’s a front-end framework with all built-in CSS classes you just need to import one it will do all styling to your website. you can start working on it without much knowledge of CSS. <strong>It also creates a responsive website.</strong> Of course, you have to know HTML (Basics of website building).</p><p>Pick one template that best suits your projects UI remove sections that you feel useless in that template.</p><h3>5. Start Writing code.</h3><p>At first, I will explain the use case that I’m deploying to a web app which will help in detecting the disease of plants only I trained for two categories Tomato &amp; Potato analyze and provide remedies biologically and chemically to overcome the loss and further controlling in affected plants. if you feel confused with agricultural things in remedies I gathered a few videos that help you explaining in practice by videos button located near results.</p><p>You can find the code of the above project in my Github below link. I will explain the code in detail step by step.</p><p><a href="https://github.com/Manikanta-Munnangi/Keras-Custom-Model-Deployment-Using-Flask-And-Heroku">Manikanta-Munnangi/Keras-Custom-Model-Deployment-Using-Flask-And-Heroku</a></p><p>First, you should know the structure of files in the flask project. it will look like below one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*rYzmREdW51-KlBKneiscwg.png" /><figcaption>Flask files structure.</figcaption></figure><blockquote>Not to worry about the files in the models’ folder. you can grasp files in the model folder are nothing but model weights(h5), architecture (JSON) and database (.sqlite)those are my project files but for beginning, you need to have folders . Don’t change the name of the folders as they are to be in format flask wants.</blockquote><p>First, two folders were __pycache__ and .vscode are for visual studio code(vs code) config files it will be generated when you code in visual studio. So, not to worry about it.</p><blockquote><strong>Folders:</strong></blockquote><ol><li>Models ==&gt; model weights, JSON and any database files.</li></ol><p>2. Static ==&gt; this is where CSS, javascript files and also images used in the flask will be stored in this folder.</p><p>3. Templates ==&gt; have index.html (name need not be changed) and other HTML files.</p><p>4. Uploads ==&gt; Before making predictions the image file should be stored in some folder this is it.</p><blockquote><strong>Files:</strong></blockquote><p>app.py ==&gt; Main code to run flask and also working on the webserver.</p><p>Procfile ==&gt; You use the Procfile to tell Heroku how to run various files of your app.</p><p>requirements.txt ==&gt; List Packages used for your projects so that Heroku will install on it dynos (containers).</p><p>.gitignore ==&gt; GitHub files to ignore.</p><p>.gitattributes ==&gt; Paths to Large File Storage (Git LFS) when you want to upload files more than 100mb Git LFS comes handy.</p><h4>5.2 Flask Script.</h4><p>5 Lines of code can get your web app up and running.</p><p>Flask boilerplate code.</p><p><strong>In Index.html</strong> write hello world or any text to display.</p><pre>&lt;!doctype html&gt;<br>&lt;html&gt;  <br>&lt;body&gt;       <br>&lt;h1&gt; Hello world&lt;/h1&gt;   <br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p><strong><em>@app.route(‘/’)</em></strong><em> </em>where @ decorator used to wrap another function and extends the behavior of other functions.</p><p><strong><em>render_template</em> </strong>render the Html files. <strong><em>app.run() starts the webserver</em></strong> and provide a localhost URL. Open <a href="http://127.0.0.1:5000/">http://127.0.0.1:5000/</a> to view your web app,</p><blockquote>Flask Basics Done. Write Model predict function .</blockquote><p>Create a predict function in the <strong>app.py file </strong>that gets our image through <strong>request module</strong> in flask and process it with model and returning the results to result.html to display.</p><p><strong>==&gt;Get the image file</strong> using the request function from the flask module.</p><p><strong>==&gt; Save images </strong>from user uploads to a folder called “uploads”. before prediction, it should be in memory.</p><p>==&gt;<strong> leaf_predict</strong> is a function that returns if a user uploaded image has a leaf or not. This is done using <strong>Convolutional Autoencoders </strong>which I’ll discuss in the next article. if the return variable is leaf then our model will start prediction unless it won’t.</p><p>==&gt; <strong>Model_predict </strong>function used to preprocess the uploaded image in such a way we were trained on like resizing, image to the array, normalizing and expanding dimensions then compiling and predictions.</p><p>==&gt; <strong>Info() </strong>function is to get disease information from a database file (.sqlite). it will retrieve disease information after model_predict returns disease name .to retrieve we make write code to check disease name and SQLite database disease name is same, if same we return disease info to results page.</p><p>==&gt; <strong>At last returning None</strong> ..Why?? After the ‘POST<strong>’</strong> method <strong>request.files</strong> set the default to None.</p><blockquote>If you want to get a clear picture and more about the code you can view through My <a href="https://github.com/Manikanta-Munnangi/Keras-Custom-Model-Deployment-Using-Flask-And-Heroku">Github</a>.</blockquote><p>Check out it will be super simple. it’s a big project so I’m leaving for you to review the remaining code and understand so you can get workflow.</p><h4>5.3 Html script for the input form.</h4><p>Get your downloaded bootstrap or Html file in Vs code or any IDE of your choice here I used it vs code.</p><p>But the<strong> main part is to get image data through the Html button</strong> so we use form data after submitting it should call <strong>predict function in app.py</strong></p><p>form data Html.</p><ul><li>&lt; form action = <strong>“/predict”</strong> function to evoke after submission with POST method.</li><li>&lt;input tags type of<strong> “file“</strong> makes a button for uploading the file <strong>accept=” image/*” </strong>gets only images of all formats like(jpg, jpeg, png…)</li><li><strong>required </strong>variable at the end makes the user input image compulsory for submitting the form.</li><li>Finally, &lt;input type=” submit” makes form submitting after receiving the image.</li></ul><h4>5.4 Returning Results with Html.</h4><p>After prediction, we want to display results it can be done with Html again. first, we need to pass the result through the “predict” function in the app.py to result.html file.</p><p>Results through Html.</p><p>result.html disease info code.</p><blockquote>After Building entire model with flask .Now, it’s time to upload your work to Github.</blockquote><ul><li>Uploading all code to Github for<strong> Heroku cloud to grasp code </strong>from GitHub rather than Using Heroku CLI to deploy.</li></ul><p>Before pushing your project to Heroku You need to have two files that are needed for Heroku on how to run the app. Procfile and requirements.txt</p><h4>Procfile:</h4><pre>web: gunicorn app:app --bind 0.0.0.0:$PORT</pre><ul><li>Gunicorn is an open-source web server for Python. It allows Heroku to deploy our application .you need to install it with pip in case you are not installed.</li><li>We point our server to start the app.py with the app name the instance of Flask is the second parameter and the first parameter is the name of the app.[app:app]==&gt;[name of the app : its instance of Flask(__name__)]</li></ul><pre><em>from </em>flask <em>import </em>Flask</pre><pre>app = Flask(__name__)</pre><ul><li>Port and hosting will be taken care of Heroku.</li></ul><h4>Requirements.txt:</h4><p>To get all packages that you used for your project into a file .you probably know this command</p><pre>pip freeze &gt; requirements.txt</pre><p>Freeze command display all packages with their current versions. we are copying the result of freeze command to a file <strong>called requirements.txt using “&gt;“operator</strong></p><h3>6. Deploying to Heroku.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*j2XUbg7VoO7pYhtpGTzWrQ.jpeg" /><figcaption>Heroku with Github.</figcaption></figure><p>It makes the job easier with Heroku cause it takes care of everything because it is a<strong> platform as a service (PAAS)</strong> meaning it does set up infrastructure, pre-installed OS and redundant servers, run time environment. Except for some steps you should do manually.</p><h4>Steps to follow:</h4><ol><li>Create a Heroku account through the official Heroku <a href="http://www.heroku.com/">website.</a></li><li>After login, Create App.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wEjaAliB2KVjasQSQqugUQ.png" /><figcaption>Create a new app in Heroku.</figcaption></figure><p>3. Name your project it will be deployed as name.herokuapp.com and set up the <strong>Deployment method to Github.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NUS_dvGn3hZXfexUl2F5bw.png" /><figcaption>Connect to Github.</figcaption></figure><p>4. Here, we are linking our GitHub account with selecting our<strong> project repository.</strong></p><p>5. Manual deployment verifies the procfile and installs all libraries in requirements.txt file compress to slug compiler responsible for scaling application to a dyno for execution.if whole project after compressing to <strong>slug is more than 300MB your application stop process your app.</strong> Because they limited the slug size for free access accounts with limited hours.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ylyeiA8mnNZWTdj8HnlkCQ.png" /><figcaption>Look for Slug, buildpacks, and config settings.</figcaption></figure><p>6. My slug size is below 300MB and the frameworks used python and git LFS, the files that are linked to<strong> Large File System (LFS) are not supported in Heroku.</strong></p><ul><li>So we need to add configs as key “HEROKU_BUILDPACK_GIT_LFS_REPO” to value “https://&lt;token&gt;@github.com/username/repository.git” token is a unique personal Access token.</li><li>You need to register for that in your GitHub &gt; settings&gt; Developer Settings for Heroku to access your LFS files and also link in buildpacks to install LFS “<a href="https://github.com/raxod502/heroku-buildpack-git-lfs.git">https://github.com/raxod502/heroku-buildpack-git-lfs.git</a>”.</li></ul><p>7. Lastly, hit the deploy button in the deploy section and you are done with your project and<strong> available for people accessing over the internet.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*zdMJDxy_KDRqVC27dBDl_w.png" /><figcaption>Finally, Deploy.</figcaption></figure><blockquote>If you get any error it good to address the logs and debug your errors and google it you will surely end up with solution.</blockquote><h3>Key points to remember:</h3><ol><li>Use the flask framework if you are a beginner learning your basics.</li><li>Use the template from the bootstrap or html5.net website they are free. Make changes to the template that fits your project.</li><li>Get working with Heroku it seems to be easy as you working on often.</li><li>Finally, try to make projects that can level up your skills to advance get core fundamentals with small projects then move on to big ones.</li></ol><p>It’s a long article, I hope you guys like it and has learned basics from this article. Try playing with the code that is in my GitHub. I come up with another article soon.</p><blockquote>Happy Learning :)</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=279cd733f3d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/everything-from-your-deep-learning-model-to-a-web-app-279cd733f3d4">Everything After Training Your Deep Learning Model to a web app.</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[Crop: Plant Disease Identification Using Mobile App.]]></title>
            <link>https://medium.com/data-science/crop-plant-disease-identification-using-mobile-app-aef821d1a9bc?source=rss-f3e4af2eac13------2</link>
            <guid isPermaLink="false">https://medium.com/p/aef821d1a9bc</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[convolutional-network]]></category>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[plants]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Manikanta Munnangi]]></dc:creator>
            <pubDate>Fri, 18 Oct 2019 13:33:38 GMT</pubDate>
            <atom:updated>2019-11-21T03:43:34.059Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Plant diseases can be detected by leveraging the power of Deep Learning.</blockquote><figure><img alt="Crop Demo" src="https://cdn-images-1.medium.com/max/1024/1*hTBHmiYbWB13_hOxlUnuow.png" /><figcaption>Demo of Crop App.</figcaption></figure><p>In this article, I’m going to explain how we can use the Deep Learning Models to detect and classify the diseases of plants and guide the farmers through videos and give instant remedies to overcome the loss of plants and fields. At first, we have to understand</p><ol><li>What is the cause and how to overcome the cause?</li></ol><p>2. What are the benefits of doing this?</p><p>3. Can we solve this problem with <strong>“Deep Learning technology”?</strong></p><p>4. In Deep Learning “<strong>which Algorithm”</strong> is used to address this problem ? and how to do that ?.</p><blockquote>NOTE: I did it only for Tomato and Potato plants. you can do it for other plants by collecting data of that plant.</blockquote><h3>It also deployed to Web App. Check out below Link.</h3><p><a href="https://cropify.herokuapp.com/">Crop: A Plant Disease Identifier</a></p><h3>1. The Cause And Introduction.</h3><blockquote>Since the past days and in the present too, farmers usually detect the crop diseases with their naked eye which makes them take tough decisions on which fertilisers to use. It requires detailed knowledge the types of diseases and lot of experience needed to make sure the actual disease detection. Some of the diseases look almost similar to farmers often leaves them confused. Look at the below image for more understanding.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*nCn6lY6f9OMdbcKbwRmrpg.png" /><figcaption><strong>Similar Symptoms but different diseases.</strong></figcaption></figure><p>They look the same and almost similar. In case the farmer makes wrong predictions and uses the wrong fertilizers or more than the normal dose (or) threshold or Limit (every plant has some threshold fertilizers spraying to be followed), it will mess up the whole plant (or) soil and cause enough damage to plant and fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*QiKmn2lkrvRXGQHdts8PlQ.png" /><figcaption>Cause of overdose of fertilizers. (Source: jainsusa.com)</figcaption></figure><h4>So, How to prevent this from happening?</h4><p>To prevent this situation we need better and perfect guidance on which fertilizers to use, to make the correct identification of diseases, and the ability to distinguish between two or more similar types of diseases in visuals.</p><p>This is where <strong>Artificial Neural Networks </strong>comes handy. In short ANN</p><h3>2. What is ANN?</h3><blockquote>Artificial Neural Nets are computational model based on structure of biological neural nets designed to mimic the actual behaviour of a biological neural network which are present in our brain.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzH4WwxrAn-FJGpRgdX5iw.gif" /><figcaption>Combining the Multiple ANN’s.</figcaption></figure><p>So we can assign some stuff to it, it gets our job done. ANN helps us to make the correct identification of disease and also guiding the right quantity of fertilizers.</p><p>Only a single ANN can’t get our job done. So, we make a bunch of them stacking one on other forming a layer which we can make multiple layers in between input layer(where weights and data are given) and output layer(result) those multiple layers called Hidden layers and it then makes a<strong><em> Deep Neural Network and the study of it called Deep Learning.</em></strong></p><h3>2.1 How does it looks like The Deep Neural Network.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*q-_6fT1j1QzLsgTGPXwMuQ.jpeg" /><figcaption>Simple vs Deep Neural Nets.</figcaption></figure><p>Simple Neural Nets are good at learning the weights with one hidden layer which is in between the input and output layer. But, it’s not good at complex feature learning.</p><p>On another hand Deep Learning Neural Nets, the series of layers between input and output layer are called hidden layers that can perform identification of features and creating new series of features from data, just as our brain. The more layers we push into the more features it will learn and perform complex operations. The output layer combines all features and makes predictions.</p><p>Therefore, Simple Neural Nets are used for simple tasks and bulk data isn’t required to train itself. whereas in Deep learning Neural Network can be expensive and require massive data sets to train itself on. I’m not gonna discuss this topic cause it goes beyond this article.</p><blockquote>IF you are absolute beginner to Deep Learning concept below link would help to get all basics.</blockquote><p><a href="https://towardsdatascience.com/the-basics-of-deep-neural-networks-4dc39bff2c96">The basics of Deep Neural Networks</a></p><h3>2.2 What type of Deep Learning Model is best for this scenario??</h3><p>There you go <strong>Convolutional Neural Network(CNN or Conv Nets)</strong>. It is well known for its widely used in applications of image and video recognition and also in recommender systems and Natural Language Processing(NLP). However, <strong>convolutional</strong> is <strong>more</strong> efficient because it reduces the number of parameters which makes different from other deep learning models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*IY5W4FmGgBsu_5wbaNECCw.png" /><figcaption><strong>CNN Architecture.</strong></figcaption></figure><p>To keep it simple I will explain only the brief understanding of this model and the steps that are used in building Convolutional Neural Network.</p><h3>Main Steps to build a CNN (or) Conv net:</h3><ol><li>Convolution Operation</li><li>ReLU Layer (Rectified Linear Unit)</li><li>Pooling Layer (Max Pooling)</li><li>Flattening</li><li>Fully Connected Layer</li></ol><p>Start Writing Code.</p><p><strong>1. Convolution</strong> is the first layer to extract features from the input image and it learns the relationship between features using <strong>kernel or filters</strong> with input images.</p><p>2. <strong>ReLU Layer:</strong> ReLU stands for the Rectified Linear Unit for a non-linear operation. The output is <strong><em>ƒ(x) = max(0,x). </em></strong>we use this because to introduce the non-linearity to CNN.</p><p>3. <strong>Pooling Layer: </strong>it is used to reduce the number of parameters by downsampling and retain only the valuable information to process further. There are types of Pooling:</p><ul><li>Max Pooling (Choose this).</li><li>Average and Sum pooling.</li></ul><p>4. <strong>Flattening: </strong>we flatten our entire matrix into a vector like a vertical one. so, that it will be passed to the input layer.</p><p>5. <strong>Fully Connected Layer: </strong>we pass our flatten vector into input Layer .we combined these features to create a model. Finally, we have an activation function such as softmax or sigmoid to classify the outputs.</p><h3>3. Done understanding CNN Operations. What next??</h3><ol><li><strong>Gathering Data (Images)</strong></li></ol><p>Gather the data sets as many as you can with Images affected by diseases and also which are healthy. you should require bulk data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*PTOVUfDZfymZ12sgWAyE6g.jpeg" /></figure><p><strong>2. Building CNN.</strong></p><p>Build CNN using some popularly used open-source Libraries for the development of AI, Machine Learning and also Deep Learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*07pPlP1a8heoVmUsaCz8Sg.png" /><figcaption>Open Source Libraries.</figcaption></figure><p><strong>3. Choose Any Cloud-Based Data Science IDE’s.</strong></p><p>It is good to train models in the cloud as it requires massive computation power our normal machines laptops and the computer won’t sustain. If you have a good GPU config laptop you can train in your local machine. I choose Google colab you can choose whatever cloud you like.</p><p><strong>Google Colab:</strong></p><blockquote>Google colab is a free cloud service which offers free GPU(12Gb ram). It’s a hassle free and fastest way to train our model no need to installation of any libraries on our machine. it works completely on cloud. It comes pre-installed with all dependencies.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*2AMf0X9CZf5xwDE6nbg1Wg.png" /><figcaption>Google Colab offers free GPU.</figcaption></figure><p>Sign-in to colab and create a new python notebook(ipynb) switch to GPU mode and start writing code.</p><h4>4. Start Writing Code.</h4><blockquote>Data should be stored in Google drive before writing code.</blockquote><p>Source Code can be found here My GitHub <a href="https://github.com/Manikanta-Munnangi/CROP---Plant-Disease-Identification-Using-App">link</a> .</p><blockquote><strong><em>Step 1: Mount data from google drive</em>.</strong></blockquote><pre>from google.colab import drive<br>drive.mount(‘/content/your path’)</pre><blockquote><strong><em>Step 2: Import Libraries.</em></strong></blockquote><pre># Import Libraries<br>import os<br>import glob<br>import matplotlib.pyplot as plt<br>import numpy as np</pre><pre># Keras API<br>import keras<br>from keras.models import Sequential<br>from keras.layers import Dense,Dropout,Flatten<br>from keras.layers import Conv2D,MaxPooling2D,Activation,AveragePooling2D,BatchNormalization<br>from keras.preprocessing.image import ImageDataGenerator</pre><blockquote><strong><em>Step 3: Load train and test data into separate variables.</em></strong></blockquote><pre># My data is in google drive.<br>train_dir =&quot;drive/My Drive/train_set/&quot;<br>test_dir=&quot;drive/My Drive/test_data/&quot;</pre><blockquote><strong><em>Step 4: Function to Get count of images in train and test data.</em></strong></blockquote><pre># function to get count of images<br>def get_files(directory):<br>  if not os.path.exists(directory):<br>    return 0<br>  count=0<br>  for current_path,dirs,files in os.walk(directory):<br>    for dr in dirs:<br>      count+= len(glob.glob(os.path.join(current_path,dr+&quot;/*&quot;)))<br>  return count</pre><blockquote><strong><em>Step 5: View number of images in each.</em></strong></blockquote><pre>train_samples =get_files(train_dir)<br>num_classes=len(glob.glob(train_dir+&quot;/*&quot;))<br>test_samples=get_files(test_dir)<br>print(num_classes,&quot;Classes&quot;)<br>print(train_samples,&quot;Train images&quot;)<br>print(test_samples,&quot;Test images&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*fh-dcgpRftRgYDIe94WXXQ.png" /><figcaption>5.Output.</figcaption></figure><ul><li>12 Classes == 12 types of diseases images are collected.</li><li>14955 Train Images</li><li>432 Test images (i took only a few images to test mistakenly).</li><li>For prediction, I took only a few samples from unseen data. we can evaluate using validation data which is part of train data.</li></ul><blockquote><strong><em>Step 6: Pre-processing our raw data into usable format.</em></strong></blockquote><pre># Pre-processing data with parameters.<br>train_datagen=ImageDataGenerator(rescale=1./255,<br>                                   shear_range=0.2,<br>                                   zoom_range=0.2,<br>                                   horizontal_flip=True)<br>test_datagen=ImageDataGenerator(rescale=1./255)</pre><ul><li>Rescaling image values between (0 –1) called normalization.</li><li>whatever pre-processing you do with the train it should be done to test parallelly.</li><li>All these parameters are stored in the variable “<strong>train_datagen and test_datagen”.</strong></li></ul><blockquote><strong><em>Step 7: Generating augmented data from train and test directories.</em></strong></blockquote><pre># set height and width and color of input image.<br>img_width,img_height =256,256<br>input_shape=(img_width,img_height,3)<br>batch_size =32</pre><pre>train_generator =train_datagen.flow_from_directory(train_dir,<br>                                target_size=(img_width,img_height),                                                    batch_size=batch_size)<br>test_generator=test_datagen.flow_from_directory(test_dir,shuffle=True,target_size=(img_width,img_height),                                               batch_size=batch_size)</pre><ul><li>Takes the path to a directory, and generates batches of augmented data. Yields batches indefinitely, in an infinite loop.</li><li>Batch Size refers to the number of training examples utilized in one iteration.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*DG30cNRP67QCyZ02NETKJQ.png" /><figcaption>7.Output.</figcaption></figure><blockquote><strong><em>Step 8: Get 12 Diseases Names/classes.</em></strong></blockquote><pre># The name of the 12 diseases.<br>train_generator.class_indices</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*6GtXcXmkRsGvUgHvFAdb-w.png" /><figcaption>8.Disease Names.</figcaption></figure><blockquote><strong><em>Step 9: Building CNN model</em></strong></blockquote><pre># CNN building.<br>model = Sequential()<br>model.add(Conv2D(32, (5, 5),input_shape=input_shape,activation=&#39;relu&#39;))<br>model.add(MaxPooling2D(pool_size=(3, 3)))<br>model.add(Conv2D(32, (3, 3),activation=&#39;relu&#39;))<br>model.add(MaxPooling2D(pool_size=(2, 2)))<br>model.add(Conv2D(64, (3, 3),activation=&#39;relu&#39;))<br>model.add(MaxPooling2D(pool_size=(2, 2)))   <br>model.add(Flatten())<br>model.add(Dense(512,activation=&#39;relu&#39;))<br>model.add(Dropout(0.25))<br>model.add(Dense(128,activation=&#39;relu&#39;))          <br>model.add(Dense(num_classes,activation=&#39;softmax&#39;))<br>model.summary()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*i9CDUqI5vUFzECyrfzHRZQ.png" /><figcaption>9.Summary of layers.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*2nCDPR5by5ejy56uvugk3Q.png" /><figcaption>9. Output.</figcaption></figure><p>CNN shrinks the parameters and learns features and stores valuable information output shape is decreasing after every layer. <strong>Can we see the output of every layer? Yes!! We can.</strong></p><blockquote><strong><em>Step 10: Visualisation of images after every layer.</em></strong></blockquote><pre>from keras.preprocessing import image<br>import numpy as np<br>img1 = image.load_img(&#39;/content/drive/My Drive/Train_d/Tomato___Early_blight/Tomato___Early_blight/<br>(100).JPG&#39;)<br>plt.imshow(img1);<br>#preprocess image<br>img1 = image.load_img(&#39;/content/drive/MyDrive/Train_d/<br>Tomato___Early_blight/Tomato___Early_blight(100).JPG&#39;, target_size=(256, 256))<br>img = image.img_to_array(img1)<br>img = img/255<br>img = np.expand_dims(img, axis=0)</pre><ul><li>Take a sample image from the train data set and visualize the output after every layer.</li><li><strong>NOTE: Pre-processing is needed for the new sample image.</strong></li></ul><pre>from keras.models import Model<br>conv2d_1_output = Model(inputs=model.input, outputs=model.get_layer(&#39;conv2d_1&#39;).output)<br>max_pooling2d_1_output = Model(inputs=model.input,outputs=model.get_layer(&#39;max_pooling2d_1&#39;).output)</pre><pre>conv2d_2_output=Model(inputs=model.input,outputs=model.get_layer(&#39;conv2d_2&#39;).output)<br>max_pooling2d_2_output=Model(inputs=model.input,outputs=model.get_layer(&#39;max_pooling2d_2&#39;).output)</pre><pre>conv2d_3_output=Model(inputs=model.input,outputs=model.get_layer(&#39;conv2d_3&#39;).output)<br>max_pooling2d_3_output=Model(inputs=model.input,outputs=model.get_layer(&#39;max_pooling2d_3&#39;).output)</pre><pre>flatten_1_output=Model(inputs=model.input,outputs=model.get_layer(&#39;flatten_1&#39;).output)</pre><pre>conv2d_1_features = conv2d_1_output.predict(img)<br>max_pooling2d_1_features = max_pooling2d_1_output.predict(img)<br>conv2d_2_features = conv2d_2_output.predict(img)<br>max_pooling2d_2_features = max_pooling2d_2_output.predict(img)<br>conv2d_3_features = conv2d_3_output.predict(img)<br>max_pooling2d_3_features = max_pooling2d_3_output.predict(img)<br>flatten_1_features = flatten_1_output.predict(img)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cZeZMrCiX1nSDe-Rpqzkgg.jpeg" /><figcaption>10. Visualization</figcaption></figure><blockquote><strong><em>Step 11. Start Training CNN with Parameters.</em></strong></blockquote><pre>validation_generator = train_datagen.flow_from_directory(<br>                       train_dir, # same directory as training data<br>                       target_size=(img_height, img_width),<br>                       batch_size=batch_size)</pre><pre>opt=keras.optimizers.Adam(lr=0.001)<br>model.compile(optimizer=opt,loss=&#39;categorical_crossentropy&#39;,metrics=[&#39;accuracy&#39;])<br>train=model.fit_generator(train_generator,nb_epoch=20,                             steps_per_epoch=train_generator.samples//batch_size,                        validation_data=validation_generator,nb_val_samples=validation_generator.samples // batch_size,verbose=1)</pre><ul><li>Adam optimizer is used with learning rate=0.001</li><li>Loss function categorical_crossentropy is used for our<strong> Multi-class classification problem</strong>. Metrics is<strong> “ accuracy”.</strong></li><li>Fit_generator is used to train the CNN model. Using the validation data parameter for<strong> fine-tuning the model.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_vj5ikQuTK1mNLX-mfyP_w.png" /><figcaption>11. Train and validation Accuracy and Loss.</figcaption></figure><blockquote><strong>Step 12: Saving Model weights.</strong></blockquote><ul><li>Saving model weights to prevent from re-training of the model.</li></ul><pre># Save model<br>from keras.models import load_model<br>model.save(&#39;crop.h5&#39;)</pre><blockquote><strong>Step 13: Load Model from saved weights.</strong></blockquote><pre># Loading model and predict.<br>from keras.models import load_model<br>model=load_model(&#39;crop.h5&#39;)</pre><pre># Mention name of the disease into list.<br>Classes = [&quot;Potato___Early_blight&quot;,&quot;Potato___Late_blight&quot;,&quot;Potato___healthy&quot;,&quot;Tomato___Bacterial_spot&quot;,&quot;Tomato___Early_blight&quot;,&quot;Tomato___Late_blight&quot;,&quot;Tomato___Leaf_Mold&quot;,&quot;Tomato___Septoria_leaf_spot&quot;,&quot;Tomato___Spider_mites Two-spotted_spider_mite&quot;,&quot;Tomato___Target_Spot&quot;,&quot;Tomato___Tomato_mosaic_virus&quot;,&quot;Tomato___healthy&quot;]</pre><ul><li>Mentioning the name because our output is in <strong>numeric format. </strong>We cast it into strings.</li></ul><blockquote><strong><em>Step 14: Predictions</em></strong></blockquote><pre>import numpy as np<br>import matplotlib.pyplot as plt</pre><pre># Pre-Processing test data same as train data.<br>img_width=256<br>img_height=256<br>model.compile(optimizer=&#39;adam&#39;,loss=&#39;categorical_crossentropy&#39;,metrics=[&#39;accuracy&#39;])</pre><pre>from keras.preprocessing import image</pre><pre>def prepare(img_path):<br>    img = image.load_img(img_path, target_size=(256, 256))<br>    x = image.img_to_array(img)<br>    x = x/255<br>    return np.expand_dims(x, axis=0)<br>    <br>    <br>result = model.predict_classes([prepare(&#39;/content/drive/My Drive/Test_d/Tomato_BacterialSpot/Tomato___Bacterial_spot (901).JPG&#39;)])<br>disease=image.load_img(&#39;/content/drive/My Drive/Test_d/Tomato_BacterialSpot/Tomato___Bacterial_spot (901).JPG&#39;)<br>plt.imshow(disease)<br>print (Classes[int(result)])</pre><ul><li>we need to preprocess our image to pass in a model to predict</li><li>First, we resize the image ===&gt; image(150,150)</li><li>convert image to array by this it will add channels===&gt;image(150,150,3) RGB</li><li>Tensorflow works with batches of images we need to specify image samples===&gt;(1,150,150,3).</li><li>Predict_classes help to predict the new image belongs to the respective class.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6hUe6ZQWpz-0Y7CiE0vIPw.jpeg" /><figcaption>14.Predictions on test data, different diseases.</figcaption></figure><blockquote><strong><em>Final Step: Convert Model into “tflite”.</em></strong></blockquote><pre>from tensorflow.contrib import lite<br>converter = lite.TFLiteConverter.from_keras_model_file( &#39;crop.h5&#39; ) <br>model = converter.convert()<br>file = open( &#39;output.tflite&#39; , &#39;wb&#39; ) <br>file.write( model )</pre><ul><li>To make our model communicate with App we have to convert into the TensorFlow lite version, tflite is made for mobile Versions.</li><li>So, you can build or create a mobile app and make the app communicate with the model.</li></ul><p><strong>You can use the Google flutter framework to build apps with beautiful UI’s.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*bIwMiB8T4Co8R2dOXgG5qg.png" /><figcaption>Google flutter framework.</figcaption></figure><blockquote><strong>Before</strong> moving on into App part, you need setup the installation of flutter environment into your machine from <a href="https://flutter.dev/docs/get-started/install"><strong>Official website.</strong></a></blockquote><p>Open up flutter editor either Android studio or visual studio as you wish to code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*Rffl5IYDF5tUNVqUlrAMuA.png" /><figcaption>Editors of Flutter.</figcaption></figure><blockquote>Create a new flutter Project and make a folder in project files drop “<strong>output.tflite</strong>” file into assets folder into our flutter project .Below name is changed but tflite file is same.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/1*EtFjDxf6gw-sLdh1ZDR3VQ.png" /><figcaption>Flutter Assets folder.</figcaption></figure><p>The App User Interface can be of your choice, you can make one by learning flutter or just use my flutter app interface. It can be found in my Github.</p><p>Once you are done with dropping “output.tflite” in the assets folder, start running the app in the emulator and<strong> test model with some pictures that are from the test folder and also with real images that are unseen by the model before.</strong></p><h3>Conclusion:</h3><p>Plant Diseases are major food threats that should have to overcome before it leads to further loss of the entire field. But, often framers unable to distinguish between similar symptoms but ace different diseases. This will mislead to wrong or overdosage of fertilizers. Here, we employ Convolutional Neural Network(CNN) multiple layers of ANN called Deep Learning Algorithms to reduce this loss and guide farmers with video lessons. This can be done through mobile App “Not all farmers but some do use it.”</p><blockquote>I hope the above stuff would useful for everyone reading this article. I will surely come up with topics related to Data Science, ML, and DL. Happy Learning :)</blockquote><h3>Thank you for Reading…</h3><p><a href="https://github.com/Manikanta-Munnangi">My Github Profile.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aef821d1a9bc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/crop-plant-disease-identification-using-mobile-app-aef821d1a9bc">Crop: Plant Disease Identification Using Mobile App.</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>