<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nitin K. Chauhan on Medium]]></title>
        <description><![CDATA[Stories by Nitin K. Chauhan on Medium]]></description>
        <link>https://medium.com/@nitinkchauhan?source=rss-e44deb7cb9f9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Bf1WuBHfmpAg3Andiqan8w@2x.jpeg</url>
            <title>Stories by Nitin K. Chauhan on Medium</title>
            <link>https://medium.com/@nitinkchauhan?source=rss-e44deb7cb9f9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:59:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nitinkchauhan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Installing Conda and Creating Python Environment]]></title>
            <link>https://nitinkchauhan.medium.com/installing-conda-and-creating-python-environment-1cb71b8b0fc7?source=rss-e44deb7cb9f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cb71b8b0fc7</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[environment-management]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Nitin K. Chauhan]]></dc:creator>
            <pubDate>Sun, 07 Mar 2021 15:59:52 GMT</pubDate>
            <atom:updated>2021-03-07T15:59:52.687Z</atom:updated>
            <content:encoded><![CDATA[<h4>Quick Bites on How to install Conda &amp; to manage python environment without root privileges.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qXQyG5M2qhar_smm" /><figcaption>Photo by <a href="https://unsplash.com/@altumcode?utm_source=medium&amp;utm_medium=referral">AltumCode</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>Hello</strong>, imagine a condition where you are given a Linux machine, but you don’t have the root privileges on also you don’t wish to mess with the system’s Python or it could, you might be working under resource constraint condition, or there are many users on the dedicated machine those are the times where Environment management systems like Conda comes in use. For managing the python Environment.</p><blockquote>This is a quick and short article that will help on, how to install the conda locally without sudo or root privileges easy and preferable way to create a conda environment for different versions of Python. So lets Start,</blockquote><p><strong>Downloading conda</strong> executable from their <a href="https://www.anaconda.com/products/individual">website</a>. There are two versions either you can download a larger file that comes with the graphical installer in the range of some Five hundreds megabytes or a simple .sh file version which is in the range of 300 MB’s.</p><p>If considering the size as an limiting factor, you can click to use their archives and download the miniconda which is in the range of 70MB here download command given below is so with the smaller file OF MINICONDA INSTALLER.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*POnAi2GPmvHexEYXSof7zg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SulLz2tXWHzpmbNTR7RWBQ.png" /></figure><p>Or using the “wget” which is a command-line download utility that will download the file for you can also download that using the browser also if the above link expires, replace the link below with the latest link, and it will download the executable file for you</p><pre><strong><em>wget </em></strong><a href="https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh"><strong>https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh</strong></a></pre><p>Once Downloaded, we have to convert the file to the executable below command will help you, but conda should be replaced with the name of your conda/miniconda executable.</p><pre><strong>chmod +x ./conda.sh</strong></pre><p>Now we will proceed to installation for that use the command mentioned below. It will asks you to hit enter and then will open the agreement keep pressing the space bar to reach at the end of it and accept the terms by typing yes then, proceed.</p><p>Remember since we are doing the local installation you can choose the different path for installation otherwise it will by default create a directory in /home/miniconda it will also prompt you with confirmation once done, it will start installing the libraries.</p><pre><strong>sh ./conda.sh</strong></pre><p>Once your installation is done, you can close out the terminal and open a new one where you will see “base” mentioned on terminal prompt, if you have chosen to append the conda command in ./bashrc at the last part of installer else you have to initialize the conda each time manually.</p><p>Now will head towards Creating the environments, and you can use the command below</p><pre><strong>conda create -n name_of_env python=version anaconda</strong></pre><p>Here you can play little smart generally for system-specific Python create two environments based on two major python versions and could name them, for example<br>For version python3.6, you can name your environment python36, and for version python2.7, name it as python27, which makes it easy to remember also, most programs work easily on these two versions of python</p><pre><strong>conda create -n python36 python=3.6 anaconda</strong></pre><p>Then for python 2.7</p><pre><strong>conda create -n python27 python=2.7 anaconda</strong></pre><p>Using anaconda at the end of the command will take you a little longer to finish based on your bandwidth, but that’s good enough and save you from installing few mostly used packages since it will preinstall them for you.</p><p>Once you have created the environment, you can activate them by using the command below. That will change the terminal prompt that will base the name of your environment.</p><pre><strong>conda activate name_of_env</strong></pre><p>Then you can use your environment install packages in it using pip or conda and deactivate the environment by simply typing the command below</p><pre><strong>conda deactivate name_of_env</strong></pre><p>Installing package in the environment</p><pre><strong>conda install name_of_env package </strong></pre><pre><strong>pip install package </strong></pre><p>To list packages installed</p><pre><strong>conda list</strong></pre><blockquote>That was the strategy to tackle the system level python version issues but imagine you are working on a specific project and want to keep track of the dependency getting or being used by that particular project. For this kind of issue, I will guide you with the strategy you can try.</blockquote><p>Imagine as an example you wish to work with the GPT2, a large <a href="https://arxiv.org/abs/1706.03762">transformer</a>-based language model with 1.5 billion parameters.</p><p>Fork the GPT2 git library</p><pre><strong>git clone </strong><a href="https://github.com/nshepperd/gpt-2.git"><strong>https://github.com/nshepperd/gpt-2.git</strong></a><strong> </strong></pre><p>Once that’s done, you can create a different environment with your project’s name like here; I have named my environment as gpt2.</p><pre><strong>conda create -n gpt2 python=3.6 # creating a env</strong></pre><blockquote>You can also note down that I haven’t used the parameter anaconda at the end, and by that, it only installs few necessary packages for the environment to work also, this finishes in quickly</blockquote><pre><strong>conda activate gpt2</strong></pre><p>For example, your package comes with the requirements file. You can pip install the requirement file like in the command below</p><pre><strong>pip install -r requirements.txt # dependency</strong></pre><p>We have learned how to use conda in simple and quick short ways to tackle the system-level python version issues, use the project-specific environment, and install it without root privileges. There are more complex way environment management systems that even create the more complex software specific version stacks you can check out about Docker.</p><blockquote>And if you have reached this end of the article, Thanks for Reading .. :)</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cb71b8b0fc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create a voice chatbot in python using NLTK, Speech Recognition, Google (text-to-speech)&…]]></title>
            <link>https://nitinkchauhan.medium.com/create-a-voice-chatbot-in-python-using-nltk-speech-recognition-google-text-to-speech-445468c083f8?source=rss-e44deb7cb9f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/445468c083f8</guid>
            <category><![CDATA[nltk]]></category>
            <category><![CDATA[chatbots]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[for-beginers]]></category>
            <category><![CDATA[speech-recognition]]></category>
            <dc:creator><![CDATA[Nitin K. Chauhan]]></dc:creator>
            <pubDate>Thu, 21 May 2020 10:22:10 GMT</pubDate>
            <atom:updated>2020-05-31T16:20:35.831Z</atom:updated>
            <content:encoded><![CDATA[<h3>Create a voice chatbot in python using NLTK, Speech Recognition, Google (text-to-speech)&amp; Scikit-learn</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*APeX55G1_nOazFXC75uV6Q.png" /><figcaption><em>icon used :https://www.flaticon.com/premium-icon/chatbot_1698586</em></figcaption></figure><blockquote>Chatbots are a class of intelligent, conversational systems that works by natural language input that can be in the form of text, voice, or both. They provide conversational output in response, and are sometimes used for task execution. However, chatbot technologies have existed since the 1960s and have influenced user interface development in games since the early 1980s.</blockquote><blockquote>- Radziwill, Nicole M., and Morgan C. Benton. “Evaluating quality of chatbots and intelligent conversational agents.” arXiv preprint arXiv:1704.04579 (2017).</blockquote><h3><strong>Disclaimer :</strong></h3><blockquote>Since this guide is for <strong>beginners</strong>, this is a relatively simple implementation of nltk and speech recognition. It does not talk about using heavy stuff like integrating frameworks like RASA for NLU or RDB to store QA improvement. With all this in mind, let us get started.</blockquote><p>We will create a chatbot interacting via voice input and voice output like popular personal assistant apps like Siri and Alexa in python.</p><p>Our Bot uses an offline backend corpus as a knowledge base which user can change by merely tweaking the backend corpus by adding their personalization to answers from Bot. It is a simple command-line implementation for beginners, but to make it look interesting will be adding things like emotion detection, greeting function, and a color pallet to distinguish between questions and answers.</p><blockquote><em>Want to read this story later? Save it in </em><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=blog&amp;utm_campaign=noteworthy&amp;utm_content=eid7"><em>Journal</em></a><em>.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*zBWrcLv1vm2ploDmwzSHcw.png" /></figure><p>key steps include</p><ol><li>Backend Corpus serving as Bot’s knowledge base.</li><li>User initializing verbal input via a microphone</li><li>Conversion of input query information into respective text form.</li><li>Classification of input type using Naive Bayes between question or emotion type.</li><li>Processing of input using NLP &amp; Computing answers from the Corpus.</li><li>Computing best possible answers via TF-IDF score between question and answers for Corpus</li><li>Conversion of best Answer into Voice output.</li></ol><p><strong>Downloading and installing packages</strong>. We will be installing python libraries nltk, NumPy, gTTs (google text-to-speech), scikit-learn and, SpeechRecognition using pip. Rest, we will be installing mpg123, portaudio, for accessing the microphone from the system.</p><pre>pip install SpeechRecognition numpy gTTs sklearn<br>sudo apt-get install mpg123<br>sudo apt-get install portaudio19-dev python-all-dev python3-all-dev</pre><p><strong>Calling Libraries, </strong>Done with installing the needful dependencies, we will start with our script from the import section. Also, note that nltk.download command will download the mentioned corpora on the first run, after which its recommended to<strong> </strong>comment these <em>“.download” </em>commands; otherwise, it will repeatedly search for mentioned corpora adding to run time<strong>.</strong></p><pre>import io<br>import random<br>import string<br>import warnings<br>import numpy as np<br>from sklearn.feature_extraction.text import TfidfVectorizer<br>from sklearn.metrics.pairwise import cosine_similarity<br>import warnings<br>from gtts import gTTS<br>import os<br>warnings.filterwarnings(&#39;ignore&#39;)<br>import speech_recognition as sr <br>import nltk<br>from nltk.stem import WordNetLemmatizer</pre><pre>#for downloading package files can be commented after First run<br>nltk.download(&#39;popular&#39;, quiet=True)<br>nltk.download(&#39;nps_chat&#39;,quiet=True)<br>nltk.download(&#39;punkt&#39;) <br>nltk.download(&#39;wordnet&#39;)</pre><p>We will write a function to classify user input, which uses nps_chat corpora and naive Bayes classifier to categorize the input type by classifying them into listed categories.Where else Bot will answer only to Question type classes.</p><p>#Greet<br>#”Bye”&gt;<br>#”Clarify”&gt;<br>#”Continuer”&gt;<br>#”Emotion”&gt;<br>#”Emphasis”&gt;<br>#”Greet”&gt;<br>#”Reject”&gt;<br>#”Statement”&gt;<br>#”System”&gt;<br>#”nAnswer”&gt;<br>#”whQuestion”&gt;<br>#”yAnswer”&gt;<br>#”ynQuestion”&gt;<br>#”Other”</p><pre>posts = nltk.corpus.nps_chat.xml_posts()[:10000]</pre><pre># To Recognise input type as QUES. <br>def dialogue_act_features(post):<br>    features = {}<br>    for word in nltk.word_tokenize(post):<br>        features[&#39;contains({})&#39;.format(word.lower())] = True<br>    return features</pre><pre>featuresets = [(dialogue_act_features(post.text), post.get(&#39;class&#39;)) for post in posts]<br>size = int(len(featuresets) * 0.1)<br>train_set, test_set = featuresets[size:], featuresets[:size]<br>classifier = nltk.NaiveBayesClassifier.train(train_set)<br></pre><p>To make our chatbot more engaging and interactive, we will create a greeting function.</p><pre># Keyword Matching<br>GREETING_INPUTS = (&quot;hello&quot;, &quot;hi&quot;, &quot;greetings&quot;, &quot;sup&quot;, &quot;what&#39;s up&quot;,&quot;hey&quot;,)<br>GREETING_RESPONSES = [&quot;hi&quot;, &quot;hey&quot;, &quot;*nods*&quot;, &quot;hi there&quot;, &quot;hello&quot;, &quot;I am glad! You are talking to me&quot;]</pre><pre>def greeting(sentence):<br>    &quot;&quot;&quot;If user&#39;s input is a greeting, return a greeting response&quot;&quot;&quot;<br>    for word in sentence.split():<br>        if word.lower() in GREETING_INPUTS:<br>            return random.choice(GREETING_RESPONSES)</pre><p>We will call Corpus of our chatbot and perform some NLP pre-processing steps on it, i.e., Sentence and Word Tokenization, Lemmatization, Normalisation. We are calling our Corpus as intro_join. Here We have taken an article from <a href="https://en.wikipedia.org/wiki/Athlete%27s_foot">Wikipedia</a> about a fungal disorder <em>Tinea pedis</em> (athlete’s foot) pasted into the text file. You can use your choice data by merely placing it in a file named “intro_join.”</p><pre>#Reading in the input_corpus<br>with open(&#39;intro_join&#39;,&#39;r&#39;, encoding=&#39;utf8&#39;, errors =&#39;ignore&#39;) as fin:<br>    raw = fin.read().lower()</pre><pre>#TOkenisation<br>sent_tokens = nltk.sent_tokenize(raw)# converts to list of sentences <br>word_tokens = nltk.word_tokenize(raw)# converts to list of words</pre><pre># Preprocessing<br>lemmer = WordNetLemmatizer()<br>def LemTokens(tokens):<br>    return [lemmer.lemmatize(token) for token in tokens]<br>remove_punct_dict = dict((ord(punct), None) for punct in string.punctuation)<br>def LemNormalize(text):<br>    return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))</pre><p>To make it look appealing, we will add the color pallet, which is a list of functions using the format command, for adding color to std terminal output.</p><pre>#colour palet<br>def prRed(skk): print(&quot;\033[91m {}\033[00m&quot; .format(skk)) <br>def prGreen(skk): print(&quot;\033[92m {}\033[00m&quot; .format(skk)) <br>def prYellow(skk): print(&quot;\033[93m {}\033[00m&quot; .format(skk)) <br>def prLightPurple(skk): print(&quot;\033[94m {}\033[00m&quot; .format(skk)) <br>def prPurple(skk): print(&quot;\033[95m {}\033[00m&quot; .format(skk)) <br>def prCyan(skk): print(&quot;\033[96m {}\033[00m&quot; .format(skk)) <br>def prLightGray(skk): print(&quot;\033[97m {}\033[00m&quot; .format(skk)) <br>def prBlack(skk): print(&quot;\033[98m {}\033[00m&quot; .format(skk))</pre><p>Now we will create a function for processing the user response converting it into a vectorized form and get the best result from Corpus via computing TF-IDF cosine similarity between the question and answer.</p><pre># Generating response and processing <br>def response(user_response):<br>    robo_response=&#39;&#39;<br>    sent_tokens.append(user_response)<br>    TfidfVec = TfidfVectorizer(tokenizer=LemNormalize, stop_words=&#39;english&#39;)<br>    tfidf = TfidfVec.fit_transform(sent_tokens)<br>    vals = cosine_similarity(tfidf[-1], tfidf)<br>    idx=vals.argsort()[0][-2]<br>    flat = vals.flatten()<br>    flat.sort()<br>    req_tfidf = flat[-2]<br>    if(req_tfidf==0):<br>        robo_response=robo_response+&quot;I am sorry! I don&#39;t understand you&quot;<br>        return robo_response<br>    else:<br>        robo_response = robo_response+sent_tokens[idx]<br>        return robo_response</pre><p>Now we are almost ready to print the First message from Bot. Being an Ironman fan, I have named mine after him. 😃</p><pre>#Recording voice input using microphone <br>file = &quot;file.mp3&quot;<br>flag=True<br>fst=&quot;My name is Jarvis. I will answer your queries about Science. If you want to exit, say Bye&quot;<br>tts = gTTS(fst, &#39;en&#39;)<br>tts.save(file)<br>os.system(&quot;mpg123 &quot; + file )<br>r = sr.Recognizer()<br>prYellow(fst)</pre><p>Now the snippet below uses all the functions we created so far. It is using speech recognition for registering user input using the microphone. Converting it into text form, Searching for its answers from the processed Corpus, and returning the output using text-to-speech. It will continue taking user input and answering until the user says Bye/Goodbye.</p><pre>while(flag==True):<br>    with sr.Microphone() as source:<br>        audio= r.listen(source)<br>    try:<br>        user_response = format(r.recognize(audio))<br>        print(&quot;\033[91m {}\033[00m&quot; .format(&quot;YOU SAID : &quot;+user_response))<br>    except sr.UnknownValueError:<br>        prYellow(&quot;Oops! Didn&#39;t catch that&quot;)<br>        pass<br>    <br>    #user_response = input()<br>    #user_response=user_response.lower()<br>    clas=classifier.classify(dialogue_act_features(user_response))<br>    if(clas!=&#39;Bye&#39;):<br>        if(clas==&#39;Emotion&#39;):<br>            flag=False<br>            prYellow(&quot;Jarvis: You are welcome..&quot;)<br>        else:<br>            if(greeting(user_response)!=None):<br>                print(&quot;\033[93m {}\033[00m&quot; .format(&quot;Jarvis: &quot;+greeting(user_response)))<br>            else:<br>                print(&quot;\033[93m {}\033[00m&quot; .format(&quot;Jarvis: &quot;,end=&quot;&quot;))<br>                res=(response(user_response))<br>                prYellow(res)<br>                sent_tokens.remove(user_response)<br>                tts = gTTS(res, &#39;en&#39;)<br>                tts.save(file)<br>                os.system(&quot;mpg123 &quot; + file)<br>    else:<br>        flag=False<br>        prYellow(&quot;Jarvis: Bye! take care..&quot;)</pre><p><a href="https://gist.github.com/nitinp14920914/220cbb0630110839021f6f0c265f7e0b">Complete Final script is Here.</a> Now let us run the Bot. I have pasted a few screenshots of the final output that will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J8q3DAAMSA54dj6Oh8-fYA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J5BTWMB1HN4GIX9Yd3nCew.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NGs3vSYAGv1B7O0g70iRVw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x-oi9kzhTGJj39iikNBCKQ.png" /></figure><h3><em>Conclusion</em></h3><p>We have demonstrated development of a Voice chatbot for voice input-output. As mentioned in the disclaimer, this is a pretty straightforward implementation accompanied by enhanced interfacing using speech recognition.</p><p>Furthermore, if you are feeling motivated and thrilled for chatbots, you can plan on considering the integration of Natural Language Understanding(NLU) using frameworks like RASA. You may also consider using relational and cloud-based databases like SPARQL which would be great to store the Q&amp;A log, and later on, applying some deep learning will improve your Bot a lot. Later on, GUI can also be integrated using the Django framework.</p><p>The original piece of the script was Sourced from <a href="https://github.com/parulnith/Building-a-Simple-Chatbot-in-Python-using-NLTK/blob/master/chatbot.py">Here</a>.</p><p>I hope you find this article useful .!!! <a href="https://github.com/nitinp14920914/chatbot_verbal">Here is the project link</a>.</p><blockquote>Also, thanks for the response on the previous version of this story, That offered chance for me to voluntarily take that down for correction and improvements .</blockquote><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=blog&amp;utm_campaign=noteworthy&amp;utm_content=eid8"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ArLSH4tuI2v4pF0giI3-OQ.png" /></a></figure><p>📝 Save this story in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_read_later_text">Journal</a>.</p><p>👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. <a href="https://usejournal.com/newsletter/noteworthy-in-tech/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=tech&amp;utm_content=guest_post_text">Read the Noteworthy in Tech newsletter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=445468c083f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>