We all remember Jarvis! Jarvis is an interactive virtual assistant of Marvel Comics character IronMan. Virtual Assistants are all around us, be it in our smartphones, smart homes or on our websites. Chatbots are already dominating in majority of customer service roles as employed by Banks, Ecommerce giants and other B2C firms. Some companies are even considering chatbots for marketing efforts.
Merriam Webster defines AI is as “the capability of a machine to imitate intelligent human behavior”. So machine learning at its core is not about complex mathematical equations rather its about automation. When it comes to the recent advancements in AI, Deep Learning is considered to have shown a great promise in replicating human perceptions such as Vision, Auditory and Speech.
Training deep learning algorithms is computationally heavy, but thanks to the deep learning community across the globe, there are many open-source implementations/solutions available for us to work with. So let’s do a little project to get some hands on AI.
Required python libraries & packages.
The full project is available in my github repository here.
For the sake of simplicity, I had chosen weather querying as the context of usage for the chatbot. When you run the python code, The conversational AI would introduce itself and listen for your query. To simplify the project we shall listen for only 7 seconds. Once the bot receives your query, it will convert the Audio input into text using the SpeechRecognition Library in python.
Natural Language Processing
Once the user_query is converted to text, the bot will then process the identified text using the NLP package Spacy to extract intents and entities(To know more about Intents and Entities refer here). Below shown is the code to identify relevant entities like Geo_Loc(Geographical Location) and Time_date.
Once the relevant entities are identified and extracted, the bot will then ping the metaweather API to get the weather status. We will use a custom_string to generate the reply. The generated reply(text) shall be converted to speech using the python library gTTs. The code to which is shown below.
Date parsing is another important aspect to successfully retrieve information from the metaweather API. I’ve made use of timefhuman and dateparser libraries in python to convert the date text into mm/dd/yyyy format. The code to which is shown below.
Hot words or Trigger words like “Okay Google”, “Alexa”, “Hey Siri” is also important to have in a chatbot. While this is an interesting feature to have, it doesn’t affect the functionality of the bot. The open source implementation for Trigger word detection is explained in the Andrew NG’s Deep Learning course on “Sequence Models”. We will also need Deep Learning Package “Keras” to implement the model for hot word detection. I will be inculcating this feature later on.
Directions to use:
- Install the relevant python packages
- Clone the github repo.
- Go to the directory in terminal.
- Run the weatherbot.py file in python.
- Wait for the welcome text to be spoken.
- Ask for weather status of a single city for a single date. Eg. “What’s the weather in New York, yesterday?” or “What’s the weather in Philadelphia, 4th of July 2015?”
Note: The bot can only work with the cities that are configured in the metaweather API. I found that there is an issue when working with locations with names that have two words. Eg: “San francisco” etc. Having said that, the bot works well for most major cities in the world.
Sources and References:
Thank you Google. 🙂
Thank you Spacy!
Thank you timefhuman — package(Python Library) for converting my date entities to numbers!
Lastly, Thank you for you time.