<?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 Chirag Sharma on Medium]]></title>
        <description><![CDATA[Stories by Chirag Sharma on Medium]]></description>
        <link>https://medium.com/@plusminuschirag?source=rss-4b6f3495ca9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iC4aOZbLV3N7oGJ8idzZiQ.jpeg</url>
            <title>Stories by Chirag Sharma on Medium</title>
            <link>https://medium.com/@plusminuschirag?source=rss-4b6f3495ca9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:28:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@plusminuschirag/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[Deploying APIs with custom domains with Nginx, Let’s Encrypt, FastAPI, and Uvicorn]]></title>
            <link>https://plusminuschirag.medium.com/deploying-apis-with-custom-domains-with-nginx-lets-encrypt-fastapi-and-uvicorn-619438168143?source=rss-4b6f3495ca9------2</link>
            <guid isPermaLink="false">https://medium.com/p/619438168143</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Chirag Sharma]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 17:31:49 GMT</pubDate>
            <atom:updated>2023-12-17T17:31:49.538Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EyiZxjH15EiAFVFpRBZDkQ.png" /><figcaption>Lot of moving parts, but only way is forward.</figcaption></figure><h3>Summary and Goals of this guide.</h3><h4><strong>Goals</strong></h4><p><strong>End Goal</strong></p><ul><li>The end goal is to deploy locally hosted APIs to the AWS EC2 instance and access them via a domain. For example, you might be using <a href="http://localhost:300/">localhost:3000</a> to run your FastAPI app, this guide will help you run it on an EC2 instance and access it via your own purchased domain for example <a href="http://chiragsharma.xyz/">chiragsharma.xyz</a></li></ul><p><strong>Secondary Goals</strong></p><ul><li>Get your hands with end to end flow of setting up all things web-related.</li><li>This guide is not designed to be deep into individual components, it gets you aware of all the moving parts of the web to achieve our end goal. Once you have followed this guide to the end, you will find it easy to deep dive into one of each component as you will now be aware of where they fit.</li></ul><h4><strong>Summary</strong></h4><p>This guide is broken down into the following sections:</p><ul><li><strong>Local Development</strong>: This is just to get ourselves going, if you are handsy with Python you can directly start by <strong><em>Setting up our code on the AWS EC2 Instance</em></strong> section.</li><li><strong>Setting up our code on AWS EC2 Instance:</strong> This section deals with launching a new AWS EC2 Instance, Adding an Elastic IP to it, and then installing dependencies and running our code making it accessible via our Elastic IP or public IP DNS.</li><li><strong>Purchasing a Domain and Mapping IP to DNS:</strong> This section deals with purchasing a domain(Namecheap in my case) and then mapping our Elastic IP to DNS in Domain Name Registrar.</li><li><strong>Configuring SSL Certificates and Nginx as Reverse Proxy:</strong> This section deals with installing SSL certificates from Let’s Encrypt and then setting up our Nginx as a reverse proxy so that we can use our domain to access our endpoints.</li></ul><h4><strong>Who is this for?</strong></h4><ul><li>I have tried to make this guide as simple as possible to follow but if you have prior experience with FastAPI and basic AWS EC2 Instances you will breeze through the guide, if not you have to start learning the concepts why not now?</li></ul><h3>Local Development</h3><h4>Quick Discussion on FastAPI and uvicorn</h4><p>Make sure you have <strong>python3.10</strong> installed, we are choosing python3.10 as this is the default python version that comes configured in Ubuntu Instances on AWS right now. To keep it simple let’s go with this version on our local too.</p><p>We will be building this project on top of FastAPI and uvicorn:</p><p><strong>What is </strong><a href="https://fastapi.tiangolo.com/"><strong>FastAPI</strong></a><strong>?</strong></p><ul><li>In short, it’s a web framework with totally awesome features right out of the box, you have fast performance, automatic API documentation, solid data validation, and serializations inbuilt. It’s very fast to test and spin-off web APIs on FastAPI.</li></ul><p><strong>Why are we using it?</strong></p><ul><li>Quick, fast, large community support.</li><li>Microsoft, Uber, and Netflix are using FastAPI in their internal or external work.</li></ul><p><strong>What’s uvicorn?</strong></p><ul><li>Uvicorn is a tool that helps your Python web application talk to the internet. Think of it as a middleman who takes requests from users on the internet, like when someone visits a web page and hands them over to your application. Then, it takes the response from your application (like the content of a web page) and delivers it back to the user’s browser.</li></ul><p><strong>Why are we using it?</strong></p><ul><li>It’s fast, asynchronous, lightweight, and works well with modern Python web apps.</li></ul><h4>Setting up Code and Project</h4><p>Let’s start with the local development. We will be building dummy API Endpoints.</p><p>Once you have cloned the <a href="https://github.com/plusminuschirag/api-endpoint-domain-reverse-proxy-configuration">GitHub Repo</a>, create a python3.10 virtualenv and install the requirements.txt in it. Make sure the virtualenv is activated and you are in the project directory. You are ready to proceed to the next steps.</p><ul><li>Type `uvicorn main:app — reload` in the terminal and let the system roll if everything goes well you will start seeing the following logs in the terminal with it being under the control of uvicorn.</li></ul><pre>INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)<br>INFO:     Started reloader process [19320] using StatReload<br>INFO:     Started server process [30656]<br>INFO:     Waiting for application startup.<br>INFO:     Application startup complete.</pre><ul><li>If your system is correctly up until this point, you can run the following cURLs and expect the following response.</li></ul><pre>curl --location &#39;localhost:8000&#39;<br><br>Response 200 OK:<br>{<br>    &quot;message&quot;: &quot;Endpoint is up!!&quot;<br>}</pre><pre>curl --location &#39;localhost:8000/me&#39;<br><br>Response 200 OK:<br>{<br>    &quot;message&quot;: &quot;This endpoint is about my handle @plusminuschirag go find me on linkedin and github&quot;<br>}</pre><h4>Code Explanation</h4><p>Project Directory has only single Python file ⇒ <a href="http://main.py/">main.py</a> which has the following contents. The file code is pretty straightforward with most basic FastAPI usage.</p><pre>from fastapi import FastAPI<br><br>app = FastAPI()<br><br><br>@app.get(&quot;/&quot;)<br>async def root():<br>    return {&quot;message&quot;: &quot;Endpoint is up!!&quot;}<br><br><br>@app.get(&quot;/me&quot;)<br>async def me():<br>    return {&quot;message&quot;: &quot;This endpoint is about my handle @plusminuschirag go find me on linkedin and github&quot;}</pre><h3>Setting up our code on AWS EC2 Instance.</h3><ul><li>The goal of this section is to create an AWS EC2 Instance and run this code on the server in a way that it doesn’t stop if you close the SSH tunnel to your server.</li></ul><h4>Creating an EC2 Instance</h4><ul><li>Login to your AWS Account, go for <a href="https://us-east-1.console.aws.amazon.com/ec2/home?region=us-east-1#Home:">EC2 Dashboard</a>. Click on Instances(Running) Tile in the middle of your screen under Resources Block.</li><li>Click on Launch instances in the top right corner, it’s an orange button very easy to spot.</li><li>You will be taken to a Launch an Instance Page where you will see some configurations as you scroll down. So scroll back to the top, and let’s start filling them one by one.</li></ul><p><strong>Name</strong></p><ul><li>Fill in any name for the server that is easily recognizable for you. For example, I used <a href="http://chiragsharma.xyz/">chiragsharma.xyz</a> to highlight that this is the URL I will be hosting on the server, name should be easily clickable for you.</li></ul><p><strong>Application and OS Images</strong></p><ul><li>Select Ubuntu from the “Under the Quick Start”. Let other options be as they are, you don’t need to change anything here.</li></ul><p><strong>Instance Type</strong></p><ul><li>Select the t2.micro if it isn’t already selected, this comes under Free Tier if you have a new account or haven’t already exhausted the limit. You can use this free tier to follow this guide.</li></ul><p><strong>Key Pair(login)</strong></p><ul><li>for SSHing into the server. If you don’t know what they are it pays to read about it. If you know create a new key pair, name it something conventional for you, download the keys, and keep them safe, if you lose them your server access is as good as gone.</li></ul><p><strong>Network Settings</strong></p><ul><li>Tick the Checkbox for Allow HTTPS traffic from the internet</li><li>Tick another checkbox for Allow HTTP traffic from the internet</li></ul><p><strong>Configure Storage</strong></p><ul><li>You can leave it at 8 GiB, no need to change for this guide.</li></ul><p>That’s all the configuration you need to run your server, click Launch instance button on the right panel. It’s an orange button again very easy to spot.</p><p>Once you click the button your instance will be created and then launched, go back to your Instances Dashboard and wait for the Instance State of your server to become Running</p><h4>Adding Elastic IP to our EC2 Instance</h4><p>Click on your instance Id from the dashboard and you will taken to the instance summary page. Here you will be two panels:</p><ul><li>Top panel for instance summary</li><li>Bottom panel with multiple tabs like Details, Security, Networking etc</li></ul><h4>Top Panel</h4><ul><li>You will find Public IPv4 DNS and Elastic IP addresses</li><li><strong>Public IPv4 DNS:</strong> This is a DNS assigned to you by the AWS. This is dynamic, if you stop or restart your instance this can change, this will be very problematic we will see later on in our guide.</li><li><strong>Elastic IP addresses:</strong> You will find this field empty right now because AWS doesn’t give you Elastic IP by default, you have to get an IP from the AWS console and assign it to your server. This will be static IP and you will hold it until you release it from your AWS. If you stop or restart your instance this IP will not change.</li></ul><p>Go back to your EC2 Dashboard and click Elastic IPs from the middle top Resources Panel.</p><p>Click on the Allocate Elastic IP address button on the top right, let the settings by default, and click Allocate.</p><p>As soon as you do that you will have that IP, all that remains is to map it to our instance. You will see your newly generated Elastic IP in front of you click on the IP Address and you will be taken to another Summary page for this Elastic IP.</p><p>Click Assosiate Elastic IP address and select the name of your instance in the field, once you select that you will see private IP address filled with your private IP of the instance, if not then just click on it and select your private IP.</p><p>Tick the Checkbox for Allow this Elastic IP address to be reassosiated</p><p>Now you have assigned a static IP to your EC2 Instance.</p><h4>Running our code</h4><p>Click the Instance ID of your server from your Instance Dashboard(left panel), Click the Connect Button in the Top Row.</p><p>Select the SSH Client Tab, here you will be given an example of how to connect to your server via SSH below</p><pre>ssh -i &quot;chiragsharma.xyz.pem&quot; ubuntu@ec2-52-23-30-80.compute-1.amazonaws.com</pre><p>This pem file is the same ssh key-value pair file you created while launching your instance. Navigate in your terminal to the directory where the pem file is present and directly run the command from the example on your SSH Client Tab.</p><p>If everything goes right you will be in your server.</p><ul><li>Your server right now is just a clean slate.</li></ul><h4>Let’s do a step-by-step setup of the code on this server.</h4><p>Run sudo apt update</p><ul><li>Before you install or upgrade packages, your system must know what the latest versions of packages are and where to download them from. This ensures you’re getting the latest and potentially the most secure versions of the software.</li></ul><p>Run python3 --version</p><ul><li>This should print Python 3.10.12 on your screen.</li></ul><p>Run git clone https://github.com/plusminuschirag/api-endpoint-domain-reverse-proxy-configuration.git</p><ul><li>This will clone the repository in your server.</li></ul><p>Run ls -l and it will show you list of directories present, you should see only one directory api-endpoint-domain-reverse-proxy-configuration</p><p>Run mv -T api-endpoint-domain-reverse-proxy-configuration web-hosting</p><ul><li>Let’s change the folder name to web-hosting</li></ul><p>Run cd web-hosting to move into the directory</p><p>Run python3 -m venv venv to create a virtualenv</p><ul><li>Ubuntu might give you some errors while doing this one but will show you the command directly on the screen so you can fix it up.</li></ul><p>Run source/bin/activate to activate your virtualenv. If you run into the following error:</p><pre>root@ip-172-31-26-10:/home/ubuntu/web-hosting/venv/bin# ./activate <br>bash: ./activate: Permission denied</pre><p>Simply run chmod +x source/bin/activate</p><ul><li>Sometimes we don’t have execution permission, so this command will add execution permission to the activated file.</li><li>Once activated, run pip install -r requirements.txt</li><li>This will install the Python pip packages in your environment.</li></ul><p>Run uvicorn main:app --host 0.0.0.0 --port 8000 --reload</p><p>This will start the uvicorn server and if everything goes fine we will see the same logs as we saw in the local setup.</p><pre>INFO:     Uvicorn running on &lt;http://0.0.0.0:8000&gt; (Press CTRL+C to quit) <br>INFO:     Started reloader process [19320] using StatReload <br>INFO:     Started server process [30656] <br>INFO:     Waiting for application startup. <br>INFO:     Application startup complete.</pre><p>We have done something differently here from the local setup, we are running on host 0.0.0.0 instead of 127.0.0.1. Passing host as 0.0.0.0 tells the uvicorn to allow requests from outside the local network.</p><p>You can now use your &lt;elastic-ip&gt;:8000 to access the endpoints.</p><p>Wait what? It didn’t work yes it will not. Check out the next section for that.</p><p>First Terminate the server by pressing CTRL + C.</p><h4>Why it didn’t work and making it work.</h4><p>See it this way, you have hosted your app on port 8000 but your EC2 instance as of now doesn’t allow anything to connect at port 8000.</p><p>We have to make your port, 8000 in this case to allow incoming traffic. For this, we have to add something called the Inbound rule to allow requests at 8000.</p><p>Follow the Steps and you will allow traffic on your <strong>port 8000</strong>:</p><ul><li>Go to your Instances Dashboard.</li><li>Click on your Instance ID</li><li>Select Security tab from the Bottom Panel</li><li>Click on the security group from the Security Groups</li><li>Click Edit Inbound Rule and a new rule table will open.</li><li>Click on Add rule</li><li>Select Custom TCP in Type</li><li>Add 8000 to Port Range</li><li>Right After Source Dropdown Select the empty field and click 0.0.0.0/0 from the dropdown.</li><li>Click on the Save rules</li></ul><p>You can now use your &lt;elastic-ip&gt;:8000 to access the endpoints.</p><p>You can also make a curl request to the same just like you did on your local host.</p><p>Terminate the server by pressing CTRL + C.</p><h4>Running our uvicorn server for practical purposes.</h4><p>We cannot run our uvicorn server this way for the following reasons:</p><ul><li>This server will terminate as soon as we exit out of our SSH connection.</li><li>This server blocks your terminal, you cannot do any other operation while it has occupied the terminal.</li></ul><p>We can use several options to deal with this challenge:</p><h4>nohup</h4><ul><li>The <strong>nohup</strong> command can be used to run commands in the background and ignore the hang-up signal.</li></ul><h4>screen</h4><ul><li><strong>screen</strong> is a terminal multiplexer that enables you to manage multiple terminal sessions and keep processes running after you disconnect.</li></ul><h4>tmux</h4><ul><li>Similar to <strong>screen</strong>, <strong>tmux</strong> allows you to detach from a session and reattach later.</li></ul><h4>systemd</h4><ul><li><strong>systemd</strong> is used for starting, stopping, and managing services and daemons. Services are defined in <strong>.service</strong> files, which <strong>systemd</strong> uses to control how and when to start these services.</li><li><strong>systemd</strong> is designed for parallel execution, which allows for faster boot times as it can start services simultaneously, rather than sequentially.</li><li><strong>systemd</strong> includes <strong>journald</strong>, a logging daemon that collects and manages system and service logs, providing advanced logging capabilities.</li></ul><h4>Setting up our systemd file</h4><p>Run sudo nano /etc/systemd/system/web-hosting.service</p><p>This will create and open a file named “web-hosting.service” for you in the mentioned directory.</p><pre>[Unit]<br>Description=Uvicorn instance to serve my app<br>After=network.target<br><br>[Service]<br>User=ubuntu<br>Group=ubuntu<br>WorkingDirectory=/home/ubuntu/web-hosting<br>ExecStart=/home/ubuntu/web-hosting/venv/bin/uvicorn main:app --host 0.0.0.0 --port 8000<br>Restart=always<br>RestartSec=5<br>KillSignal=SIGQUIT<br>Type=simple<br>StandardError=syslog<br>NotifyAccess=all<br><br>[Install]<br>WantedBy=multi-user.target</pre><p>Pay Attention to one thing, in our ExecStart entry we are mapping the uvicorn in the virutalenv, not activating virtualenv.</p><p>Double check you have the same content in the file, press Ctrl + S and Ctrl + X to save and exit respectively.</p><ul><li>Restart the systemctl daemon : sudo systemctl daemon-reload</li><li>Restart the web-hosting service: sudo systemctl start web-hosting.service</li><li>See the status of your service : sudo systemctl status web-hosting.service</li></ul><p>By this point, your uvicorn server will keep running even if you close the SSH connection and your server will be running in the background</p><h3>Purchasing a Domain</h3><ul><li>If you are following this practical only, then buy a cheap domain, I bought mine from Namecheap for just $3 a year, you can try other options. Purchasing a domain is very straightforward, for this section, I will be assuming you have bought the domain from Namecheap, if not? don’t worry once you go through this section you will figure out what to do with yours.</li></ul><h4>Assuming you bought from NameCheap</h4><ul><li>Once you have purchased your domain, go to your <a href="https://ap.www.namecheap.com/domains/list/">Domain List</a></li><li>You will see your domain listed in front of you, select the drop-down on the right most end of the domain row and click Manage.</li><li>Once it loads, click on the Advanced DNS Tab.</li><li>Now you will see two default entries in your Host Records, you can delete them both.</li></ul><p>We have to now create two new A Records entries:</p><ul><li>First Record</li></ul><pre>Type as A Record<br>Host @<br>Value : Elastic IP of your AWS Instance<br>TTL: 1 min</pre><ul><li>Second Record</li></ul><pre>Type as A Record<br>Host www<br>Value Elastic IP of your AWS Instance<br>TTL : 1 min</pre><h4>Not purchased from NameCheap</h4><ul><li>You just have to locate your DNS records and add the above two entries in your DNS Records, you can delete the default records without problem.</li></ul><h4>Verifying your DNS Mapping</h4><ul><li>After this step you have mapped your static IP with the domain name, so from now on whenever someone enters your domain, it will be resolved to the IP of the server you have just provided.</li><li>You can go to <a href="https://www.whatsmydns.net/">WhatsMyDNS</a> enter your domain, select A from the drop-down, and search wherever in the world your changes have been reflected, don’t panic if they haven’t it takes time to propagate through the world.</li></ul><h3>Configuring Certbot and Nginx</h3><p>Till this point, you have completed the following:</p><ul><li>Hosted your app on EC2 instance which is accessible from outside.</li><li>Linked your Domain Name to AWS Server IP in your Domain Name Registrar’s DNS.</li></ul><p>Our App is accessible using &lt;ELASTIC-IP&gt;:&lt;PORT&gt; right now but we don’t see websites or APIs often working that way, they have domains instead. This section will deal with that.</p><p>We will allow our endpoint to handle http and https both traffic, for this, we need to have SSL certificates, for now, just understand https won’t work without them. So now we have 2 things at our end:</p><ul><li>Get an SSL certificate</li><li>Configure nginx to entertain http and https traffic.</li></ul><p><strong>SSH back into your server</strong></p><h4>Installing Certbot</h4><ul><li>Run sudo apt install certbot python3-certbot-nginx</li><li>Run sudo certbot --nginx -d [yourdomain.com](&lt;http://yourdomain.com/&gt;) -d [www.yourdomain.com](&lt;http://www.yourdomain.com/&gt;)</li><li>In my case, sudo certbot --nginx -d chiragsharma.xyz -d [www.](&lt;http://www.yourdomain.com/&gt;)chiragsharma.xyz</li></ul><h4>Installing and Configuring Nginx</h4><ul><li>Run sudo apt install nginx</li><li>Run sudo nano /etc/nginx/sites-available/yourdomain.com</li><li>In my case, sudo nano /etc/nginx/sites-available/chiragsharma.xyz</li><li>Add the following to the file and save(CTRL + S) and exit(CTRL + X)</li></ul><pre>server {<br>    listen 443 ssl;<br>    server_name chiragsharma.xyz www.chiragsharma.xyz;<br><br>    ssl_certificate /etc/letsencrypt/live/chiragsharma.xyz/fullchain.pem;<br>    ssl_certificate_key /etc/letsencrypt/live/chiragsharma.xyz/privkey.pem;<br><br>    location / {<br>        proxy_pass http://localhost:8000;<br>        # Other necessary configurations...<br>    }<br>}<br><br>server {<br>    listen 80;<br>    server_name chiragsharma.xyz www.chiragsharma.xyz;<br>    return 301 https://$host$request_uri;<br>}</pre><p>Run <strong>sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/</strong></p><ul><li>A symbolic link named <strong>yourdomain.com</strong> is created in the <strong>/etc/nginx/sites-enabled/</strong> directory.</li><li>This symlink points back to the original configuration file in <strong>/etc/nginx/sites-available/yourdomain.com</strong>.</li><li>Nginx will now recognize and use the configuration for <strong>yourdomain.com</strong> when it starts or reloads, as it reads all configurations from the <strong>sites-enabled</strong> directory.</li><li>In my case, I had to run sudo ln -s /etc/nginx/sites-available/chiragsharma.xyz /etc/nginx/sites-enabled/</li></ul><h4>Why Use Symbolic Links for Nginx Configuration:</h4><ul><li><strong>Organization:</strong> It keeps the actual configuration files in a single location (<strong>sites-available</strong>) while allowing you to easily enable or disable specific configurations by adding or removing symlinks in <strong>sites-enabled</strong>.</li><li><strong>Flexibility:</strong> This setup allows you to quickly activate or deactivate sites hosted on the server without having to move or edit the configuration files themselves.</li><li><strong>Best Practice:</strong> This method is a standard practice in managing Nginx configurations, providing clarity and control over which sites are currently active on the server.</li></ul><h4>Let’s reload the nginx</h4><ul><li>Run sudo nginx -t</li><li>Run sudo systemctl reload nginx</li><li>Your APIs are up, load your domain in the web browser.</li></ul><h3>Tada 💥 and it’s done.</h3><ul><li>You can now put [yourdomain.com](&lt;http://yourdomain.com&gt;) in a web browser and will then see the relevant URL loading.</li><li>In my case: https://chiragsharma.xyz became accessible.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=619438168143" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Influencer AI — A Giant in Making]]></title>
            <link>https://plusminuschirag.medium.com/influencer-ai-a-giant-in-making-f54919116a89?source=rss-4b6f3495ca9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f54919116a89</guid>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[influencer-marketing]]></category>
            <dc:creator><![CDATA[Chirag Sharma]]></dc:creator>
            <pubDate>Fri, 23 Oct 2020 06:02:58 GMT</pubDate>
            <atom:updated>2020-10-23T06:02:58.316Z</atom:updated>
            <content:encoded><![CDATA[<h3>Influencer AI — A Giant in Making</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cc2c2IBNrtJCG7sEQpPBVA.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@matfelipe?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Mateus Campos Felipe</a> on <a href="https://unsplash.com/s/photos/influencer?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Influencer AI is a term that got the hype around it in 2018, at the same time when the research in AI was showing consistent promising results and the concept of AI beating humans was taking physical form. In fact, Influencer AI as a term has been around since 2016 but it didn’t get the props it deserved during that time.</p><p>Long before the days of AI, even before sophisticated democratic civilizations influencers were there. In fact, history is riddled with charming people, who swayed people in favors, made them do certain things which were either good or bad depending upon the time. So in history, the pope and the queen were regarded as the influencers as per today&#39;s definition because they had what it took to move people at that time. I am certainly sure that not just kings and queen but some localities held control over their communities and could more or less persuade them into doing certain things, buying something, or dealing them the good hand.</p><p>Queen and Pope generally used their positions, power, and influence to educate people about using medicines more because at that time medicines were miracles and people took them both ways, god blessed panacea or some black witchcraft. In one particular instance, <a href="https://www.aspireiq.com/blog/the-evolution-of-influencer-marketing">Josiah Wedgwood</a> a British potter whose cream-colored artwork got the approval of Queen Charlotte in 1765 even earning him the official title of “Her Majesty’s Potter.” Knowing that the Queen was the ultimate influencer at the time, Wedgwood leveraged his new status and promoted his pottery as “Queensware,” the world’s first luxury brand. The royal endorsement catalyzed his brand, as people started flocking to his business and clamoring for his work soon after. <strong>Josiah Wedgwood might be the first documented businessman to officially capitalize on the biggest influencer of that time aka Queen of England.</strong></p><p>The best example of influencers in our modern world is <strong>Santa Claus</strong>. In <a href="https://www.aspireiq.com/blog/the-evolution-of-influencer-marketing">1932</a>, to drive beverage sales at the height of the Great Depression, Coca Cola used the jolly image of Santa Claus to convey cheer during an otherwise miserable time, refocusing their target audience and helping consumers remember the joyful qualities of the company.</p><h3>Why Influencers and their techniques work?</h3><p>We live in the golden age of information, In 2020 there is almost no one who thinks company advertisements are honest and they are selling because for consumer’s sake not because they want to drive insane profits. Viewers of advertisements feel shaky about them they are really not sure whether the product that is being advertised is really good or the advertisement just has supreme production value. In this age, we all are connected as well so suggesting some productions and word of mouth really matters. One bad review and the company might lose a lot both on sales and market cap.</p><p>Secondly, <a href="https://www.aspireiq.com/blog/the-evolution-of-influencer-marketing"><strong>Global Web Index</strong></a><strong> found that 40% of internet users use ad-blocking software, meaning a big chunk of consumers don’t even see the ads brands pay for.</strong> So how do influencers fit in?</p><blockquote>Influencers provide an effective solution in the age of the ad blocker, as consumers learn about products through content that is native to where they already are - social media.</blockquote><p>Influencers engage with their followers base on raw and realistic points of view. They present themselves not as advertisers but as a companion who is advising the best product there is in a subtle tone without going overboard with the benefits and showing their followers that they promote not because they are being paid but they used it, liked it and now they want their social friends to try it. This does two things for followers, first, it provides realistic review/suggestion and compels them to buy products for the sake of loyalty on a lighter note.</p><p><a href="https://grin.co/blog/the-history-of-influencer-marketing-how-it-has-evolved-over-the-years/">Brands when advertise literally scream buy me, I am the best out here!!.</a> This is not enough to persuade people as every ad somehow claims to be the best product of their segment. Social Media Influencers help brands channelize their message to people who really want to hear it. Instead of screaming as mentioned above, they build a strong relationship with their base, trying things for them and not shying away from berating the products that they didn’t like or just wanted to berate. For people, their influencers are the authentic voice in this sea of selfish screams. They trust them and get easily persuaded by them.</p><h3>So whose the right influencer for me to hire as a brand?</h3><p>Influencer culture really caught up and now multiple niches of influencing, micro-influencers, platform-based influencers, etc are forming and maturing over time. A brand needs to find the right influencers from this bottomless ocean. Recently influencers have been caught manipulating their follower count, engagement on their social media, and overall doing borderline illegal and fake boosts to increase their brand revenue and status in the influencer hierarchy. <strong>Brands define this as the Curse of Automation.</strong> This has created one more peculiar problem for brands, whom should they hire?</p><p>Here comes the elder and mature brother of Artificial Intelligence, Data Analytics for rescue. Certain companies have come up with ways for brands to find the right influencers for their product placements, finding if the influencer they want to hire or have hired is faking the followers count, engagement rate, or conversion ratio. I haven’t tried, tested, or used any such platform but given the name of MNC clients and documentation of certain platforms, I am convinced that they are pretty successful in what they do.</p><p>Apparently, analytics was not enough then, surely it created some great results for a while but the brands needed more precise, accurate, and better fake detection mechanisms for saving themselves from draining money and getting 0 tractions or engagement from the consumers themselves. New companies popped up to fill this gap, they have leveraged the AI which you will see is not truly what it is but the term in a broader sense is right.</p><p>With AI-Powered Recommender Systems, companies now can swift through millions of Facebook, Instagram, Snapchat, Twitch, and TikTok influencers and single out whom they want to hire for their own good. Since AI is able to make connections between data points where we as a human fail due to limited computational ability of the brain, it is able to deliver results that are better by a mile than just analytics.</p><p>Thousands of filters to find the right influencers have been enacted that are AI-driven to get more precise people for brand promotion. <a href="https://indatalabs.com/blog/ai-in-influencer-marketing?cli_action=1602822401.303">Brand representatives are fed up with fake engagements, non-existing products, social bots, and other kinds of fakes that automation reinforces.</a> AI is helping them see through this web and navigate their product for good.</p><p>Not just influencers, brands are able to assess and scrutinize their base on multiple aspects such as their purchasing power, what kind of phone they use, how much likely their are to spend on certain things, what kind of internet they use. This all makes more sense to a Machine Learning Model (Also called Black Box) than to us, since it can make patterns among these so-called unrelated data points and is able to spit out a score for each and every one of them which becomes easier to analyze than an excel sheet where you have to go through hundreds of columns for millions of people and figure out whom to sell.</p><blockquote>You want a specific influencer who has been to Indonesia but has a great Japanese following and the sentiments towards them from their followers is joyous, you got it. AI helps to convert these rows of data related to different scenarios into a meaningful data point which can be further analyzed and scrutinized.</blockquote><p>Image Processing and Natural Language Processing both are branches of AI that deal with images and language respectively. Brands are able to analyze the wide-scale sentiment of influencer and their followers and to some extent predict how well they will receive their product, also one specific use case that excited me to write this is that brands are using Image Processing to figure out whether their influencer is posting real pictures or the photoshopped ones.</p><p>Travel brands are very upset with their influencers as sometimes instead of going somewhere for which the brands pay they pocket the money and post photoshopped images on their handles. They are caught but this happening. So with Image Processing, they can claim whether the image is photoshopped or not with higher accuracy than just analyzing it without AI.</p><h3>How much does influencer fraudulent really cost the brands?</h3><p>According to this <a href="https://www.thedrum.com/opinion/2020/03/30/how-artificial-intelligence-can-transform-influencer-marketing">article</a>, the challenge of finding the right creators for a brand is made worse by the problem of fraudulent influencers using social bots to falsify their impact, costing the industry $1.3 billion a year.</p><p>It really makes sense, for brands to use AI for fighting automation, humanly it’s not possible, with a sufficient amount of processing power and speed, I doubt a million humans will be able to match the havoc of a bot. Only AI can constantly analyze, maintain, and scale a bank of fraudulent footprints that might indicate fake accounts.</p><blockquote>One of the best features of using AI is that in long run it always gets better since it keeps learning from its mistakes and corrects them, it generally produces better results next time. As you keep using it more and more, it gets fluent in what it does and with right amount of human intervention in the data it is learning, AI is able to achieve exceptionally good results in a compartively shorter time.</blockquote><h3>Final Question: If AI is so good at spotting fake influencers, finding the right ones, and learning overall what gets the people interested in brands, can it become the influencer itself?</h3><p>To everyone’s surprise, it’s been happening, meet <a href="https://www.instagram.com/lilmiquela/?hl=en">lilmiquela</a>. She is 19 years old, is an outspoken activist, and is verified on Instagram. The only catch here is that she is a fictional character. She doesn’t exist in a physical yet you can check her Instagram she actively posts and not just alone with celebrities as well. She is the result of the convergence of multiple disciplines of computer science and the primary one of them is AI. Check her profile you will understand how close she is to be a real person. In fact, she looks like some robotic Snapchat filter face of a human but all of it is rendered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_xQnnUc-mxWqxkzBASkrYg.png" /><figcaption>Lil Miquela Instagram Page</figcaption></figure><p>So are we stepping into the era of AI influencers? Probably yes, but there are certain human aspects of influencers that AI or AI-enabled influencers are not able to provide. That is raw human emotions, bonds, and authenticity. CGI looks good but everyone knows that is not what it is. It doesn’t have the spirit of a human, we are really away from that point where we prefer AI over humans any day in social interaction but we surely are stepping into that age.</p><p>Every company in the 21st century is a media company. Every brand has a social presence their own dedicated PR team. AI influencers provide a scope of in-house influencing departments that might lack humanness as per se but it might figure out a way to compensate for that with a more sophisticated algorithm and learning how to engage with the crowd.</p><blockquote>According to a MediaKik survey still, more than 80% of people aren’t sure about the long-term impact of AI Influencers and half of the people on social media surveys said that they don’t think AI can be an influencer. So half of the population plain reject the idea of AI Influencers and the other is up for grab.</blockquote><p>As of now, I believe that AI-assisted influencers will do better in terms of humanness they provide instead of AI replacing influencers. AI Industry is set to become a 25 Billion Dollar industry by 2025 and it will be really interesting to watch how much of it will be grabbed by AI influencers, AI-assisted influencers, and AI platforms helping raw humans to channelize their qualities more. As per transition into this new age, we will see who will make the big bucks and decide the Influence 2.0.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f54919116a89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplest Guide for Regular Expressions: NLP Made Easy]]></title>
            <link>https://medium.com/data-science/simplest-guide-for-regular-expressions-nlp-made-easy-bbb33cd694be?source=rss-4b6f3495ca9------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbb33cd694be</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Chirag Sharma]]></dc:creator>
            <pubDate>Wed, 20 May 2020 07:25:20 GMT</pubDate>
            <atom:updated>2020-05-22T15:06:40.344Z</atom:updated>
            <content:encoded><![CDATA[<h3>Simple Guide to Regular Expressions</h3><h4>NLP made easy</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BWdJQGj2xJ6PuRlnx4bNsg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@franki?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Franki Chamaki</a> on <a href="https://unsplash.com/s/photos/data?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>Regular expressions are considered hard and advanced level stuff if you don’t know them but if you do, congrats, you know hard and advanced level stuff. In this post, we will uncover the basics of regular expressions and at the end, I have attached a link to my notebook where you can see three times more functionalities apart from the one we will discuss here.</p><p>So let’s start by defining regular expressions:</p><blockquote>A regular expression is a sequence of characters that define a search pattern.</blockquote><h4>Where they are used?</h4><p>Regular expressions have wide use cases:</p><ul><li>Text preprocessing</li><li>Extracting text on the basis of some pattern, finding and replacing some words that fulfill a pattern match, for example, locate all words that start with ‘a’ and replace them with word cat</li><li>Password pattern matching</li><li>Data validation</li></ul><p>Regular expressions play a vital role in your day to day coding tasks under the hood plus it’s a super-powerful tool when it comes to data-cleaning, data-mining, and other operations that are too vast to hard-code. We create a regular expression pattern that is slid across the whole text and the matched part’s location or value is returned to us.</p><p>Regular expression pattern matching has two parts to it:</p><p>1. Right pattern: it’s about figuring out what we really want to match</p><p>2. Right <strong>re</strong> function: It’s related to the position. Whether we want to match the pattern at the beginning or anywhere. In case we want to split and substitute we have to change our re function as well.</p><h4><strong>Problem: You are given two texts and you have to find whether they start with the word corona or not.</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/186baca396ae9a438a52d7797c9b932a/href">https://medium.com/media/186baca396ae9a438a52d7797c9b932a/href</a></iframe><p>So now we have to figure out two things: what pattern to use, and what function to use.</p><ol><li>We have to match word corona only so corona is our pattern string.</li><li>For function, we will select re.match because of the reason we need to find if the string <strong>starts</strong> with pattern corona or not.</li><li>re.match takes 3 inputs -&gt; pattern to match, the text which needs to be searched, and flags. We will talk about flags later.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2dcb400087c4099e31b5e800738f16e2/href">https://medium.com/media/2dcb400087c4099e31b5e800738f16e2/href</a></iframe><p><strong>Output</strong>:</p><pre>&lt;re.Match object; span=(0, 6), match=&#39;corona&#39;&gt;<br>None</pre><p>If a pattern matches the string a match object is returned, otherwise, None object is returned.</p><p>In case of a match as in result_text1 match object is returned which has three properties:</p><ul><li>.span(): returns a tuple containing start and end positions of the match.</li><li>.string : returns the string passed into the function</li><li>.group() : returns the part of string where was a match</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38afea3e6939c0496f7a58ffbf9b716b/href">https://medium.com/media/38afea3e6939c0496f7a58ffbf9b716b/href</a></iframe><p><strong>Output</strong>:</p><pre>Span of result_text1:  (0, 6)<br>String passed to result_text1:  corona epidemic has taken world by storm.<br>Groups in result_text1:  corona</pre><h3>Issue with re.match:</h3><ul><li>It’s an excellent function for matching strings only in the beginning.</li><li>In case we want a match anywhere in the string we use re.search. It works the same as re.match but allows us to match anywhere in the string. Returns a <strong>Match object</strong> and if no match is found returns <strong>None</strong>.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ccf95ce09cc7dc87c4c0ec127ff75aa/href">https://medium.com/media/7ccf95ce09cc7dc87c4c0ec127ff75aa/href</a></iframe><p><strong>Output</strong> :</p><pre>&lt;re.Match object; span=(0, 6), match=&#39;corona&#39;&gt;<br>None<br>&lt;re.Match object; span=(29, 35), match=&#39;corona&#39;&gt;</pre><h3>Limitations with re.match and re.search</h3><p>re.match can match only in the beginning and re.search can match anywhere but only the first match is returned. The reason is that re.search is designed to find whether a pattern exists in the string or not. In case we want all of the matches to be returned we use re.findall. In fact re.findall is by default for pattern matching since by various identifiers and conditioning it can behave as re.match &amp; re.search.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da6ec2519bf49550cb6ba55daaedaeac/href">https://medium.com/media/da6ec2519bf49550cb6ba55daaedaeac/href</a></iframe><pre>&lt;re.Match object; span=(0, 6), match=&#39;corona&#39;&gt;<br>[&#39;corona&#39;, &#39;corona&#39;]</pre><h4>What if we want to replace places where the pattern matches a string of our choice?</h4><p>Let’s say we want to replace all occurrences of <strong>coronavirus</strong> with COVID-19. For this purpose we use re.sub re.sub(pattern,replacement,text,count) : the pattern is what we are trying to match, replacement is what to replace the pattern with and text is what we are searching pattern in. Set <strong>Count</strong> in case of substituting the limited number of occurrences. By default, it substitutes all occurrences.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44d02b7a865c4589316850791392dfee/href">https://medium.com/media/44d02b7a865c4589316850791392dfee/href</a></iframe><p><strong>Output</strong>:</p><pre>coronavirus is causing international shutdowns. Neil Ferguson&#39;s report stated that coronavirus matches SARS.<br>COVID-19 is causing international shutdowns. Neil Ferguson&#39;s report stated that COVID-19 matches SARS.</pre><pre>ONLY ONE OCCURENCE IS SUBSTITUTED IF WE MENTION COUNT = 1</pre><pre>coronavirus is causing international shutdowns. Neil Ferguson&#39;s report stated that coronavirus matches SARS.<br>COVID-19 is causing international shutdowns. Neil Ferguson&#39;s report stated that coronavirus matches SARS.</pre><h3>Splitting text where the pattern matches</h3><p>re.split(pattern,string,maxsplit,flags) pattern and string are usual parameters. maxsplit means how many split at max we want to do, by default it means all. We will talk about flags later</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3d4372d10ccf0732f4544c542dbeb97/href">https://medium.com/media/b3d4372d10ccf0732f4544c542dbeb97/href</a></iframe><p><strong>Output</strong>:</p><pre>[&#39;COVID-19 is &#39;, &#39;virus, as of 24 March &#39;, &#39;virus has causes more than 400,000 cases.&#39;]</pre><blockquote>String is split everywhere the pattern is matched. Since the above string has two corona occurrences it just split it at two places and hence resulting in three parts. A list of splits is returned.</blockquote><p>Regular expressions are excellent weapons again text-cleaning, text-mining, and doing complex stuff in one-liners.</p><p>For remaining functionalities check out my Github notebook. Other advanced features of regular expressions are discussed there:</p><p><a href="https://github.com/iamchiragsharma/Regular-Expressions-NLP-Text">iamchiragsharma/Regular-Expressions-NLP-Text</a></p><p>Follow me on twitter for more updates on Natural Language Processing, Deep Learning, and Text Analytics:</p><p><a href="https://twitter.com/csblacknet">Chirag Sharma</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbb33cd694be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/simplest-guide-for-regular-expressions-nlp-made-easy-bbb33cd694be">Simplest Guide for Regular Expressions: NLP Made Easy</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Genetic Algorithms — 2]]></title>
            <link>https://plusminuschirag.medium.com/genetic-algorithms-2-9670eec0d39f?source=rss-4b6f3495ca9------2</link>
            <guid isPermaLink="false">https://medium.com/p/9670eec0d39f</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[science]]></category>
            <dc:creator><![CDATA[Chirag Sharma]]></dc:creator>
            <pubDate>Tue, 20 Aug 2019 16:32:31 GMT</pubDate>
            <atom:updated>2019-08-20T16:32:31.751Z</atom:updated>
            <content:encoded><![CDATA[<h3>Genetic Algorithms — 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CWv6E63UWrvvsWiGs_BrhA.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@james-lee-932763?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">James Lee </a>from <a href="https://www.pexels.com/photo/blue-lamp-2017089/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>We are back with another instalment of Genetic Algorithms. This time we will discuss the famous approach called the <strong>Steady State Algorithms</strong>. It’s an equivalent of <strong>Genetic Algorithms with slightly different mutation and population control options.</strong></p><h3><strong>Difference:</strong></h3><p>In Genetic Algorithm <strong>we create off-springs and then in the next generation they may compete with their parents but in steady state we create offspring and let the old man and woman go loose. Yeah sounds dark but it works.</strong></p><p><strong>Last time we updated population in a single sweep but we will do this now in a piece wise manner. One piece at a time or multiple pieces at a time but we are not gonna sweep whole population under the carpet like some megalomaniac dictator.</strong></p><p>There can be many variations regarding the Steady State Algorithms. <strong>We will discuss major four in great details today.</strong></p><h3>What’s the idea dude..?</h3><p><em>The idea is to breed a new child or two, assess their fitness, and then reintroduce them directly into the population itself, killing off some preexisting individuals to make room for them.</em></p><h3><strong>What’s better now?</strong></h3><ul><li>First of all we need half of the memory as required by the previous Genetic Algorithms as we need to maintain only the parent population as off-springs are included in it and there is no separate population of off-springs to be maintained. Checkout my previous articles for the context. We have covered <a href="https://medium.com/@iamchiragsharma/evolutionary-strategies-darwin-in-ml-e6d8133698f3">Evolutionary Strategies</a> and <a href="https://medium.com/@iamchiragsharma/genetic-algorithms-i-4438475ad5c6">Genetic Algorithms First Part</a></li><li>Since parents stay literally longer in the population then the (μ + λ) and (μ, λ) strategies we prevent premature convergence(it’s not a good thing if you are hearing it for first time).</li><li><strong>This implements exploitation more and exploration less:</strong> <em>This is something we can debate all the day but understand it by an analogy if you want hangout with your same buddies all the time and rarely make new friend you are on the exploitation side but if you make new friends all the time congratulations you the explorer but both of them are best when done in controlled way.</em></li></ul><h3>So what’s the plan, Johnie?</h3><p>Let’s do it one step at a time.</p><p><strong>Step 1 : Importing the necessary libraries and defining genes and the target.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6521afa530ae4895fc2e3d0a5a0413d/href">https://medium.com/media/f6521afa530ae4895fc2e3d0a5a0413d/href</a></iframe><p><strong>Step 2: Defining back bone of all the genetic and evolutionary programming algorithms. The major 4 functions:</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e72e550f5c4aa7da9a032d6f75053a12/href">https://medium.com/media/e72e550f5c4aa7da9a032d6f75053a12/href</a></iframe><p><strong>Step 3 : Creating the multiple way function for various creating population.</strong></p><p>We will discuss way of creating off-spring that we will call <strong>mutate</strong>.</p><ol><li><strong>Singular Mutate</strong> : Imagine you have a Parent 1 and Parent 2 , you will create offspring Children 1 and Children 2 by taking genes from respective parents and adding some genuine controlled mutation.</li><li><strong>Double Mutate</strong> : You have a Parent 1 and Parent 2 , you will create offspring Children 1 and Children 2 bu taking genes from any of the parent by controlled randomness and adding some mutation.</li></ol><p>Next up, we will discuss the way of eliminating parents. This is what makes Steady State in contrast with Genetic Algorithm. Steady State kills off parents in the same generation but Genetic Algorithms keeps them around for the next round of fitness check and then eliminates on some based condition but relatively parents stay longer in population in Steady State as they are killed in batches not all together which sometime happens in Genetic Approach.</p><p>We will discuss removal of parents:</p><ol><li><strong>Random Removal</strong> : In this way we don’t kill the parents used in the off-spring creation. We put them back in population and select two parents on random to kill. This way we keep elitism in check and randomness keeps the pre-mature convergence or loss of vital genes at bay.</li><li><strong>Non-Random Removal </strong>: This way we kill parents used in the off-spring creation. No questions asked.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07ccff26344837c72dff426c857cf666/href">https://medium.com/media/07ccff26344837c72dff426c857cf666/href</a></iframe><h3>Let’s start the show</h3><p><strong><em>Case 1 : We take the case for mutate being singular and removal being random.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3bde58e7be7debc5096f502b26444d9d/href">https://medium.com/media/3bde58e7be7debc5096f502b26444d9d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/1*HMTGDBKTOWRspKoLYsMqyQ.png" /><figcaption>Output : Mutate : Singular , Removal : Random</figcaption></figure><p><strong><em>Case 2 : We take the case for mutate being singular and removal being non-random.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff9d267bbbf2a9cec17fe0f2ba74775d/href">https://medium.com/media/ff9d267bbbf2a9cec17fe0f2ba74775d/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*HbTuJ0UYH4yjorDuXMjr0Q.png" /><figcaption>Output : Mutate : Singular , Removal : Non-Random</figcaption></figure><p><strong><em>Case 3 : We take the case for mutate being double and removal being random.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2fb83002fb5e921130a27de8524d52f9/href">https://medium.com/media/2fb83002fb5e921130a27de8524d52f9/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*x4sLD4hC8mEmbtvK4rX09w.png" /><figcaption>Output : Mutate : Double, Removal : Random</figcaption></figure><p><strong><em>Case 4 : We take the case for mutate being double and removal being non-random.</em></strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9425222f3e269428618060d7ba0c5500/href">https://medium.com/media/9425222f3e269428618060d7ba0c5500/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*SQHmdDXcIZVleALpVVg7xw.png" /><figcaption>Output : Mutate : Double, Removal : Non-Random</figcaption></figure><h3>Conclusion<em>:</em></h3><p>We can easily see the population didn’t converge in three cases <strong><em>but the case of Double Mutate and Random Removal converged to the target very fast.</em></strong> When you take a look at all the diagrams you can see all of them maintained constant fitness for a while and didn’t run lose with their randomness which is constantly helpful when we are trying to implement genetic algorithms in the implementation of deep learning and facial-recognition systems. You can checkout various research papers on their usage.</p><p><strong>So in my opinion using the double mutation with random removal is best if you are more attracted toward reaching goal otherwise all methods are better alternative when you want more exploitation and less of random guessing. </strong>Population convergence make take time but it’s a meta-heuristics so cannot complain there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9670eec0d39f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Genetic Algorithms — I]]></title>
            <link>https://plusminuschirag.medium.com/genetic-algorithms-i-4438475ad5c6?source=rss-4b6f3495ca9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4438475ad5c6</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Chirag Sharma]]></dc:creator>
            <pubDate>Fri, 09 Aug 2019 19:51:42 GMT</pubDate>
            <atom:updated>2019-08-09T20:02:38.771Z</atom:updated>
            <content:encoded><![CDATA[<h3>Genetic Algorithms — I</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W2B9VGSna34h0Ak2o1f70A.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@gabriel-peter-219375?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Gabriel Peter </a>from <a href="https://www.pexels.com/photo/red-jelly-fish-706924/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>I never knew how strong I was until I had to do biology to make my programming better. I thought that programming was a single discipline with mathematics staring at me with disgusting grim on it’s face. Mathematics is one of the noble pursuit but as you mature up in a field you began to realize all other fields are quite informative and really running the world.<strong> Biology for once I never thought would be implementable in the field of mathematics but boy was I wrong!</strong> Right now I am going crazy over the in depth analysis of Genetic Algorithms as I never thought they had so much mathematical significance in them.</p><p>So let’s begin the ride for today! I promise you that this one is going to be interesting and you promise me If you develop something over it you will let me know because there is nothing more fun than watching someone create something fabulous.</p><h3>What’s the fuss about?</h3><p><strong>Machine Learning, Artificial Intelligence and other fields of study where we are creating the human vs robot debate is being charged to full extent by usage of algorithms and patterns that exist among the nature and yes you guessed it right! Genetic Algorithms are part of this whole circus for which everyone wants ticket to.</strong></p><h3>Famous Usage of Genetic Algorithms:</h3><ul><li><strong>Construction of </strong><a href="https://en.wikipedia.org/wiki/Facial_composite"><strong>facial composites</strong></a><strong> of suspects by </strong><a href="https://en.wikipedia.org/wiki/Witness"><strong>eyewitnesses</strong></a><strong> in forensic science.</strong></li><li><strong>File allocation for a </strong><a href="https://en.wikipedia.org/wiki/Distributed_system"><strong>distributed system</strong></a><strong>.</strong></li><li><a href="https://en.wikipedia.org/wiki/Game_theory"><strong>Game theory</strong></a><strong> equilibrium resolution.</strong></li><li><a href="https://en.wikipedia.org/wiki/Computational_creativity"><strong>Artificial creativity</strong></a><strong>.</strong></li><li><a href="https://en.wikipedia.org/wiki/Code-breaking"><strong>Code-breaking</strong></a><strong>, using the GA to search large solution spaces of </strong><a href="https://en.wikipedia.org/wiki/Cipher"><strong>ciphers</strong></a><strong> for the one correct decryption.</strong></li></ul><h3>Let’s start, shall we?</h3><ul><li>Importing all the necessary libraries and fixing the amount of individuals I will keep at max in any generation i.e 100:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/29f4b6a265924e39973826d8c2f7828c/href">https://medium.com/media/29f4b6a265924e39973826d8c2f7828c/href</a></iframe><ul><li>For this whole session my target would be to achieve the final goal as PYTHON but with a little bit of twist -&gt; Achieve PYTHON’s binary equivalent combination i.e. ‘1010000 1011001 1010100 1001000 1001111 1001110’.</li><li><strong>GENES: Possible Set of Achievable Points. In this case only 0 1 and “ “ are achievable so I am using them otherwise you can add others as a noise to balance out the early convergence (will talk about this term later).</strong></li><li>Keep this in mind. <strong>TARGET = ‘1010000 1011001 1010100 1001000 1001111 1001110’</strong></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/229d86305941ea4e2c85349c911b44f5/href">https://medium.com/media/229d86305941ea4e2c85349c911b44f5/href</a></iframe><ul><li><strong>Chromosome Function :</strong> Creates an individual from the genes provided. Here they are only three : <strong>0,1,’ ‘.</strong></li><li><strong>Mutation Function : </strong>Function with a twist. It helps to prevent early convergence(will talk about this later for love of god believe me!). This is like as I have explained before in my previous article that it helps to abruptly break the stupidity out of the children(bad genes) and can be harmful to break the great sensible habits from the children(good genes). We will see what it is and why it matters very soon.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7176c80a941a4401ec85ee56e40b77ea/href">https://medium.com/media/7176c80a941a4401ec85ee56e40b77ea/href</a></iframe><ul><li><strong>DNA_mismatch Function</strong>: This will calculate how much of the population’s individuals differ from the actual target to achieve. It just zips their error and the individual together.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f11e9b46ebe77792731c44e534b8f882/href">https://medium.com/media/f11e9b46ebe77792731c44e534b8f882/href</a></iframe><h3><strong>What’s happening?</strong></h3><p>Genetic Algorithms mainly defer by the way new off springs are created and how mutations are introduced in the generation. Crossover is the process of creating off springs and we will different kind of mutations and strategies within it to create the superior individual.</p><h3><strong>1. Cross Over Without Mutation</strong></h3><p>This means we are reproducing new offsprings but without introduction of new mutations. If A,B,C ∈ P1 and 1,2,3 ∈ P2 then C1 and C2 will be produced by using <strong>CrossOverWithoutMutation</strong> from P1 and P2 only if they have any of the six genes but none of the genes x ∈ C1 , C2 but ∉ P1,P2.</p><ul><li><strong>Plan of Attack</strong> : Create a random population. Assign DNA mismatch error in it. Select the top 10% and they will go to the next generation since they are most fit and cross breed the top 50% to create 90% offsprings which will compete with their parents for the next turn and keep doing that until you find your own homegrown evil AI created individual.</li></ul><p>Here’s the code for it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0efd7792c3f962864ffa05bea70148a3/href">https://medium.com/media/0efd7792c3f962864ffa05bea70148a3/href</a></iframe><p>When you run this the output will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*phc9iGHSruJeYGZdg-K5SA.png" /><figcaption>Output produced by the code above. It’s random can be different when you run it.</figcaption></figure><p>See this <strong>converged.</strong></p><h3>So what is this Convergence?</h3><p><strong>Convergence means when you reach your expected goal instead of compromising in mid between due to the bad genes being passed into the next generation or the good ones being eliminated from the generation.</strong></p><p>Let’s plot this one and see it more clearly how it happened:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a0958766b07b5c664849a21bc001c9b9/href">https://medium.com/media/a0958766b07b5c664849a21bc001c9b9/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*exeDIP7oH2cfiZCLnueSgw.png" /><figcaption>It found the best individual very quickly! Damn dude.</figcaption></figure><p><strong>Is this the best we can do?</strong></p><p>Certainly no and let me tell you one more thing. <strong>This thing worked only and only because of the lack of noise in the genes. We had only three options and they were repetitive there were very very less chance of missing some important gene and converging before reach the right point.</strong> So if you know that your task is controlled and you are pretty sure that genes won’t be lost(which will be no matter how hard you try, this is something you cannot control to full extent) then go for it otherwise stay and explore the mutation ones with me.</p><h3>2. <strong>CROSS OVER WITH MUTATION</strong></h3><p>This means we are reproducing new off springs but without introduction of new mutations. If A,B,C ∈ P1 and 1,2,3 ∈ P2 then C1 and C2 will be produced by using <strong>CrossOverWithMutation</strong> from P1 and P2 only if they have any of the six genes but none of the genes x ∈ C1 , C2 but ∈ or ∉ P1,P2.</p><ul><li><strong>Plan of Attack</strong> : Create a random population. Assign DNA mismatch error in it. Select the top 10% and they will go to the next generation since they are most fit and cross breed the top 50% to create 90% offspring which will compete with their parents for the next turn and keep doing that until you find your own homegrown evil AI created individual. (Same as the above case but this time we use different crossing technique keep that in mind).</li></ul><p>Here’s the code for it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0b1dab23500a231569dadf969f3256d/href">https://medium.com/media/e0b1dab23500a231569dadf969f3256d/href</a></iframe><p>When you run this the output will be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*H2gqp-xY7iy0zdXrhqs4pQ.png" /></figure><p>This one converged too.<strong> This is not just random, mutation makes sure that you reach your goal but sometimes on the cost of more iterations.</strong></p><p>Plotting this one:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b3a1e9a3e2b03489a52d52e60e78950/href">https://medium.com/media/0b3a1e9a3e2b03489a52d52e60e78950/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*EX2tV9pC_I3xACmYIgjoBw.png" /><figcaption>If you compare it, it’s better.</figcaption></figure><h3>3. ONE POINT CROSS OVER</h3><p>We will try one more approach now. Let’s see how about we try to create children purely out of parents?</p><p>We will take two parents and swap certain bits of them. Let’s say we get a random number c and we will swap every bit of two parents from index 0 to c and name the new entities as their offspring.</p><p>Here’s the code for it:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/89e467cc9e2c393b43e41cee47aebaeb/href">https://medium.com/media/89e467cc9e2c393b43e41cee47aebaeb/href</a></iframe><p>I cannot paste it’s output since it didn’t converge but I will show you it’s plot:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df6e8abe9d9b6fbba3a0f641d12e9824/href">https://medium.com/media/df6e8abe9d9b6fbba3a0f641d12e9824/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/1*DtUordqMjJ3oWMLe6PNfqw.png" /></figure><p><strong>Why this happened?</strong></p><p><strong>We kicked some of the greatest genes that were necessary to reach our perfect individual by not having enough mutations in it. For example: if you can pick superpowers from your father and mother and they both chose the power to take naps whenever they want. How can you possibly inherit the power to lift ships and planes without having drastic mutations. This is what happened here. Here parents lacked some info, we created off springs out of them and lack of info kept on going and at some stage none of the powerful off springs had the almighty genes to become predecessor of our almighty individual.</strong></p><p>Similarly you can create Two Point Cross Over and Uniform Cross Over by yourself. If you need any help in that reach to my <a href="https://github.com/iamchiragsharma/pythonForInsanes/blob/master/Advanced%20Optimizations/Population%20Methods/Genetic%20Algorithms/Genetic-Conceptual-Binary.ipynb">Github Repo</a> and leave a star if you like it. See ya again keep learning till then.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4438475ad5c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Evolutionary Strategies: Darwin in ML]]></title>
            <link>https://plusminuschirag.medium.com/evolutionary-strategies-darwin-in-ml-e6d8133698f3?source=rss-4b6f3495ca9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6d8133698f3</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Chirag Sharma]]></dc:creator>
            <pubDate>Mon, 05 Aug 2019 18:45:31 GMT</pubDate>
            <atom:updated>2019-09-01T14:43:01.217Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*cMhelrzZI8YMgl0d.jpeg" /><figcaption>Photo by <a href="https://www.pexels.com/@bruna-tovar-faro-1251359?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Bruna Tovar Faro </a>from <a href="https://www.pexels.com/photo/round-clear-glass-plate-2570976/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>Darwin was a genius he gave the theories which explained why stupidity and wrong kind of addictions will wipe you out. He was right about the survival of fittest but does this approach works in code too? Let’s see.</p><p>Before we jump top down into this let me explain you some technical aspects before hand:</p><ol><li><a href="https://en.wikipedia.org/wiki/Heuristic"><strong>Heuristics</strong></a>: Something that works but cannot be explained by proper mathematical models but solves the problem practically or at least reaches the sufficient goal. Limited to certain kind of specific problems.</li><li><a href="https://en.wikipedia.org/wiki/Metaheuristic"><strong>Meta-Heuristics</strong></a>: Heuristics with swag. They are generalized and solve a variety of problems.</li></ol><h3>Why they matter?</h3><p>Sometimes you have <em>incomplete information, limited processing power</em> which stops you from lingering in all of the possible solution space. So when you hands are tied these two acts as the savior of the day, untie you and make you feel pretty awesome even though the day was ruined by the other kind of algorithms.</p><p>Specifically in the machine learning and artificial intelligence sector when you deploy the models you don’t have the luxury to just keep expanding power and storage. They become your best buddies for the work.</p><p>Meta heuristics are most practical, having most use cases in the advanced Artificial Intelligence and Deep Learning Concepts.</p><h3>Back to the Point:</h3><p>I am not going to talk about all of the heuristics and meta-heuristics today. Just of one kind that are Evolutionary Strategies. <strong>The family of algorithms known as Evolution Strategies (ES) were developed by <em>Ingo Rechenberg </em>and <em>Hans-Paul Schwefel</em> at the Technical University of Berlin in the mid 1960s.</strong></p><p>We are going to discuss two of the most important Evolutionary Strategies:</p><h3>1. (μ,λ) Algorithm</h3><ul><li>We begin with <strong>λ</strong> individuals generated randomly</li><li>Assess <strong>fitness</strong> of all the individuals via <strong>fitness functions.</strong></li><li>Delete all except the <strong>μ</strong> fittest ones.</li><li>Each of <strong>μ </strong>fittest ones produces <strong>λ/μ</strong> children through ordinary <strong>mutations</strong> (We have new <strong>λ</strong> children)</li><li>We have <strong>μ </strong>parents and <strong>λ</strong> children making it to next generation for the same process.</li></ul><h3>Ummmmmmmm…</h3><p>Yes it’s a lot to digest at first but let’s walk through it one by one.</p><h3>What is fitness?</h3><p>Fitness means how close are your individuals to the target you have assigned to reach. It gives them a score.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/434/1*TRNbPWQCzTkV2FJV6cuTlw.png" /><figcaption>Fitness is 5 because characters matching at the required indexes is 5.</figcaption></figure><h3>What is mutation?</h3><p>Mutation means abrupt change in the generation. For ex: If you are genius but your predecessors weren’t then it means you have mutated from your bloodline for good.</p><h3>How much mutation in the Evolution?</h3><p>See this is difficult to answer. Personally controlled mutation is often best as high mutation is going to make your next generation too random and low mutation is going to make them same as the parents?</p><h3>What’s the issue with low and high mutations?</h3><p>Let’s understand with an example. Let’s say A has a kid B, A is very smart and it would be very awesome have those genes transferred to B but the mutation being very high makes smartness of B completely random and he maybe comes out sharpest tool in the shop or just a tool who fixes tires using screw drivers.</p><p>Let’s say B has a kid C, B turned out to be stupid and no one in sane mind would hope for C to inherit the same genes as B. So in this case we need high mutations but since now we have kept the mutations very low we are going to land up with the whole pack of stupidity. So we clear on keep mutations moderate!</p><h3>Let’s wind it up:</h3><p>We are going to create 20 parents randomly from the genes mentioned above. The fittest 20 (closest to the target value) will be passed to create children. After that the fittest 20 among them will be passed to create children again and again until we reach the target and we are going to mutate in a control way via mutation function so stupidity doesn’t get compounded over the generation or the smartness acquired in a generation is lost in another due to high mutation.</p><p>Let’s start the code for this algorithm:</p><ul><li><strong>Let’s import the package needed for this code:</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*bPD4zQbH6ghh7eChljUOCg.png" /></figure><ul><li><strong>Fixing some global parameters:</strong></li></ul><ol><li><strong>Genes: </strong>Consists of all of the smallest things that will make our chromosomes.</li><li><strong>Chromosomes</strong>: An individual which consists of groups of genes. It will be 5 for this case.</li><li><strong>Target: </strong>What you want to achieve from your population. A point that you wan’t to reach.</li><li><strong>MAX_POPULATION:</strong> At any given point of time. You cannot have individual existing in a generation more than the MAX_POPULATION.</li><li><strong>PARENTS:</strong> No. of people you begin with and also the number of people who get to create children in every generation.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*Gd7n-RZn4GVYW_o2E3IQnQ.png" /></figure><ul><li><strong>Creating a mutation function: </strong>Just picks out a genes randomly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*bFAoFaoFQtBb1xsgVr_0EQ.png" /></figure><ul><li><strong>Creating a Population Generator:</strong> This one creates a random population.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/995/1*bBEYRmsU-HGlVd9g6ayr6g.png" /></figure><ul><li><strong>Fitness Finder: </strong>This one checks the fitness of your population as explained by the logic mentioned above.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*_2leoTBJPuqHJD_EwmrOjg.png" /></figure><ul><li><strong>Mating Function: </strong>This one is more like a control over the mutation. See that there is 1 in 4 chance of having mutation which is pretty much under control.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*8kZu2tTEQzIdfj9HfYYDFw.png" /></figure><ul><li><strong>Let’s start the show:</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*c2eY86_avk-Xs9ZypkXrZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*eAz4F9C2tO_IeK_NEj7A_w.png" /></figure><p><strong>So we finally got our answer in the 9th Generation. We accumulated the right genes and lost the wrong ones to achieve our goal. Darwin would be happy.</strong></p><h3>2. (μ + λ) Algorithm</h3><p>Instead of keeping the total population fixed we start with λ parents and add μ offspring of their own. They compete with each other to get into the next generation. Fittest survives and they are again allowed to create offspring.</p><h3>Why don’t you go ahead and try to code this algorithm?</h3><p><strong>For any chance if you need help feel free to connect with me on </strong><a href="https://www.linkedin.com/in/iamchiragsharma/"><strong>LinkedIn</strong></a><strong> and for more of this advanced stuff which helps a lot please refer to the my </strong><a href="https://github.com/iamchiragsharma/pythonForInsanes"><strong>Github Repo</strong></a></p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PYxBP_WV7LI6zc-zdUkNqQ.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_read_later_text">Journal</a>.</p><p>👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. <a href="https://usejournal.com/newsletter/noteworthy-in-tech/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_text">Read the Noteworthy in Tech newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6d8133698f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>