<?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 Harsh Bardhan Mishra on Medium]]></title>
        <description><![CDATA[Stories by Harsh Bardhan Mishra on Medium]]></description>
        <link>https://medium.com/@harshcasper?source=rss-1e6bdd4e0a76------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_qIeRSS0-8UOJVLfeJU5cw.jpeg</url>
            <title>Stories by Harsh Bardhan Mishra on Medium</title>
            <link>https://medium.com/@harshcasper?source=rss-1e6bdd4e0a76------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 11:52:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@harshcasper/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[Building an API to fetch Memes using Python and Flask]]></title>
            <link>https://medium.com/analytics-vidhya/building-an-api-to-fetch-memes-using-python-and-flask-f0991a949be0?source=rss-1e6bdd4e0a76------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0991a949be0</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Harsh Bardhan Mishra]]></dc:creator>
            <pubDate>Thu, 09 Jul 2020 12:28:22 GMT</pubDate>
            <atom:updated>2020-07-10T13:56:11.572Z</atom:updated>
            <content:encoded><![CDATA[<p>Get to know how you can build a Flask REST API which can fetch Memes and Quotes from Reddit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K3Rtn0958wT1OLZJ" /><figcaption>Photo by <a href="https://unsplash.com/@_louisreed?utm_source=medium&amp;utm_medium=referral">Louis Reed</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>As a Front-End Developer, if you are moving into the intricacies of Backend Development, and you are just confused on the options you have, starting off with Python would be the best option for you here. Python is an interpreted language that has found its usage with Web Developers, Data Scientists, Application Developers and more. With a fairly gentle learning curve and easy-to-understand syntax, it would be the best option for you to start off with your Backend Development Journey in a fairly quick manner.</p><p>Similar to any other Language, Python has got plenty of Frameworks to develop Backend Interfaces. Some of the most popular ones are Django, Flask, Web2Py and more. They are used to set up things pretty quickly and help you get started with the Business Logic of your Application and interaction with your Database Layer. In this article, we will be covering on Flask primarily and how you can develop an Application Programming Interface (API) with Flask fairly quick which can fetch you Memes and Quotes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*-Qf7tXr42ZPGKPCkJQPHgw.jpeg" /><figcaption>Well, it’s that easy!</figcaption></figure><h3>What is Flask</h3><p>Flask is a Micro Web-Framework that is used for developing Backend Interface for your Application. It is a lightweight framework which has a small footprint and can be used to set up things pretty quickly, with a simple yet extensible core. While we talk about Backend, we must understand that it is the service which sends data from the Server to a User, who is present at the Client-Side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*2SLt4V7lti7Qbmpt4ShzDA.jpeg" /></figure><p>With the rise of complex applications which rely on Architectural Patterns to scale up, services are now being broken down into components that are being handled by a representative API. With the APIs, each service can be deployed independently and offers improved fault isolation. These APIs can be coupled to discrete tasks and can also be used to communicate with each other to pass on Data.</p><p>These APIs can be used to wrap up operations and hence they are being used extensively for developing Backend Interfaces and making them communicate with the Client-Side Interface. One of the most common API Pattern that is being used today is the REST API where REST stands for Representational State Transfer. They make use of the Hypertext Transfer Protocol (HTTP) and can be communicated via an HTTP Request, which specifies the Operation that needs to be done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WX2EiCdNPqB1V4TJQbvd9w.jpeg" /><figcaption>REST API allows your Client-Side to communicate with your Server-Side</figcaption></figure><p>Flask can be used to develop these REST APIs where simple HTTP methods can be used to communicate between the Client-Side and Server-Side Interfaces. Every API Request consists of four parts: <strong>Endpoint, Method, Header </strong>and a<strong> Body.</strong></p><p>The Endpoint defines the URL route which is being requested by a User while the Method defines the type of request. It can be either a GET, POST, DELETE or a PUT/PATCH request. The header is a piece of information that is usually passed for authentication between the Client and the Server while the Body decides the information that we need to pass to the server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*82gzUS7f_RiDf75b5FzRMQ.jpeg" /></figure><p>That was a pretty quick way to summarize everything up going at the Server-Side. Let’s see how Flask can be used to rapidly compose an API which can return us a Date-Time of our current request in JSON Format:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/54c846408a543f1d3bbc224442a9fa3f/href">https://medium.com/media/54c846408a543f1d3bbc224442a9fa3f/href</a></iframe><p>We managed to compose two endpoints for our Flask API within 15 Lines of Code. The <strong>@app.route</strong> decorator maps the HTTP requests to the functions and returns back HTTP responses in the form of JSON. The <strong>jsonify </strong>wraps the Datetime in a message and passes it as an HTTP response.</p><h3>Let’s build the App</h3><p>Now we will be building an API which can fetch Memes for us and we will define multiple endpoints for our Application to provide extensibility and customization options to the User. We will be using Praw which is a Python Reddit API Wrapper to help us fetch Memes directly from Reddit. Let’s get started with creating a Virtual Environment for our purpose.</p><p>Create a Folder for all your Code and open the Command Line Tool for your Operating System and push in the following commands:</p><pre>$ pip install virtualenv</pre><p>Once the virtualenv is installed you can activate a Virtual Environment by pushing a simple command:</p><pre>$ virtualenv env</pre><p>This will create a new Python executable in your current directory. Once the setup is finished, you can move forward with activating the Virtual Environment:</p><pre>$ activate</pre><p>You can alternatively deactivate your Virtual Environment with a simple command, if required. Let’s move ahead to creating a simple Flask API. Push in the following command and type in:</p><pre>$ pip install flask</pre><p>Open the VS Code/PyCharm and make a File app.py and push in the following Code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/176d27d6aa7f8e4def6df69492018c33/href">https://medium.com/media/176d27d6aa7f8e4def6df69492018c33/href</a></iframe><p>Kickstart your Code by opening the Command-Line and pushing in: python app.py. This will kickstart your Code and you will have a Web Server running on Port 5000 with the message &#39;Hello World from Python Flask!&#39;. Pretty easy isn’t it?</p><p>Let’s define the Logic Layer for our API in a separate file. We would need praw for our purpose so we will install it via Python Package Manager:</p><pre>$ pip install praw</pre><p>Go to <a href="https://praw.readthedocs.io/en/latest/getting_started/quick_start.html">Praw’s Documentation Page</a> and check out how you can carry out an OAuth Authentication before you can use the Wrapper in your API. You can register your Application for the purpose of building a Web App and you will get the following:</p><ol><li>A Client ID which is a 14-Character String.</li><li>A Client Secret which is a 27-Character String.</li><li>Password for the Reddit Account you are using.</li><li>Username for your Reddit Account.</li></ol><p>Let’s make a file named Main.py to define our Logic Functions here. Let’s authenticate this by running a User Run for our Application:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/085f0bc350581fb6952b0a1a30447b79/href">https://medium.com/media/085f0bc350581fb6952b0a1a30447b79/href</a></iframe><p>Let’s define a Function now which can be used to check if our Image is a <strong>JPEG/PNG</strong> or not. This will be used to check if the Image we are getting is a Valid Image or not:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3770a039aee4ec97a88eba84ff7f1c9b/href">https://medium.com/media/3770a039aee4ec97a88eba84ff7f1c9b/href</a></iframe><p>Let’s get a Meme now. We will define a Function wherein we pass two parameters: sub which means the Subreddit from where we want to Fetch the Memes and count which means the number of Memes we wish to fetch. Let’s define the function now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/411f583177feacc9f3bb7fa268b251d5/href">https://medium.com/media/411f583177feacc9f3bb7fa268b251d5/href</a></iframe><p>We will get the <strong>Title, URL, Upvotes, Downvotes, Reddit-URL </strong>and the <strong>Subreddit </strong>and append it to the Result and return it from the Function. We will define a similar function to get the Quotes as well from the Subreddit and the Count specified as well:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/756dd5b504f06a4117559dfa3994ee07/href">https://medium.com/media/756dd5b504f06a4117559dfa3994ee07/href</a></iframe><p>The <strong>submission </strong>defines the hottest submissions in a particular Subreddit and <strong>selftext </strong>defines the Markdown Content for a particular Submission. The rest of the code is pretty self-explanatory and you can play with it further before defining the API endpoints further.</p><h3>Let’s build the API</h3><p>Go back to the app.py file and let’s get started with defining the REST API endpoints for our Application. Remove all the code that we had written earlier in our file since we will be starting afresh. Let’s first define the Subreddits from where we want to fetch our Memes and initialize our Flask Application, by importing necessary libraries and creating a running app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00d0c1b779634fc1cef9931ac859afa0/href">https://medium.com/media/00d0c1b779634fc1cef9931ac859afa0/href</a></iframe><p>Let’s add the Decorators above individual functions now which converts them to a “Route” that defines new URLs for our Backend Service. Let’s create the Endpoint to represent our “Welcome” message on the screen, once the User kickstarts the API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d9080bd3ed5cb4bd26ad80d0e492a90/href">https://medium.com/media/9d9080bd3ed5cb4bd26ad80d0e492a90/href</a></iframe><p>Let’s know define an Endpoint which will return as a Meme from a Random Subreddit. We will make use of the get_meme() and check_image() function that we had defined earlier in our Main.py file to fetch Random Memes. We will take in the Title, URL of the Post, Upvotes/Downvotes, URL of the Picture and finally the Subreddit from where the meme has been fetched.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f18c42ceb28ff3a91e7cafb57f656a8/href">https://medium.com/media/9f18c42ceb28ff3a91e7cafb57f656a8/href</a></iframe><p>Let’s now define a Route that returns us a Meme from a Subreddit of our choice. We will be placing our code in a Try-Catch Block just to ensure that a 404 Message is returned if in case the Subreddit does not exist. We will return all the Data as a JSON with a Random Meme from the particular Subreddit, we are fetching from.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7eb09983da1460a2a72bb838baa21db8/href">https://medium.com/media/7eb09983da1460a2a72bb838baa21db8/href</a></iframe><p>The Code for this is pretty self-explanatory so let’s move forward towards building more endpoints and adding more functionality to our API with all the Functions that we had defined earlier.</p><p>We will now create an Endpoint which fetches us Memes given the number of Counts. Let’s write the code for this now:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb76f944b1b3273b634a9fc7f7cade60/href">https://medium.com/media/cb76f944b1b3273b634a9fc7f7cade60/href</a></iframe><p>We are adding a count of 50 here so that if the user asks for more than 50 Memes, we will send an Error Message correspondingly. We will implement another Route which can fetch us a number of Memes from a particular Subreddit. Let’s implement this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3c14a866fe7cadb080a701ebbb83859/href">https://medium.com/media/d3c14a866fe7cadb080a701ebbb83859/href</a></iframe><p>Let’s see what Endpoints we have implemented till now:</p><ol><li><strong>/givememe: </strong>Returns a Random Meme from any Subreddit that we had defined.</li><li><strong>/givememe/&lt;sub&gt;: </strong>Returns a Meme from the Subreddit that the User has specified.</li><li><strong>/givememe/&lt;int: c&gt;: </strong>Returns a Number of Memes from any Subreddit that we had defined.</li><li><strong>/givememe/sub/&lt;int: c&gt;: </strong>Returns a Number of Memes from a Subreddit that the User has specified.</li></ol><p>We will now define similar Routes to fetch the Text as Quotes as well from the Subreddits. The Code is pretty self-explanatory and you can skim through them as we implement further routes here.</p><p>Let’s implement a Route to fetch a Quote from a Subreddit specified by the User:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69a16470930fb59a83b99df66f698031/href">https://medium.com/media/69a16470930fb59a83b99df66f698031/href</a></iframe><p>Let’s implement a final functional Route now to return a number of Quotes from a particular Subreddit:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f135c979d7dac6561f5212a1b17cdcd/href">https://medium.com/media/0f135c979d7dac6561f5212a1b17cdcd/href</a></iframe><p>We will define a 404 Route as well so that the User can fall back on an Error Message if he has directed to an unspecified URL.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1e01e01a881e9b75559cb3c4d1b34d3/href">https://medium.com/media/a1e01e01a881e9b75559cb3c4d1b34d3/href</a></iframe><p>Now that we have built our API, let’s add this final block of Code which kickstarts our Application.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd26b37b3a6d544a8b037361d5c6acf5/href">https://medium.com/media/dd26b37b3a6d544a8b037361d5c6acf5/href</a></iframe><h3>Testing the API</h3><p>Now that we have built all our API endpoints and defined the Logic in them, we will move forward with testing our API at all suitable endpoints. Here, I will make use of Postman to test our API endpoints. If you have not installed the Postman, you can make use of your Browser to test our all the API endpoints.</p><p>Open your Command Line Tool and push in the command:</p><pre>$ python app.py</pre><p>This will kickstart the Server at Port 5000. Open Postman and create a new Request. Let’s push in the API endpoint: http://localhost:5000/givememe to create a Request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ycsLr8Vzj2mYatZR_P0jw.png" /><figcaption>A 200 OK Status Response and our JSON in Response</figcaption></figure><p>We can further experiment this with the other endpoints as well to further explore how our API works and functions. Let’s check out another API endpoint to fetch a 15 Random Memes by passing in: http://localhost:5000/givememe/15 to create a Request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YKWft6UoII8z_4Z7WvMqQg.png" /><figcaption>A 200 OK Status Message and a JSON Message in Response</figcaption></figure><p>You can optionally test these Endpoints on your Browser as well and they would send you proper JSON Response. You are now free to experiment with these endpoints and customize them according to your needs and purposes.</p><h3>Conclusion</h3><p>In this article, we have covered up the intricacies of API Development and how you can compose a Microservices API with Flask and Python fairly quick to fetch Memes and Quotes from particular Subreddits. We have also learnt how we can define our Endpoints and test them using Postman. We have a fully functional API at ready, and we can now work upon integrating a Front-End for the Application which can bring us a Meme-Sharing Network at hand as well.</p><p>So, what next? With Flask, you can further explore developing RESTful APIs and deploying it on Cloud-based Services like Azure or Heroku. You can start exploring how you can develop Scalable Features with Flask which can handle numerous requests and more. Unlike Django or Ruby on Rails, which automatically generate multiple files once you finish setting them up, Flask provides you with a lot more functionality and helps you define exactly what you need here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*7AZlyVPmMw1aYSdGoASE5Q.gif" /><figcaption>Leave a Clap</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0991a949be0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/building-an-api-to-fetch-memes-using-python-and-flask-f0991a949be0">Building an API to fetch Memes using Python and Flask</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Node Package Manager Guide]]></title>
            <link>https://medium.com/tesseract-coding/the-node-package-manager-guide-39b21d26e47d?source=rss-1e6bdd4e0a76------2</link>
            <guid isPermaLink="false">https://medium.com/p/39b21d26e47d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[npm]]></category>
            <dc:creator><![CDATA[Harsh Bardhan Mishra]]></dc:creator>
            <pubDate>Wed, 10 Jun 2020 11:39:57 GMT</pubDate>
            <atom:updated>2020-06-10T11:39:57.813Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Es3ii8Gs293nMlkIRerpbA.jpeg" /></figure><p>Node.js is an Open-Source Server Environment that helps implements Javascript in Server-Side Operations and allows setting up Web Applications on Chrome’s V8 Engine. Ever since its inception, Node.js has been a hot technology in the market especially with its multiple features enhancing the productivity of the Development Team and allows the development of Scalable Applications.</p><p>Node.js is supported by an incredibly flexible Javascript ecosystem and while Node.js is traditionally used to develop Backend Interfaces, it also allows the development of Command Line Interface Tools and Server-side rendering Applications, that has given Node.js a much impetus in the field of Development.</p><p>Node.js shines in the field of development, for its incredible-fast server-side operations and non-blocking, event-driven I/O that allows the implementation of real-time applications where the client and server can initiate communication freely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*1KY5C7_bOp4uQqywXea4jw.jpeg" /></figure><p>To explain this further, let me take the example of Apache Web Server that is traditionally used to deploy PHP-based Web Applications. In Apache, all requests are single-threaded and follow a monolithic structure.</p><p>This means that in Apache, a single thread waits for the file system to finish its operation before it can do anything else. Let’s take the example of a Restaurant and a Waiter. In an Apache Web Server, the Waiter will first take your order and will not do anything else before your order has been served.</p><p>This means, that before your order if you need a glass of water, that will not be served before your primary order has been served. After the primary order has been served, the Waiter can serve you a glass of water and so forth. This operation is known as Blocking.</p><p>In Node.js on the other hand, events are handled asynchronously. This means that events are handled continuously which are taken care of in the order they are raised. This is called “No Blocking Driven I/O”. In Node.js, everything is single-threaded and all users are sharing the same thread. This makes Node.js incredibly fast and reliable for real-time processing and operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_btkqY4YJlz6VaQgBHohQQ.png" /><figcaption>NodeJS Processing Model. Image Credits: MindMajix</figcaption></figure><h3>What is NPM?</h3><p>While talking about Node.js, it is incredibly important to understand about NPM or Node Package Manager, which is the primary intent of our article. The concept of NPM is quite similar to Ruby Gems or Python Pip Packages, which revolves around the purpose of modularity.</p><p>These packages are available online and hence can be downloaded by easy installation and managed in the project with dependency management. If you have worked with any Node.js Project or with any other Javascript Framework, you might have encountered NPM.</p><p>The purpose of NPM further enforces the belief that using Third-Party Packages can sometimes be used to further optimize the applications rather than reinventing the wheel with each iteration.</p><p>In this article, we will be seeing how we can work with NPM and manage our Javascript Project with much efficiency and dive deep into some advanced features of NPM as well. Before you work with NPM packages, it is highly recommended that you have Node.js installed on your system so that we can work with it easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*V3fS4fQ9urF8nDQkoIkMUw.jpeg" /></figure><h3>What are Packages?</h3><p>If you have ever built an application using Javascript, you must have used the Package Manager to install the dependencies. These dependencies must be installed with your project to allow the building of your project and rendering on your Local Host and these packages are mentioned in the package.json file which serves as the map of the project.</p><p>The package.json file will tell who created the project, what is the dependencies, and what are the individual version of the NPM packages we seek for our project. NPM is the largest package repository available in the world, and you can take a look at the various packages at <a href="http://npmjs.com/">NPM-JS</a> to search for packages and functionality that you would like to add to your project.</p><p>The basic idea of having Packages is to further enforce the belief of having lightweight projects that can be integrated into your code freely, which can be downloaded and put to use from anywhere around the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*oqggoUuwMjwGEUJVFHPlDQ.jpeg" /></figure><h3>Creating a package.json File</h3><p>To create a Node Project, npm init command is used. This command will initialize the Node Project and ask for various things like Package Name, Version of the Project, Description, Entry Point, Git Repository, Author, and Keywords. The Package Name chosen should be unique if you are looking to publish your Node Project on NPM Store. After you fill in all the necessary details, you will be asked to affirm the Package.json File which will now initialize a Node Project with a Package.json file.</p><p>Once we start installing the new packages, we will see how the package.json file is updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jxR-dGHm4zOhUNWjVZX0aA.png" /></figure><h3>Adding Packages Locally and Globally</h3><p>Now, we have our package.json initialized, so let’s move on and add some Packages to our Project. You can add packages to your Project, either locally or globally. If you are installing the packages locally, the packages will be available only in your project directory. If you are installing the packages globally, the packages will be available across your system and you can call it from any Node Project. So, let’s start by adding a new package to our project. We will use the npm install command to install a new package:</p><pre>$ npm install moment</pre><p>This Command will install the moment package that is used for parsing and display dates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kBIZaZe-NVcZxZLDiuMN0Q.png" /></figure><p>You can see, that the package has been mentioned in our package.json file along with its version:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*omk-cE-121EKJ_RgkCcepw.png" /></figure><p>These are the regular dependencies that we can work on during the project. But what about a scenario, where you need a package only in your development environment but not in your production environment? We will use a separate command along with the ubiquitous npm install command to install our Dev Dependencies. Let’s install the corona-tracker-stats (An NPM package developed by me) using this command:</p><pre>$ npm install corona-tracker-stats --save-dev</pre><p>Let’s see what this results in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jag-YclCEk4dkW_Z11pm8g.png" /></figure><p>You can now see that a separate Dev Dependency has been installed? But what exactly is it? It basically means that these are Development Tools and will not be included in your production environment. So we have now understood how we can download packages to local projects, but how can we add a package globally which can be accessible to all the projects?</p><p>If you want to add any Package globally you can just use a -g or -global flag to add the package globally which you can easily access from anywhere on your system. Let’s add a package globally on our system:</p><pre>$ npm install -g data_structure_models</pre><p>Let’s see what this results in:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*_Tfdoc6IsY_55wQCyfpHwg.png" /></figure><p>So, here I have added the data_structure_models package (Another Package developed by me) globally onto my system. I can now access the Package from any project in my system without needing to install it locally for every project.</p><h3>Further Operations with Packages</h3><p>Many a time, you will get warnings about your project packages for being out of date or for being a deprecated version. If we want to check if the Packages need to be updated, we can run a simple command:</p><pre>$ npm outdated</pre><p>If we want to check for Packages that need to be updated globally, we can simply run the same command with a -g flag:</p><pre>$ npm outdated -g</pre><p>If you want to remove a Package from your Project, you can simply do that with an npm uninstall command. Not a bit of surprise here! Let’s uninstall the moment package that we installed earlier:</p><pre>$ npm uninstall moment</pre><p>Let’s see what this yields:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*vkqtoiPY1OD_cuY3HCfOSg.png" /></figure><p>This is how easy it is to add, remove and update packages on NPM. Now before we move on with some further advanced topics, we can take a look at the semantic versioning of NPM packages. Let’s take a look at our package.json file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*rzMX5dOBKwunHsUad33czA.png" /></figure><p>If you take a look at the corona-tracker-stats package in the devDependenices, you can take a look at its version: 1.0.1. The first number is usually the major new releases like a full new version of the software. The second number is minor releases like adding new functions to this major release or a new tool. And finally, the last numbers are patches and fixes, usually for bugs and such. Let’s install a package named JSON and take a look at the package.json file:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/1*F-1aEMrACxc3aIW44rZnOA.png" /></figure><p>Here we can see the version of the JSON package and see the Semantic Versioning that has been applied to denote the version of the package. Another tool that helps us manage our dependencies is the package-lock.json file. Every developer that is creating, managing, and publishing new packages on NPM, must follow versioning and it is quite common that packages often rely on each other.</p><p>So, in a Production Environment, it is quite common that these packages might break and cause a Build Failure. This is where the package-lock.json file comes to the rescue. When we install NPM packages, the package.json serves as the input while package-lock.json serves as the output. This new file will always ensure that whenever we are installing a pre-built project, the dependencies don’t break while building. Let’s say we are using a package whose version is 4.5.3 as used in our project but it has been updated to 4.7.2.</p><p>The package-lock.json file is instrumental in adding the packages that we have originally used in our project without much ado. Do note that all the packages that are installed in your project, are kept in a separate node_modules folder which is a huge bundle of all the Packages and Scripts required to keep your project up and running. Nevertheless, to say, it is sometimes a nightmare to maintain.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*g1923zaDxSh-2jS7QugEDw.jpeg" /></figure><h3>Advanced Topics</h3><p>NPM keeps a cache of your modules so that you don’t need to install them every time for your projects. If you are trying to install a module that should be working, but is not installed properly you can go with npm cache clean which will clear all your cache. Sometimes, the command might not work so you need to use a — force flag to remove all the cache.</p><pre>$ npm cache clean --force</pre><p>Cleaning the Cache is a troubleshooting step and must be used only when necessary. Another command that we can take a look at is npm audit command which will check the dependencies of your project and makes sure they are safe to use. Whenever you install a new package, the command npm audit runs automatically and tells you if there are any issues with the package. You can simply run an audit command using:</p><pre>$ npm audit</pre><p>This is what the command yields on my Command Line:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*GGkoFdLrOvSZXKdqmMxrOg.png" /></figure><h3>What is NPX?</h3><p>Have you ever experienced installing CLI tools from npm packages that you use only once in order to create new projects? Some good examples are Angular CLI or create-react-app. Suppose I want to develop an Angular Project without installing the CLI tool. In that case, I will be going with NPX instead of NPM to temporarily install the package while we create a new project. Let’s try it out installing the NPX first:</p><pre>$ npm i -g npx</pre><p>If you have the latest Node version, then NPX has already been pre-installed and you can just run this command, to verify if the NPX has been installed:</p><pre>$ npx --version</pre><p>Let’s try out installing the Angular CLI tool and initializing a new application:</p><pre>$ npx -p @angular/cli ng new myFirstApp</pre><p>Now we have got the Angular App up and running and we did it without installing the actual tool. NPX, in turn, makes NPM a lot nicer and easier to work with since you don’t always need to install global packages every time you need for development and testing.</p><h3>Conclusion</h3><p>This article was all that you need to know about NPM as a Javascript or a Web Developer so that you can easily work with Packages. The basic advantage of having NPM is the flexibility it gives Developers to manage the Project Dependencies irrespective of the System Environment. Before you start off with any new JS Project and wish to have Third-Party Packages, look no more. NPM can be your best buddy here. And if you are stuck, somewhere, don’t panic: Refer back here which has everything you need to know about NPM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*NURMYBgQnm7fqdrK1Azbpw.gif" /><figcaption>Leave a Clap</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=39b21d26e47d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tesseract-coding/the-node-package-manager-guide-39b21d26e47d">The Node Package Manager Guide</a> was originally published in <a href="https://medium.com/tesseract-coding">Tesseract Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Machine Learning Pipeline]]></title>
            <link>https://medium.com/tesseract-coding/building-a-machine-learning-pipeline-2065b3578d08?source=rss-1e6bdd4e0a76------2</link>
            <guid isPermaLink="false">https://medium.com/p/2065b3578d08</guid>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[text-processing]]></category>
            <category><![CDATA[naive-bayes]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Harsh Bardhan Mishra]]></dc:creator>
            <pubDate>Fri, 05 Jun 2020 13:34:01 GMT</pubDate>
            <atom:updated>2020-06-05T13:34:01.091Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1YI9twzDtOoOYfHf" /><figcaption>Photo by <a href="https://unsplash.com/@mbenna?utm_source=medium&amp;utm_medium=referral">Mike Benna</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Have you ever got a message or Mail exclaiming that you have won a Prize Money, for a competition that you never participated in, or a trip to some foreign destination, just out of the blue? It happens with every one of us, but the thing that underlies beneath them is a malicious intent to dupe us and to make easy money from a gullible public. The rise of Internet and Mobile Networks have heralded a new revolution in the Cyberspace where advertisers are utilizing new means to reach the public, and sometimes these means are placed in the wrong way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Jj4BozDfiKXasozb" /><figcaption>Photo by <a href="https://unsplash.com/@yapics?utm_source=medium&amp;utm_medium=referral">Leon Seibert</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>People often get fooled by these contents which usually carries an advertisement that places a misplaced notion on the product or service they are offering. To counter this, messages were often classified as <strong>“Spam”</strong>, which served an explicit warning to people about their content. While the messages which were regarded as useful for the receiver were classified as <strong>“Ham”.</strong></p><p>With the rise of Artificial Intelligence and the usage of Machine Learning in multiple use-cases, many corporations and E-Mail service providers started utilizing Machine Learning Models to classify these messages or Mails as <strong>“Spam” </strong>or <strong>“Ham”. </strong>In this article, we will be covering how we can develop an End-to-End Machine Learning Model to serve as a use case to help us classify messages into <strong>“Spam” </strong>or <strong>“Ham”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XqoW5RHjiMiN9h2a" /><figcaption>Photo by <a href="https://unsplash.com/@charlesdeluvio?utm_source=medium&amp;utm_medium=referral">Charles Deluvio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>What is an End-to-End Machine Learning Model?</h3><p>In simple terms, End-to-End Machine Learning is a term used to denote on how we can serve our Machine Learning Models into Production. It allows us to serve our model directly onto a server to reach the customers through the client-side while bypassing all of the procedures that we do in Development.</p><p>Majority of Machine Learning Practitioners and Students, prefer to develop and model their Data on an interactive environment like Jupyter Notebook or Azure Notebook. They formulate their hypothesis, load the Dataset, clean and pre-process it before they move ahead with using specific libraries to model the Data. This means that an original input, let’s say <strong>X</strong>, goes through multiple processes to reach the end-result <strong>Y. </strong>So how does an End-to-End Machine Learning Model helps us?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*wMVIJf7J9tZnDIbOQkMBEA.png" /><figcaption>Image Credits: Datanami</figcaption></figure><p>It allows us to directly take an input <strong>X</strong> to make a prediction <strong>Y</strong>, without needing to go through any intermediate process in the midst. Developing an End-to-End Machine Learning Model, allows us to develop scalable models which can be served to multiple users and allows real-time processing.</p><p>While in traditional Machine Learning, the historic data is collected, pre-processed, modelled using a specific algorithm and then compared for the Scores, an End-to-End Machine Learning Model prefers to collect the data, stream it for features and use the existing models to generate some results. In this project, we will be developing a Machine Learning Pipeline which can be directly served to an application and help us check if a message is <strong>“Spam” </strong>or <strong>“Ham”.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*SaOSGiX-UWg2eX27JN7X9w.jpeg" /></figure><h3>Data Collection and Exploratory Data Analysis</h3><p>We will be using the SMS Spam Collection Data Set from <a href="https://archive.ics.uci.edu/ml/index.php">UCI Machine Learning Repository</a> which is a collection of 5574 Text Messages for Classification and Clustering purposes. The messages are suitable labelled as “Spam” or “Ham” and we can use it to model our Machine Learning Model.</p><p>Let’s first load our Dataset using <strong>Pandas</strong> Library that is a popular library used for generating Dataframes and preparing the Data for final modelling.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/023d34809fcb66c292fdf55ca12c5ec4/href">https://medium.com/media/023d34809fcb66c292fdf55ca12c5ec4/href</a></iframe><p>We have divided our Dataset into two columns: <strong>labels</strong> and <strong>messages. </strong>The <strong>label</strong> denotes whether the message is “Spam” or “Ham” while the message is the actual message for which the label has been kept. Once we have loaded our Dataset, we can move forward with some Exploratory Data Analysis to help us better analyze our dataset and move forward with the final implementation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*DPlpDiBvIWdbkcaRJSQpZQ.png" /></figure><p>Let’s do some Exploratory Data Analysis before we move forward with our final implementation. We can check out some of the parameters in our Data using Pandas. Let’s check out the length of the text:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/083ca9f5c3f3027e3bc28b8eded341aa/href">https://medium.com/media/083ca9f5c3f3027e3bc28b8eded341aa/href</a></iframe><p>This is what we get as the output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OAIUFEec_UYeGNqDcydM6w.png" /></figure><p>Let’s go forward and check out the length of “Spam” and “Ham” messages each:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6e8098787753e93fe155fe8087e73c08/href">https://medium.com/media/6e8098787753e93fe155fe8087e73c08/href</a></iframe><p>In the below graph, we can see that the length of the message is an essential parameter to judge whether a message is a spam or not. Here we can see that Spam messages tend to have more characters compared to Ham messages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*deH7AxPu4So8mgzccqDLNA.png" /></figure><p>So we have sorted out our Feature Engineering, so we can move forward with pre-processing our Dataset and fine-tuning it for our Data Modelling.</p><h3>Data Pre-Processing</h3><p>In this Dataset, all the input variables are in the form of Strings. Machine Learning Algorithms, on the other hand, tend to use numerical vectors to model the data and generate the predictions. In this case, we will be converting our whole dataset into a numerical value that can be processed by our Machine Learning Model easily.</p><p>To make this possible, the raw messages which are a sequence of characters is converted into a sequence of numbers and for this, we will use the <strong>Bag-of-Words</strong> approach where all the characters are denoted by one number. To make this possible, we will first go through removing <strong>Stopwords</strong> from our strings. Stopwords are words that are used by people in general and do not hold any significance in Data Modelling Operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/837/1*Y7fctFT9plCNtVSach8gEQ.png" /><figcaption>Stopwords in English. Credits: XPO6</figcaption></figure><p>Let us define a function that can take in any string and remove the Stopwords and Punctuations from it. We will be using the <strong>NLTK </strong>library for the same to remove the stopwords for this purpose.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5feddf4e6a85563a2f4661783ba4c31e/href">https://medium.com/media/5feddf4e6a85563a2f4661783ba4c31e/href</a></iframe><p>Now that we have removed the Stopwords and Punctuation from the Dataset, we can move forward towards normalizing the Dataset. We will be now converting all the words in the Dataset to a form which can be operated on by Scikit-Learn Machine Learning libraries.</p><p>We will be doing this, in the form of three well-defined steps: First, we will calculate the <strong>term frequency</strong> which denotes the number of times a word occurs in a dataset. Next, we will weigh the counts so that the frequent tokens get the lower weigh, which is called the <strong>inverse document frequency. </strong>Now we will convert the vectors to unit length, to abstract from the original text length which is <strong>L2 Norm</strong>.</p><p>Let’s use Scikit-Learn’s <strong>CountVectorizer</strong> to convert the Dataset into a sparse matrix and visualize how we have converted the String into a Vector:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c307894be0e0df453076fecc930a5a8/href">https://medium.com/media/3c307894be0e0df453076fecc930a5a8/href</a></iframe><p>We have used the <strong>transform() </strong>function the entire Dataframe of the messages into a large, sparse matrix. We can now use another methodology named <strong>TFIDF </strong>or <strong>term frequency-inverse document frequency </strong>to check and highlight the importance of any word in a collection of the corpus. So, let’s go ahead and implement this with our Dataset:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/238e1165e23c37892938afbd350475cb/href">https://medium.com/media/238e1165e23c37892938afbd350475cb/href</a></iframe><p>We have now normalized our whole Dataset and we can finally move forward with our Data Modelling. We will also be building a pipeline to serve our Model finally which is the final purpose of our article.</p><h3>Data Modelling</h3><p>For the purpose of Data Modelling, we will be using a Naive Bayes classifier. The reason why we are using Naive Bayes Classifier is that it is quite simplistic and it helps us to achieve results that outperform many complex algorithms, especially in Classification Problems. Here we can use the Naive Bayes classifier for our purpose, by developing a distribution over words that can help us simplify our task at hand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5OROQqYWuC6to-5T9OMtXw.jpeg" /><figcaption>Credits: becominghuman.ai</figcaption></figure><p>We will implement the Naive Bayes using the <strong>Scikit-Learn</strong> implementation for the same which will help us write minimal code for the task at hand:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d04c55a8b6a4e915a418b278d5fd6ea4/href">https://medium.com/media/d04c55a8b6a4e915a418b278d5fd6ea4/href</a></iframe><p>Pretty easy with that? We modelled our Pre-Processed and clean Dataset in just two lines of code! Let us now evaluate the performance of our model that we have developed using yet another Scikit-Learn’s Library: <strong>classification_report.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/680ba0ca18d8fbc6dc066a254332371f/href">https://medium.com/media/680ba0ca18d8fbc6dc066a254332371f/href</a></iframe><p>We can now check out the Classification Report for the model that we have prepared. However, we have just evaluated on the same dataset that we have just trained the model on. We will now follow another methodology where we will test our model by dividing (or splitting) the dataset into two parts: <strong>Train </strong>and <strong>Test.</strong></p><p>Let’s use another Scikit-Learn Library, known as <strong>train_test_split, </strong>to split our dataset into two parts. We can use the 20% of the dataset for testing while the rest 80% can be used for training the dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6d17c932866ecd143e21366917f1d37b/href">https://medium.com/media/6d17c932866ecd143e21366917f1d37b/href</a></iframe><h3>Preparing the Pipeline</h3><p>Let us now arrive at the main part: <strong>Preparing our Pipeline to serve our Model. </strong>In the previous steps, we have loaded the dataset, pre-processed and cleaned the Dataset but now we need to move ahead with creating a Pipeline. A pipeline will help us automate all our workflow in one single steps and a few lines of code, so let’s try it out.</p><p>We will be leveraging the Scikit-Learn’s <strong>Pipeline </strong>library to model our dataset and develop a pipeline. This can be treated as an Application Programming Interface (API) which can be directly served to some Web Application and which will allow us to perform the computations real quick.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9b3ade04aec354a5061ab3a98e680372/href">https://medium.com/media/9b3ade04aec354a5061ab3a98e680372/href</a></iframe><p>In a few easy steps, we have now set our Pipeline Model which can now be served with an API, to some Client-Side Interface and we don’t need to take care about all that background processes anymore.</p><h3>Conclusion</h3><p>In this article, we have covered a lot of aspects about why Pipelines are needed to serve End-to-End Machine Learning Models and how you can classify <strong>“Spam” </strong>or <strong>“Ham” </strong>messages using a Naive Bayes Algorithm. The reason why Naive Bayes works so well is that it works on the assumption that the features of the dataset are independent of each other. We have also got to know on how you can serve the Model using a Pipeline and in further articles, we will get to know on how you can directly serve it using a Flask API on a Client-Side Interface while learning the basics of Flask on the way.</p><p>Check out the Code <a href="https://github.com/HarshCasper/Brihaspati/blob/master/Spam-Ham%20Classification%20Pipeline/Spam-Ham%20Classification%20Pipeline.ipynb"><em>here</em></a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/310/1*NURMYBgQnm7fqdrK1Azbpw.gif" /><figcaption>Leave a Clap</figcaption></figure><p><strong>~ Harsh Bardhan Mishra</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2065b3578d08" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tesseract-coding/building-a-machine-learning-pipeline-2065b3578d08">Building a Machine Learning Pipeline</a> was originally published in <a href="https://medium.com/tesseract-coding">Tesseract Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Five must- known concepts to get started with Javascript Development]]></title>
            <link>https://medium.com/tesseract-coding/five-must-known-concepts-to-get-started-with-javascript-development-18663996abdd?source=rss-1e6bdd4e0a76------2</link>
            <guid isPermaLink="false">https://medium.com/p/18663996abdd</guid>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript-development]]></category>
            <dc:creator><![CDATA[Harsh Bardhan Mishra]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 06:11:07 GMT</pubDate>
            <atom:updated>2020-06-01T06:11:07.577Z</atom:updated>
            <content:encoded><![CDATA[<p>Before we start talking about some of the features of Javascript as a language, it would be no heresy to say that you all must have heard about <strong>Javascript </strong>before. And there are good reasons for that. According to Stack Overflow’s <strong>2020 Developer Survey</strong>, Javascript has remained as the most popular and commonly used language for eight times in a row. Even the Github’s <strong>State of the Octoverse</strong> has ranked Javascript as the most widely used language and has remained consistent at its place since 2014. Well, what makes Javascript so popular after all?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OyQkQyHK_sGNg5QD" /><figcaption>Photo by <a href="https://unsplash.com/@bharat_patil_photography?utm_source=medium&amp;utm_medium=referral">Bharat Patil</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The development of Web Technologies and Frameworks has further heralded the development of Javascript. The rise of niche Front-End Frameworks like React and Angular has paved a new path in Front-End Development and frameworks like NodeJS and Express are icing on the cake which has further boosted the Javascript community. Many developers are now looking for roles in Javascript development and there are right reasons to do so: As a language, it provides capabilities to develop both <strong>Client-Side </strong>and <strong>Server-Side </strong>interfaces.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/0*ELLSKm1lsXIKGqem.jpeg" /></figure><p>If you have started with Javascript, there are many things for you to learn before you jump into Frameworks and Libraries. But that is not always the case. People tend to straight away jump into development with Javascript, and they forego the need for getting the basics right. In this article, we will be delving deep into seven of the Javascript concepts that you need to get right before you get started with Javascript development.</p><h3>1. Arrow Functions</h3><p>The most obnoxious way to write functions in Javascript is the traditional way, where we declare a function somewhere, define it later and then we call it. But what if, we need an inline function and we need to use them just once. To write such anonymous functions and to make our functions more readable, we can bank on a new feature that the <strong>ES6 </strong>provides us: <strong>Arrow Functions.</strong></p><p>Now there are multiple advantages of using Arrow Functions in your code. The most obvious ones are that it makes your code more readable, concise and you can write regular functions as well with shorter syntax. Sounds cool?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00ee24e2aa103854217cad0f696a2b80/href">https://medium.com/media/00ee24e2aa103854217cad0f696a2b80/href</a></iframe><p>As you can see that you can easily utilize the Arrow Function to simplify your function definition and usage further. If you are having only one parameter in your function definition, you can do that without needing any brackets.</p><p>For developers who are just starting to familiarize with ES6 Syntax, this transition might seem difficult. But you can just follow two simple steps to convert your regular function into an Arrow Function:</p><ol><li>Remove the <strong>function() </strong>keyword.</li><li>Add a <strong>=&gt; </strong>just after the ()</li></ol><p>Arrow Functions are only callable and not constrictive, unlike Regular Functions. This simply means that you can use the <strong>new</strong> keyword with Regular functions but not with Arrow Functions. Before you work with Arrow Functions, remember that they are anonymous functions. If you want to call an Arrow Function you can set it in a variable like <strong>const, var </strong>or <strong>let</strong>.</p><h3>2. Importing and Exporting Modules</h3><p>Let’s imagine a file that you have constructed for your purpose, using Javascript. This file consists of a lot of functions that you have defined and now you want to use them in other files as well. Now, this is actually the best way of developing new applications, where you divide your whole codebase in wholesome chunks and then import and export them as you like. With Javascript, this whole process is simplified and you can access your files using these simple keywords: <strong>import</strong> and <strong>export.</strong></p><p>Let’s write a block of code in our file <strong>math-operations.js</strong> and export a module to add two numbers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0f786b80958b202b4ae82be54873a0c/href">https://medium.com/media/f0f786b80958b202b4ae82be54873a0c/href</a></iframe><p>But how are we going to import that block of code into some other file? Well for this operation, we will be using the <strong>import</strong> keyword and the best part is you don’t need to rewrite any of the code. Sounds pretty easy?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1bbde6bd1ff0f984bfa633592272b5b2/href">https://medium.com/media/1bbde6bd1ff0f984bfa633592272b5b2/href</a></iframe><p>If you are having difficulty in understanding the purpose of importing and exporting modules, you can understand it in a slightly different manner. In Javascript, a module is simply an object, variable or function that you can export using the <strong>export</strong> keyword. You can export multiple modules but there should be only one default export.</p><p>The imports are made using the <strong>import</strong> keyword and it is executed by placing, the exact name between curly braces. Remember to check out for the correct path if you are importing locally otherwise, you can use an absolute name to check out your <strong>node_modules</strong> for the exact package.</p><p>Let’s see another example for exporting our package:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f56426dcaac9506d310b13f4996f295f/href">https://medium.com/media/f56426dcaac9506d310b13f4996f295f/href</a></iframe><p>We can know import the packages by simply importing them:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6f143e66a5e00872aba7cf6cb62513bd/href">https://medium.com/media/6f143e66a5e00872aba7cf6cb62513bd/href</a></iframe><h3>3. Promises in Javascript</h3><p>Well, it sounds pretty strange but we have this concept of promises in Javascript as well. To handle multiple tasks, all of which depends on the completion of each other, we can use multiple callbacks and end up in something we call a <strong>callback hell.</strong> To resolve this we have got <strong>promises</strong> in Javascript, that makes an asynchronous promise to do something.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/0*UPFgfl7Vie5Yju4M.png" /></figure><p>A promise can be simply understood as an object that consists of <strong>status</strong> and <strong>value. </strong>Promise serves as a constructor that takes a function as an argument with two parameters: resolve and reject. These two parameters determine the outcome of the promise.</p><p>Javascript is a single-threaded language, and therefore only a single piece of code can execute at a given time which has to run one after another. So before Promises, you’d probably been using events, async() and callbacks to get around this JavaScript feature. In Promises, we can only succeed or fail once.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6b184568275e37bbf56b4030c2c530c/href">https://medium.com/media/d6b184568275e37bbf56b4030c2c530c/href</a></iframe><p>In Promises, we can have three statuses:</p><ol><li>Initial Status is denoted as <strong>pending </strong>which is neither fulfilled nor rejected.</li><li>Fulfilled Status is denoted as <strong>fulfilled</strong> which means that the operation was successfully executed.</li><li>Failed Status is denoted as <strong>rejected</strong> which means that an error was thrown back.</li></ol><p>One of the best thing while working with Promises is that, it allows you to use <strong>Promise.resolve</strong> or <strong>Promise.reject</strong> with the exact value that you would want to represent.</p><h3>4. Variable Declaration in Javascript</h3><p>JavaScript is dynamically typed, that simply means that types can change at run time. Declaring variables with the <strong>var </strong>keyword allows us to simply overwrite the datatype of the variable without logging in an error. A new ES6 Syntax feature allows us to freeze the datatype of the variable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*72IRmXQFi-75FcZR.png" /></figure><p>The new keyword <strong>let</strong> allows declaring the variables and if we try to use the same variable name elsewhere, it will straight away throw an error. You can also <strong>use strict</strong> which enables a strict mode that can help catch us some common coding mistakes like accessing a variable without declaring it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6510be0f059a94b79bf010716006ebb6/href">https://medium.com/media/6510be0f059a94b79bf010716006ebb6/href</a></iframe><p>The one thing that you need to understand about the <strong>let</strong> keyword in Javascript, is that it follows the standard Scoping rules. The scope of any variable declared with <strong>let</strong> is limited only to that block of code.</p><p>You can also use the <strong>const</strong> keyword for declaring only read-only variables. This means that once a <strong>const</strong> keyword is used, we cannot reassign the value to it. Trying to reassign a variable with <strong>const </strong>will throw up an error.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43667b1960799b595fbba6217b66c74b/href">https://medium.com/media/43667b1960799b595fbba6217b66c74b/href</a></iframe><p>If you are starting up with declaring variables, you can start with using the <strong>const</strong> keyword for this purpose. You can later refactor your code and convert <strong>const</strong> to <strong>let </strong>once you need to reassign the variable.</p><h3>5. Map, Filter and Reduce</h3><p>Map, Filter and Reduce is one important concept that wraps your mind for once, but if you have got your basics right, it would be the most important concept in your Javascript arsenal. The purpose of Map, Filter and Reduce were properly explained in the following tweet:</p><h3>Steven Luscher on Twitter</h3><p>Map/filter/reduce in a tweet: map([🌽, 🐮, 🐔], cook) =&amp;gt; [🍿, 🍔, 🍳] filter([🍿, 🍔, 🍳], isVegetarian) =&amp;gt; [🍿, 🍳] reduce([🍿, 🍳], eat) =&amp;gt; 💩</p><p>Map, Filter and Reduce are used for Array transformation and can either perform their operations independently or they can be chained to each other. Let’s explore all three of them one by one.</p><p>A<strong> map </strong>is used to take a function and is then called on every other element of the array. It can create a new array from an existing one and call a function to operate on every single element of the array. Sounds pretty cool, isn’t it?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1289373960cf02fbbeafad52f634b81/href">https://medium.com/media/d1289373960cf02fbbeafad52f634b81/href</a></iframe><p>The map just loops over all the elements in the array, and transforms every element in the array and return it.</p><p>A <strong>filter </strong>takes every element in an array and applies a conditional statement to filter out the elements in the array. In this way, if we want some condition to be checked in the loop, we don’t need to loop through it entirely. We can just use the <strong>filter</strong> and extract the specific elements matching the condition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6d98a06b20a90564129b44806884148/href">https://medium.com/media/f6d98a06b20a90564129b44806884148/href</a></iframe><p>A <strong>reduce</strong> just loops over an entire array and convert it into something else by using a transformer function. This “something else” is referenced by you which is passed as a second argument and it can be used to “reduce” the entire array into something new which can be an object or a variable. Unlike map and filter, reduce takes four arguments:</p><ol><li><strong>Accumulator</strong></li><li><strong>Current Value</strong></li><li><strong>Current Index</strong></li><li><strong>Source Array</strong></li></ol><p>Let’s see an example of reduce:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f5ac4a1b386421cbfb234a302ecf140/href">https://medium.com/media/9f5ac4a1b386421cbfb234a302ecf140/href</a></iframe><p>The reasons why many Javascript Developer use map, reduce and filter so commonly is because they don’t have to loop through an entire array now and they can be chained to each other for easy-to-implement array transformation.</p><h3>Conclusion</h3><p>With this, we arrive at the end of some of the most important concepts of Javascript. There are furthermore features with Javascript in general and ES6 in particular that demands further insight and intuition but exceed the scope of this article. Javascript, as a language, is quite complex to understand at first and working around it, is quite difficult, even for Senior Developers, if the basics are not done right. Learning Javascript does not mean that you have to master everything before you move onto a framework or a library to work with. But essential skills in the basics are quite desirable and this is what has been addressed here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/492/0*9WWbOVFrY2lb5Pdr.jpg" /></figure><p><strong>~ Harsh Bardhan Mishra</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18663996abdd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tesseract-coding/five-must-known-concepts-to-get-started-with-javascript-development-18663996abdd">Five must- known concepts to get started with Javascript Development</a> was originally published in <a href="https://medium.com/tesseract-coding">Tesseract Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Dog versus Cat Classifier using Transfer Learning]]></title>
            <link>https://medium.com/tesseract-coding/creating-dog-versus-cat-classifier-using-transfer-learning-63cac5a8d3d8?source=rss-1e6bdd4e0a76------2</link>
            <guid isPermaLink="false">https://medium.com/p/63cac5a8d3d8</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[transfer-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Harsh Bardhan Mishra]]></dc:creator>
            <pubDate>Sun, 24 May 2020 12:13:35 GMT</pubDate>
            <atom:updated>2020-05-24T12:13:35.359Z</atom:updated>
            <content:encoded><![CDATA[<p>Dog versus Cat has been a standard Problem in Machine Learning and Computer Vision that aims to build a model that can predict if a picture contains either a Dog or a Cat. With the aid of the development of Neural Networks and Frameworks like Tensorflow and PyTorch in last few years, this problem was accelerated efficiently. In this article, we will build a Dog and Cat Classifier using Transfer Learning to develop a model that can predict if a picture if of a cat or a dog with appreciable accuracy. To develop this model, we will be using Oxford-IIIT Pet Dataset and Keras and will learn a lot of new concepts like Data Modelling, Pre-Processing and how we can augment the accuracy of our baseline model using Pre-Trained Models via Transfer Learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zf1neBbImm05LD3b" /><figcaption>The Cat and the Dog. Via <em>Unsplash.</em></figcaption></figure><h3>What is Transfer Learning?</h3><p>The idea and methodology behind Transfer Learning are quite simple: To use an existing pre-trained Neural Network’s knowledge on a new dataset which it has never seen before. Sounds easy?</p><p>The idea behind Transfer Learning started with AlexNet back in 2012 where it won the ImageNet Large Scale Visual recognition challenge. After AlexNet, many other pre-trained models came into the scene which outperformed AlexNet in terms of accuracy on ImageNet Dataset. Researchers conceptualized an idea to utilize these pre-trained models to train and develop new classifiers on a dataset that the pre-trained model has never encountered before. This technique was used to harness and transfer the learning of a previous model to a new dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/0*UKLOoshxDirtDQBv" /></figure><p>And surprisingly, Transfer Learning makes it quite easy for Researchers and Machine Learning Developers to train models on new datasets by just changing and modifying the last layer according to their needs. ImageNet Dataset has 1000 Output Classes. Fashion MNIST, on the other hand, has only 10 while our Dog-Cat Classifier has only 2. We can achieve this by changing the last layer of the model and freezing the pre-trained model by setting the variables to non-trainable.</p><p>This is done because, during the whole process of Data Modelling, we don’t want to change or update the useful weights of the pre-trained models in any way. If we randomly initialize the weights, the model is expected to underperform which we don’t desire in any way. So, this was a brief introduction to Transfer Learning.</p><p>To get started with the Code, it is preferred for you to kickstart it on Google Colab or Azure Notebooks as this will speed up your Development and Data Modelling time and you don’t need to worry about installing the Packages. Now we will start by downloading our Dataset and preparing it for our Data Modelling.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/0*t-Uazw5j4e1ZRCs8" /></figure><h3>Downloading the Dataset</h3><p>As mentioned before, we will be using the Oxford-IIIT Pet Dataset for our purpose and intent here to develop a Dog-Cat Classifier. We will be using urllib Library here to download the Dataset, which is a Python Library for opening and reading URLs. We will also import the necessary packages first so that we can streamline our development process. Let’s first download our Dataset from an Online Storage:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fc2d3f5bcb294acb2e4d9fc9864b9524/href">https://medium.com/media/fc2d3f5bcb294acb2e4d9fc9864b9524/href</a></iframe><p>In the above block of code, we have done two things:</p><ul><li>Declared the Necessary Packages we need to work with the Data.</li><li>Downloading the Dataset which includes the Images and Annotations.</li></ul><p>To download the Images and Annotations, we have used the urllib library and used annotations to point out the pictures in our Dataset which we will be using for our Data Modelling. We will be using the Matplotlib to show us some examples from our Dataset and to modularize our code, we have written everything in separate functions which we can call later for our purpose. This is our starting Boilerplate Code here and it doesn’t matter much if you don’t understand it. We will be diving deep into the more complex parts now.</p><h3>Data Pre-Processing</h3><p>After you have run the first code cell with the Code mentioned above, we can now pleasantly move onto the next steps. We will now be doing some Pre-Processing with our Dataset, and prepare the Data for our Modelling and Final Analysis. We can start this formally but first, let’s ensure that we have got Tensorflow installed on our environment and a GPU Available for our Data Modelling:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/13b11f0ffd8b368b6ce0b656e75f5eff/href">https://medium.com/media/13b11f0ffd8b368b6ce0b656e75f5eff/href</a></iframe><p>If you are using Colab, you can enable GPU by going to Runtime and clicking on, Change Runtime. You can enable the GPU Option by clicking on Hardware Accelerator and clicking GPU.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/0*Oyf9ee-roG06OqeO" /></figure><p>Now that we have our Dataset downloaded and we have done the necessary checks, we can move ahead with the problem. Since this is a Binary Classification Problem we will be using annotations to point out to our samples in the Dataset. Our Dataset has been downloaded onto the Data directory so now we will be writing some code to properly annotate Dog and Cat Pictures. If you take a look at your Dataset, you will find that there are annotations and images. In the annotations, you can see a list which is your list of files and trainval and test which holds our Training and Testing Dataset. These contain Image Names which we will be using to annotate our Dataset.</p><p>We will now write some code to map the Index to Class and vice versa and we will write some extra code to extract our annotations and print the count of Training Examples and Testing Examples:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2991f0ce84df13a48030a6176a141cb7/href">https://medium.com/media/2991f0ce84df13a48030a6176a141cb7/href</a></iframe><p>Basically, the Class to Index and Index to Class, means that the pictures annotated as 0 belongs to a Cat while the ones annotated as 1 belongs to a Dog. Now that we have extracted the annotations, let’s move next to get the images as well.</p><p>Now we will write some code to get a Random Batch from our Images. We will be preprocessing our Dataset here using Keras. The primary purpose of Random Batch is to take the annotation dictionary and return some randomly selected examples from our Dataset.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec3495a647e142029550a7c3b82c557e/href">https://medium.com/media/ec3495a647e142029550a7c3b82c557e/href</a></iframe><p>What did we do here?</p><ul><li>We took the arguments in our function as the Annotation Dictionary and the Batch Size. The Annotation Keys are converted into a list and the length is stored.</li><li>We used Numpy’s Random Function to return some randomly chosen examples from our Dataset.</li><li>The images are stored onto an Array x where we pass the batch size as the parameter and take 128x128x3 as the Image Size. The reason why we are using this is that we will be using MobileNet as our baseline model and this is one of the Image Options that are available for us and is the smallest size the Image is available for.</li><li>We will store the Class Output onto the Array y where we store either 1 or 0 which will be our Class Output.</li><li>Now we will run a loop to return the Image Examples and not just the Labels and Annotations. We will extract the Image from the Images directory and passing the key index of Image.</li><li>We can use the Preprocessing Helper Function defined in Keras by calling in tf.keras.preprocessing.image and then passing the Image Path and the Channel size which is 128x128x3.</li><li>We will use another Keras Function to convert the Image to a Numpy Array and for this operation, we will use tf.keras.preprocessing.image.img_to_array just because our model is expecting data in a multi-dimensional format.</li><li>We can further preprocess our input dataset by using another Keras function tf.keras.applications.mobilenet_v2.preprocess_input. This is primarily done to change the Mean Standard Deviation of our Dataset so that it is easy to achieve the Global Minima.</li><li>At last, we can write some code to expand our dimensions to return the batch size according to the size that we have passed in the function. Finally, we will pass the array to x and the keys to y. We can then return both x and y and end the function block.</li></ul><p>Now that we have written the function to return a random batch, let’s try it out. We will write a small block of code where we will call our previously defined function and display the examples using the functions that we defined earlier:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63eaeb287a96330790f2837731825595/href">https://medium.com/media/63eaeb287a96330790f2837731825595/href</a></iframe><p>This will show our output as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/0*7CVofBTaP5lkNHtl" /></figure><p>It will show random batches of our Dataset so we can expect to see no similar pictures here. This will come handy next when we have completed the Data Modelling and need to see some results. So we have learnt how we can pre-process our Dataset using Keras and how we can write some code to generate Random Batches. Now we will move ahead with Data Modelling and preparing our Model from a MobileNet v2 Pre-Trained Model.</p><h3>Data Modelling</h3><p>For the purpose of this article, we will be using MobileNet v2 as our Baseline Model to perform Transfer Learning. MobileNet is a popular Pre-Trained Model that has been trained on the ImageNet Dataset. Training a model akin to MobileNet, which has millions of parameters is computationally expensive and takes a lot of time and to save the time and increase the accuracy manifold, we will be relying on Transfer Learning for our purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*9kNnrfRD1ciySzPI" /></figure><p>Let’s download the MobileNet v2 from Keras and we have to specify a few parameters as well. Let’s write this simple block of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/705a442cdbaeed62a8d9112d993f9cd1/href">https://medium.com/media/705a442cdbaeed62a8d9112d993f9cd1/href</a></iframe><p>We are setting include_top to False so that we don’t modify any of the existing layers and effectively freeze them. We will specify the input shape since this is a Binary Classification problem and MobileNet can classify well up to 1000 Classes. We will also convert our pooling to average so that a Four-Dimensional tensor can be converted to a Two-Dimensional one. We will also specify the pretrained weights, which is the main part here.</p><p>We will get the whole MobileNet architecture summarized here and take no issues if you don’t understand it much. We will be leveraging this architecture to develop our own model. We have got here more than two million trainable parameters and now we will be creating our own model on top of this. So let’s get started with some code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae26a6fe7c57fa8697edbf013c3d32cf/href">https://medium.com/media/ae26a6fe7c57fa8697edbf013c3d32cf/href</a></iframe><p>Here we have initialized our model, so let’s discuss in points on what we did here:</p><ul><li>We will be using a Sequential Model from Keras. This will define how the model will be laid down in Stack Layers.</li><li>We will set the MobileNet architecture that we downloaded as our first layer and then we will set the Dropout Layer with 0.5 as the Dropout Rate.</li><li>Our Final Layer will be a Dense Layer and we will use Sigmoid as our Activation Function here.</li><li>We will then set the Trainable Layers to False so that we don’t train them from our side and then we will pass a model.compile() function with a Binary Crossentropy as our Loss Function and an Adam Optimizer.</li><li>We will then move forward to creating the Model and printing the Model Summary.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xXlDLdmgyfCeoeu4" /></figure><p>Once we have done these steps, we can see the Model Summary on the Screen. We can see that we have some 1,281 Trainable Parameters and the rest, from MobileNet, is converted to Non-Trainable. We will now write some code before we kickstart our Model and start the Training Process.</p><p>We will first write a Data Generator Function which can take in the Batch Size and Annotation as function parameters and pass the Data. We can use this in our Fit Generator Function. We will write a loop which can fetch random bathes from our Dataset:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc5178b2b14ae677d8dec2ab79a1c4b2/href">https://medium.com/media/dc5178b2b14ae677d8dec2ab79a1c4b2/href</a></iframe><p>We will now define the batch size along with other necessary parameters like steps per epoch and validation steps. So, let’s write some code for that:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be87e9ed6c2b942f03170c2cc1c3bce6/href">https://medium.com/media/be87e9ed6c2b942f03170c2cc1c3bce6/href</a></iframe><p>Now we will fit our Model by using the fit_generator() function and we will be using the data_generator() function where we will pass the batch size and Training Annotation. We will also define the Validation Data and pass the batch size and Testing Annotation. We will also define the Validation Steps and Steps per epoch and we will run one epoch. We are running the whole model for one epoch because we already have pre-trained weights and our model needs to go through all the examples just once.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/96886b9bb8f4f24d3f22fe98b2415c24/href">https://medium.com/media/96886b9bb8f4f24d3f22fe98b2415c24/href</a></iframe><p>We are using the %%time Magic Function to time the Code Cell. This might take a few seconds or minutes to configure and train and we can see that have achieved a Validation Accuracy of 94.35%.</p><h3>Predictions</h3><p>Now that we have completed our Training Part and the Validation Accuracy would be anything above 90%. The main advantage of using Transfer Learning and a Pre-Trained Modle is that we don’t need to train our model for long. We can just have Pre-Trained Weights and we can configure the Input Layers as per our requirements and the Dataset that we have in hand. So, let’s visualize the results and see what we have got. We will write a small block of code to get some random examples on which we can predict whether the picture belongs to a Cat or a Dog using our trained model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6a418424b63f0f1f0f85cd56f768dec8/href">https://medium.com/media/6a418424b63f0f1f0f85cd56f768dec8/href</a></iframe><p>We will get this result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/0*bbRKKunB__Su0KT6" /></figure><h3>Conclusion</h3><p>In this article, we have discussed a lot of things and finally built our own Binary Classifier using Transfer Learning to classify pictures of Dogs and Cats. We have also learnt on how you can utilize these concepts to work with Pre-Trained Models and how you can modify the Input Size as per your requirements. To summarize, we have explored these things:</p><ul><li>What is Transfer Learning?</li><li>How can Transfer Learning be used on new Datasets?</li><li>Pre-Processing the Dataset.</li><li>Data Modelling with Transfer Learning and Pre-Trained Weights.</li><li>Visualizing the Results.</li></ul><p>What’s next? You can use the necessary takeaways from this Article and utilize Transfer Learning on some new Datasets. You can also start exploring some new Pre-Trained Models like VGG16 which I used to create a COVID-19 Classifier <a href="https://github.com/HarshCasper/Brihaspati/blob/master/COVID-19/COVID19-XRay.ipynb"><strong>here</strong></a>, Mask R-CNN and YOLOv2. <em>Best of luck with your future endeavours!</em></p><p><em>You can view the code </em><a href="https://github.com/HarshCasper/Brihaspati/blob/master/Cat%20and%20Dog%20Classifer/Cat_and_Dog_Classifier.ipynb"><strong><em>here</em></strong></a><em>!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*I_86FvGzNacG_G5c" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63cac5a8d3d8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/tesseract-coding/creating-dog-versus-cat-classifier-using-transfer-learning-63cac5a8d3d8">Creating Dog versus Cat Classifier using Transfer Learning</a> was originally published in <a href="https://medium.com/tesseract-coding">Tesseract Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Natural Language Processing]]></title>
            <link>https://medium.com/analytics-vidhya/introduction-to-natural-language-processing-3c9cb9104b5e?source=rss-1e6bdd4e0a76------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c9cb9104b5e</guid>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[natural-language]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Harsh Bardhan Mishra]]></dc:creator>
            <pubDate>Sun, 08 Mar 2020 03:41:13 GMT</pubDate>
            <atom:updated>2020-03-08T12:55:46.770Z</atom:updated>
            <content:encoded><![CDATA[<p>Natural Language Processing or simply abbreviated as NLP is a highly specialized branch of Artificial Intelligence and Machine Learning that deals with understanding the human natural language. Natural Language Processing has paved a new path into the ever-growing use-cases of Artificial Intelligence in Real-Time Applications by expanding the horizon in the field of Speech Recognition, Sentiment Analysis, Topic Segmentation and much more. Today Natural Language Processing is aiming to help machines understand how human speak and understand their vocabulary and intent which can be then used in a variety of real-world applications with a primary focus on the user itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FGHtb_niL0g-kbK3" /></figure><p>Natural Language Processing has since long considered as computationally expensive since Human Natural Langauge is neither uniform nor subtle, especially with grammatical errors and improper sentence structure adding to the woes of NLP researchers. Today with the availability of a wide variety of Libraries and Datasets, performing NLP has become a cake-walk since they catalogue everything from grammatical mistakes and word synonyms.</p><p>However, Natural Language Processing is a deep and highly specialized area and one that is still a hotbed of research especially with newer algorithms such as LSTM (Long-Short Term Memory), Recurrent Neural Network, Convolutional Neural Network which are considered far efficient in analyzing and representing Human Language.</p><p>Before moving onto the technicalities of Natural Language Processing, we still need some basics to cover. All Human Texts and Speech consist of stopwords which are nothing but media entities, commonly-spoken words, punctuation, slangs and more which contribute to the noise that is present in the text. Before analyzing any text for processing, our first step would be to standardize our text by Text Preprocessing. Text Preprocessing can be simply defined as the entire procedure that is utilized to make the text noise-free and fit for Data Analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*4l18D7GTtxcjucRy" /></figure><p>After Text Preprocessing, we must move onto the Normalization which can be simply defined as the process of converting high dimensional features into low dimensional spaces. Normalization is seen as an optimum solution to various woes that are associated with high-level data. A good example of why Normalization is necessary can be understood that an English Text might consider multiple variations of the same word, which could be its Participle, Paste/Present/Future Tense and more. Lexicon Normalization helps tackle the problem by reducing the words to its roots.</p><p>The data is later shuffled to decrease the variance and to ensure that the model does not overfit the data. This process is followed by one of the most important processes in Natural Language Processing: Feature Extraction. Since Machine Learning Models only understand Numerical Data, the features are extracted from the text and vectorized which is then converted to a numerical form that the Machine Learning Algorithm can understand. Text Features can be extracted via various techniques some of which are N-Grams, TF-IDF Model and more. In this process, the NLP Program tokenizes the text and features are extracted and saved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*TtTUFqlBbeyCFoKv" /></figure><p>Now the Textual Data has been preprocessed and converted into Numerical Format, now is our time to apply a Machine Learning Algorithm. In the case of a Supervised Learning Problem, the most popular Use-Cases are Prediction Problems, like Gender Classification which we are going to discuss in this article. In case of an Unsupervised Learning Problem, segmentation and clustering can be applied to the vectorized data. Now that we are aware of the basics of Natural Language Processing, let us move onto a popular Natural Language Processing Problem which will be to predict the gender of a person using their name.</p><h3>Predicting the Gender of a Person using Machine Learning</h3><p>In this problem, we are going to predict the Gender of a Person using Machine Learning and Natural Language Processing. We are going to utilize an Open-Source Dataset and Naive Bayes Machine Learning Algorithm, which is a popular Machine Learning Algorithm for Classification Purposes. Let us start:</p><ol><li>We will first Import the necessary packages: NLTK (Natural Language Tool-Kit) which is a popular library available for Natural Langauge Processing and Naive Bayes Classifier from Scikit Learn Machine Learning Library.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4H0OEcYKtGgckFZR" /></figure><p>2. Next, we will download our dataset from NLTK which consists of large number of names that are labelled as “Male” and “Female”. We will import the dataset in our code and then we will upload the dataset in a data frame. The Dataframe is randomly shuffled to eliminate overfitting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*f_5kD1a0NkSgKXc-" /></figure><p>3. Now we will come to one of the most important part of any Machine Learning Algorithm Implementation: Train-Test Split. Train-Test Split is to divide the dataset into a proportion to allow some part of the data to be used for training the model while the other part of data to be used for testing the accuracy of the model. Here we will split our dataset into three parts: Train Features, Devtest Features and finally the Test Features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Hr7wOI6FB9iyYa0I" /></figure><p>4. Now we will implement the Naive Bayes Machine Learning Algorithm bypassing the Training Dataset to the algorithm. We will print the accuracy of our model on Test Features and Devtest Features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Fa6mM13D3_33SJk9" /></figure><p>5. Our Model has been developed. Let us test it know:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nLnbP5B7pjw-eP5n" /></figure><p>It seems our model is working fine. With more data and proper feature engineering along with more robust Machine Learning Algorithms, we can improve the accuracy of our model which can be then moved onto production. The model can be now saved as a Pickle File which will help us save the pain of retraining the model the next time we are in need of it.</p><h3>Conclusion</h3><p>Natural Language Processing has been used in varied files, some of which are listed below:</p><ol><li>Chatbot Development and Customer Service.</li><li>Customer Segmentation and Review Analysis.</li><li>Sentiment Analysis and Fake News Detection.</li><li>Spam Classification and Text Summarizer.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/0*lI8XKyK5Eypf9kSk" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c9cb9104b5e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/introduction-to-natural-language-processing-3c9cb9104b5e">Introduction to Natural Language Processing</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Introduction to Neural Networks]]></title>
            <link>https://medium.com/analytics-vidhya/an-introduction-to-neural-networks-417695dc1f38?source=rss-1e6bdd4e0a76------2</link>
            <guid isPermaLink="false">https://medium.com/p/417695dc1f38</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-network-algorithm]]></category>
            <dc:creator><![CDATA[Harsh Bardhan Mishra]]></dc:creator>
            <pubDate>Wed, 27 Nov 2019 05:28:46 GMT</pubDate>
            <atom:updated>2019-12-02T08:23:38.329Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p9xy0s5RtqNt-3j7nwefxw.jpeg" /></figure><p>The renaissance of Artificial Intelligence with the boost in Machine Learning and Deep Learning terminologies has sparked a lot of minds around the world, especially the ones in academics. While Artificial Intelligence on a whole encompasses the idea of creating machines that can mimic Human-like behaviour and showcase intelligence that is comparable (or can even exceed) Human Intelligence, it adds various other terminologies like Machine Learning as well, in which a model is trained to learn from the existing data where it can learn the vital patterns in the data and generate new predictions based on it. Deep Learning and Neural Networks on the other hands were once seen as the “Black Sheep”, have now gained a lot of traction and buzz-word as the concept of Artificial Intelligence has come to the hype.</p><p>So what makes Neural Networks so popular? The concept of Neural Networks have existed for decades, but only in the convolutions of mathematical concepts and research work. Neural Network a very long time to evolve, namely because of two reasons: Neural Nets require a lot of data to process and function and it needs large computing frameworks to process the data and analyze it. Neural Networks was recognized as computationally expensive and it was not until Geoffrey Hinton and his team used Restricted Boltzmann Machines to kick-start the Neural Network and Deep Learning as a whole.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0MLFs2SiQCNDiYWnlSHtQ.jpeg" /></figure><h3>What is a Net?</h3><p>The basic introduction to a Neural Network would be that it is inspired by how a Human Brain works, or let’s say how we would expect it to work. The simplest Neural Network would be a perceptron which is a network of “neuron” that can take a number of inputs and produce a single output. Our Human Brain consists of billions of neurons and this is what Neural Network tries to mimic. Just in the manner that the neurons in our brain, can process the information by receiving the necessary inputs, a traditional Artificial Neural Network can take raw features as inputs which are then processed by “Hidden Layers” before a numerical-vector is generated as an output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sqPRbtY8SUHNB5tGlI12aQ.png" /></figure><p>A Neural Network primarily consists of the following parts:</p><ol><li>Input Layer: Through the Input Layer, information is inputted to the Neural Network. This is the initial data layer that is used to input our pieces of information which is then passed onto the Hidden Layers.</li><li>Hidden Layer: While the neurons in the Input Layer, take all the raw features as the inputs, they are fed onto the Hidden Layers. The Hidden Layer takes a weighted combination of the inputs and plugs them into a sigmoid function about which we will discuss a little later. Each node in the Hidden Layer depict a weight which is multiplied to the Input Vector and a bias is added to it.</li><li>Output Layer: The Output Layer constitutes the Output of our Neural Network and they simply present the information that has been computed from the Hidden Layers.</li></ol><h3>How does a Neural Network work?</h3><p>Neural Networks are trained and made to work using an iterative algorithm called Backpropagation. Backpropagation works by feeding it numerous sequences of input vectors along with the corresponding Output Vector. During this whole process, the hidden layers that are accommodated between the Input Layer and the Output Layer are tweaked and optimized to identify the aggregate features in our data and thus can take a weighted combination. So how is Backpropagation made successful? The secret to it lies in our Activation Function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*DF_q1NL8mTj7nt1wG30aww.gif" /></figure><p>The key part of a Neural Network is how can a neuron determine the output vector from numerous input vectors. The answer to it lies in the Activation Function. While there are numerous activation functions, the one that is most commonly found in Classification Algorithms is the Sigmoid Function. Each neuron in such a system is its own logistic regression function and a Neural Network without any hidden layer, would just be a collection of numerous Logistic Regressors.</p><p>Neural Networks also require Graphics Processing Units (GPUs) to work which are specialized hardware and are extraordinarily powerful devices with massive computing and parallel processing capabilities which have gained a god-like status in Deep Learning and setting up Neural Networks. The entire aim for setting up a Neural Network is to minimize the Cost Error Function which is done through forwarding and Backward Propagation.</p><h3>“Hello World” of Neural Network</h3><p>In this <a href="https://gist.github.com/HarshCasper/fac855d392b87963c0d88295593c61b9">Code Snippet</a>, the “Hello World” of Neural Network has been coded where we use Keras, which is a High-Level Neural Network API that can be run on top of popular Deep Learning Libraries like Tensorflow or Theano. In the Code Snippet, we have tried to implement a simple function <em>y=2*x</em> and trained a Densely-Connected Neural Network.</p><p>What flows between these layers are Tensors. Tensors can be visualized as matrices hence the Input Layer itself is not a Layer but a Tensor which has the same shape as the training data. After taking in the inputs and giving the corresponding output, the model is iteratively trained for 500 epochs where the weights are calculated based on the input and output shapes.</p><p>In a dense layer, as we implemented above, the weights are multiplied with the inputs. This means, that we implement a matrix with one column per unit and one row per unit. After training the model we can give off standard values to predict the efficiency of our model which is almost 97% efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_pTAwowLN3B80-TZYps7Ew.jpeg" /></figure><p>This is not all about Neural Networks. With the dawn of the 21st Century, and aided by huge computational powers and lots of data being generated with every click on our devices, Neural Networks have expanded in scope and functionality and have been seeing wide varied uses and purpose.</p><p>Various forms of Neural Networks like Convolutional Neural Networks, Generative Adversarial Networks, Recurrent Neural Networks are being used in various applications all around the world. With the rise of various Deep Learning Libraries like the popular Tensorflow, PyTorch, Keras and more the scope and functionality of Deep Learning has expanded not only to the academics but too low-level users who don’t understand much mathematics that surrounds it, but can put the pre-defined algorithms to societal purposes, aiding in solving real-world problems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=417695dc1f38" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/an-introduction-to-neural-networks-417695dc1f38">An Introduction to Neural Networks</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>