The recent advancements in natural language processing over last few decades allowed a significant number of enterprises to leverage the potential of sentiment analysis by training artificial intelligence through deep learning and machine learning algorithms to teach the machine and perform particular operations similar to what humans apply through cognitive abilities. Though, the machines cannot comprehend, perceive, and process the scenarios through life-like experience, advanced techniques such as reinforcement learning and neural networks made it possible to engineer the machines to process data through neural machine translations. Opinion mining and sentiment analysis allows enterprises to extract the sentiment from the text to understand the swarm intelligence evolving from a particular group on a particular topic. However, since the sentiment can stem from several perspectives such as pure emotional reaction, judgement, or just evaluation. Net neutrality is a key factor to extract the insights for performing the analysis on the text. Enterprises need to make better product decisions, either in improving an existing product or to launch a new product. The customers are key stakeholders in providing the sentiment through thousands of texts. The texts can contain positive reviews, negative reviews, or some may remain just neutral. The sentiment analysis can provide insights on the positive talk created by the customers on various aspects of the business, about the brand perception that’s way better than the competitors. Going beyond the polarity of the text can be achieved through classification of the text through social networks. The customer service delivered by many organizations also need the tonality of the voice and the measurement of the customer satisfaction in terms of waiting queues and response assessment. Microsoft Research Labs in Washington conducted a sentiment analysis on women to assess the risk based on the text to evaluate the postnatal depression indicated by the anxiety and unhappiness in the text before giving the birth.
Semantic and sentiment analysis
Natural language processing has a broad range of applications for the inference of semantics and sentiment from the text. Q & A systems, speech recognition, and contextual recognition. The entire spectrum of words shows particular lexical relations, hierarchies, composition, representations, and contextual relationships. There are several topics that delve deeper into the semantic analysis such as WordNet, lexical semantic relation analyzers, synsets, named entity recognition, word sense disambiguation, and semantic relationship analysis. In 1985, Princeton University invented a massive-scale lexical database in the English language dubbed WordNet in the Cognitive Science Laboratory. The database contains verbs, adjectives, nouns, adverbs, and related lexical terms. The grouping of common concepts into sets gave rise to the synsets that has distinct concept. WordNet works similar to a Thesaurus with a set of words and corresponding synonyms. The WordNet consists around 155,000 words represented in various synsets closer to 117,000 synsets with 206,000 word-sense pairs.
Figure 1. NLTK for natural language processing.
NLTK is the most popular library for natural language processing. NLTK library can turn tokens into vectors. NLTK can also import the WordNet language dictionary to make best use of the key features. The word distributions can be stored in Redis or MongoDB as a backed corpus.
Logistic regression machine learning classier considered for the Python implementation as it has the weights with neural network architecture for Amazon Electronics Reviews. Especially logistic regression is a machine learning classifier and not a regression that works well on linearly separable classes. Logistic regression can perform binary classification and can extend to multiclass classification as well. Logistic regression is the most popular machine learning classifier in Computer Science. Since the dataset contains the files in XML, an XML parser can be utilized with BeautifulSoup library. Initially, the code goes through the vocabulary size and the corresponding index of the word and creation of vectors. In the second pass, logistic regression can be applied as a machine learning classifier that performs the binary classification by interpreting the weights of the reviews. Through logistic regression we separate the data by the hyper plane by calculating the plane itself. If the feature vector X is greater than zero, it will be assigned to the positive class, if it is negative, it will be assigned to negative class. The logistic regression works here on the neural network architecture with each input being a neuron multiplied by its weight and the results get summed towards the end generating the output. The inner product gets passed in logistic regression through a sigmoid function to produce the probability between zero and one with a positive review > 0.5 and negative review < 0.5.
Figure 2. Logistic regression neural network architecture
Figure 3. Python code implementation for NLTK for sentiment analysis
The results display the sentiment analysis with positive and negative review accuracy based on the logistic regression classifier for particular words.
Figure 5: Results
Fandango, A. (2017). Python Data Analysis — Second Edition (2 ed.). Birmingham, England: Packt Publishing.
Hardeniya, N. (2016). Natural Language Processing: Python and NLTK. Birmingham, England: Packt Publishing.
Kumar, A., & Babcock, J. (2017). Python: Advanced Predictive Analytics. Birmingham, England: Packt Publishing.
Marr, B. (2016). Key Business Analytics: The 60+ Business Analysis Tools Every Manager Needs To Know. Upper Saddle River, New Jersey: FT Publishing International.
Massaron, L., & Boschetti, A. (2016). Regression Analysis with Python. Birmingham, England: Packt Publishing.
Raschka, S., Julian, D., & Hearty, J. (2016 Python: Deeper Insights into Machine Learning. Birmingham, England: Packt Publishing.
kar, D. (2016). Text Analytics with Python A Practical Real-World Approach to Gaining Actionable Insights from your Data. New York City, New York: Apress Media LLC.
Swamynathan, M. (2017). Mastering Machine Learning with Python in Six Steps. New York City, New York: Apress.
TensorFlow Community (2018). MNIST for ML Beginners. Retrieved May 12, 2018, from https://tensorflow.rstudio.com/tensorflow/articles/tutorial_mnist_beginners.html
Thanaki, J. (2017). In Python Natural Language Processing. Birmingham, England : Packt Publishing.