Speech Sentiment Analysis in IoT

Final Project
31st August 2020

The final project in the course DSL810: Prototyping in IoT was about integrating the different prototyping skills learnt in the course into a project. Hence, I decided to work on the project: Speech Sentiment Analysis in IoT. The project uses data science, electronics (input+output device) + (uC + embedded programming) skills as well as UI in mobile app.



Project Video




Project Slide




Sentiment Analysis


Sentiment analysis is the interpretation and classification of emotions (positive, negative and neutral) within text data using text analysis techniques. Understanding people’s emotions is essential for businesses since customers are able to express their thoughts and feelings more openly than ever before. By automatically analyzing customer feedback, from survey responses to social media conversations, brands are able to listen attentively to their customers, and tailor products and services to meet their needs.




Data Used


I've used the dataset available online at Kaggle. 2 files we provided on the website:


• train.csv

• test.csv


In the training set I was provided with a dataset in which each row contains the text of a tweet and a sentiment label (positive, negative, neutral).



Code


Below is the entire code for this assignment written in Jupiter Notebook exported as an html file:


Sentiment Analysis



Approach: Explaining the Code


First task was to examine the data closely, dropping null values, and cleaning the data. The "shape" of the dataset extracted shows that it has 27480 rows, which are tweets, and has 2 columns, namely "text" and "sentiment".





Exploratory Data Analysis


• To gain a preliminary understanding of available data

• Check for missing or null values

• Find potential outliers

• Assess correlations amongst attributes/features

• Check for data skew









Preprocess Text


Text Preprocessing is traditionally an important step for Natural Language Processing (NLP) tasks. It transforms text into a more digestible form so that machine learning algorithms can perform better.



• Lower Casing: Each text is converted to lowercase.

• Replacing URLs: Links starting with "http" or "https" or "www" are replaced by "URL".

• Replacing Emojis: Replace emojis by using a pre-defined dictionary containing emojis along with their meaning. (eg: ":)" to "EMOJIsmile")

• Replacing Usernames: Replace @Usernames with word "USER". (eg: "@Kaggle" to "USER")

• Removing Non-Alphabets: Replacing characters except Digits and Alphabets with a space.

• Removing Consecutive letters: 3 or more consecutive letters are replaced by 2 letters. (eg: "Heyyyy" to "Heyy")

• Removing Stopwords: Stopwords are the English words which does not add much meaning to a sentence. They can safely be ignored without sacrificing the meaning of the sentence. (eg: "the", "he", "have")

• Lemmatizing: Lemmatization is the process of converting a word to its base form. (e.g: “Great” to “Good”)









ML Model


For the sentiment analysis, I used the logistic regression model. Logistic regression is the appropriate regression analysis to conduct when the dependent variable is dichotomous (binary). Like all regression analyses, the logistic regression is a predictive analysis. Logistic regression is used to describe data and to explain the relationship between one dependent binary variable and one or more nominal, ordinal, interval or ratio-level independent variables.





Flask API



Flask API provides an implementation of browsable APIs similar to what Django REST framework provides. It gives you properly content negotiated-responses and smart request parsing. I used Flask API to create a URL to input the text. This URL was required to run the Machine Learning Model on the MIT App Inventor.





• Positive: 0

• Neutral: 1

• Negative: 2









MIT App Inventor



I used the MIT App inventor for 3 purposes: Converting speech to text, running the ML model on the app to find out the sentiment, sending over the data over HC05 Bluetooth module.



Below is the App used in this project:


Sentiment Analysis App



UI for the app:


For converting speech to text:


For running the ML Model on the MIT App Inventor:


For sending input via bluetooth:




Arduino



Below is the Arduino Code used in this project:


Sentiment Analysis Arduino Code



The result of the sentiment analysis was sent to the Arduino via HC05 Bluetooth module. The output was given by the Built In LED of the Arduino.



• Positive: LED is turned On

• Neutral: LED starts blinking

• Negative: LED is turned Off









Real Life Application





The concepts shown with this project can be applied on a larger scale in real life. One of the use case can be in the domain of smart homes. The voice assistant currently understand only the meaning of the command given to it by the user, with considering his emotional state. With AI powered voice assistants, they can not only understand the meaning but also the emotion behind the voice command. For example, if a user is in a bad mood, AI can understand it, and in an IoT ecosystem, the voice assistant can send this information to the music system, so that the music system can better understand what to play in order to lighten the user's mood.