Bots are everywhere around us. Most days we feel we are talking to a human, we are, talking to a bot. They help to automate some of the mundane repetitive tasks so those who have this ideology have a good friend in a bot. That being said, there are also negative sides to automation. We cannot teach every aspect to a Bot. There would always be something we miss. 100% accuracy doesn’t exist in prediction like most Machine Learning Engineers and Data Scientists know.
I have built a basic NLP related chatbot that does two specific things: It tells you the Stock price of the Stock that you are interested in and if you aren’t interested in stocks, you can be interested in learning about the other application: Text Analytics. When I mean text analytics, I mean, you can enter a piece of text from any document, webpage (reviews for a product, tweets, etc.), we can see what the author’s emotion was when he wrote that piece. This is one aspect of text analytics and the other one is, you can get a summary of the text. A WordCloud. For those who aren’t familiar with the term WordCloud, you will be once I show the demo below.
I have used the Chat module with the NLTK package in Python for my chatbot. Chatterbot is one of the other more advanced chatbot modules out there. I was able to achieve what I wanted with the NLTK Chat module.
For the stock application, I am using a combination of the Yahoo_fin module and the yfinance module in Python. The Yahoo_fin module gives you the latest stock price for the stock. The yfinance module will be used to see the trend in the stock.
For the text analytics part, I am using the NLTK Vader module to check the sentiment of the text and wordcloud package to generate the word cloud.
So, let’s get to the demo:
As you can see above, I am calling the function chatbot, which then prints a default message to enter the module I would like to be entered in: Stock or Text Analytics. If I enter “Stock”, it welcomes me to the “Stock” app. Once in the app, I have to enter the symbol of the company I would be interested in knowing the stock price/trend for. I entered APPLE’s symbol (AAPL) here.
This gives me the current price, the trend graph for the current year. The discontinuity here in the graph indicates there was some data issue during that time. Also, it also gives the stock trend for the current month as shown below. All this while entering just one stock symbol.
The graph is interactive and was made using plotly.
This is a continuous conversation, courtesy of the converse() method in nltk.chat.util
If you are interested in finding more stock prices, you can continue to enter the stock symbol or type quit to exit the stock app. If you type quit as I did above, you will be directed back to the opening page, where you have to enter stock or text analytics.
Let’s move on to the text analytics section.
Instead of stock, if you choose to enter ‘text analytics’, you will be entered in the text analytics app. It would ask you to input a text for the analytics. Once you enter the text, hit enter and you can see the emotion score of the text. The negative word ‘angry; brings the negative score to 0.14, a few positive words to 0.206, and so on. A word cloud is generated for the text to give you a gist of the author’s content.
There’s a lot more a chatbot can do and I am working towards where I can take it. Feel free to reach out if you have any questions. You can reach me on LinkedIn. I am happy to put my skills to use.
Hutto, C.J. & Gilbert, E.E. (2014). VADER: A Parsimonious Rule-based Model for Sentiment Analysis of Social Media Text. Eighth International Conference on Weblogs and Social Media (ICWSM-14). Ann Arbor, MI, June 2014.