AI Trained to Perform Sentiment Analysis on Amazon Electronics Reviews in JupyterLab

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

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

Figure 4: Code I posted on Github


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

Thanaki, J. (2017). In Python Natural Language Processing. Birmingham, England : Packt Publishing.

23 thoughts on “AI Trained to Perform Sentiment Analysis on Amazon Electronics Reviews in JupyterLab

  1. yeezy shoes Posted On

    Thanks a lot for providing individuals with an extremely special opportunity to check tips from this site. It really is so superb and packed with amusement for me and my office acquaintances to search your website at least thrice a week to read through the newest things you have. And definitely, I am also usually fascinated concerning the cool knowledge served by you. Certain two points on this page are rather the most effective I’ve ever had.

  2. adidas yeezy boost Posted On

    I simply wanted to type a remark to appreciate you for all the fabulous tactics you are showing at this site. My extensive internet investigation has now been paid with incredibly good knowledge to go over with my company. I would believe that we site visitors actually are unquestionably blessed to be in a great place with so many perfect individuals with helpful secrets. I feel very much blessed to have used your entire web pages and look forward to many more thrilling moments reading here. Thanks a lot once again for everything.

  3. nike lebron soldier 10 Posted On

    I simply had to thank you so much again. I am not sure the things I would’ve worked on in the absence of the smart ideas shown by you concerning my problem. It has been a traumatic difficulty for me, nevertheless spending time with a expert form you resolved the issue made me to leap with joy. I will be happy for this help and even hope that you realize what an amazing job that you’re getting into teaching some other people thru your website. I know that you have never got to know any of us.

  4. ferragamo belt Posted On

    I wish to voice my love for your kindness for folks that should have guidance on this one topic. Your real commitment to passing the message along had been incredibly powerful and has specifically allowed professionals like me to attain their targets. Your entire insightful hints and tips can mean this much to me and still more to my fellow workers. Thank you; from everyone of us.

  5. off white shoes Posted On

    Can I simply say what a aid to search out somebody who truly knows what theyre speaking about on the internet. You positively know how you can bring a difficulty to mild and make it important. Extra folks must learn this and perceive this side of the story. I cant believe youre not more popular because you definitely have the gift.

  6. yeezy boost Posted On

    My husband and i have been now joyful when Peter managed to finish up his web research while using the precious recommendations he discovered from your own blog. It’s not at all simplistic to just continually be giving freely strategies which people might have been trying to sell. And we also do understand we need the blog owner to give thanks to for this. Most of the illustrations you’ve made, the easy web site menu, the relationships your site help instill – it’s all amazing, and it’s leading our son and our family recognize that that idea is entertaining, and that is wonderfully indispensable. Many thanks for everything!

  7. yeezy Posted On

    Good post. I be taught one thing tougher on completely different blogs everyday. It should at all times be stimulating to read content material from other writers and apply a little bit something from their store. I抎 favor to use some with the content material on my weblog whether or not you don抰 mind. Natually I抣l offer you a link on your internet blog. Thanks for sharing.

  8. nike lebron 15 Posted On

    Aw, this was a very nice post. In concept I would like to put in writing like this additionally ?taking time and precise effort to make an excellent article?however what can I say?I procrastinate alot and on no account seem to get something done.

  9. adidas yeezy Posted On

    I found your blog site on google and test a number of of your early posts. Continue to keep up the excellent operate. I simply further up your RSS feed to my MSN Information Reader. Seeking ahead to reading extra from you in a while!?

  10. Adidas NMD XR1 Black Red White Posted On

    Thank you so much for providing individuals with an extremely breathtaking chance to read articles and blog posts from here. It’s always very enjoyable plus stuffed with a lot of fun for me personally and my office peers to search your web site not less than thrice per week to find out the new items you have got. And indeed, I am just at all times fulfilled concerning the cool methods served by you. Some 1 ideas on this page are surely the most suitable we have all had.

  11. ultra boost 3.0 Posted On

    I precisely needed to appreciate you again. I do not know the things that I would’ve used in the absence of the actual creative concepts shown by you directly on this situation. It actually was the frustrating condition in my opinion, however , understanding the specialized strategy you handled it forced me to cry for gladness. Now i’m thankful for your support and as well , believe you find out what an amazing job that you’re providing instructing most people via your blog. I am certain you haven’t encountered all of us.

  12. supreme hoodie Posted On

    After examine a few of the blog posts in your web site now, and I really like your approach of blogging. I bookmarked it to my bookmark web site list and will likely be checking again soon. Pls try my website as nicely and let me know what you think.

  13. yeezy boost 350 Posted On

    I precisely wished to thank you very much all over again. I’m not certain the things I could possibly have handled in the absence of the entire suggestions documented by you on such a topic. Entirely was the distressing setting in my circumstances, but observing your specialised strategy you solved it forced me to cry with gladness. I’m happy for the information and sincerely hope you realize what an amazing job that you are putting in training the others via your web blog. Most probably you have never encountered all of us.

  14. moncler Posted On

    I抦 impressed, I must say. Really rarely do I encounter a blog that抯 both educative and entertaining, and let me let you know, you might have hit the nail on the head. Your idea is outstanding; the difficulty is one thing that not enough persons are speaking intelligently about. I am very blissful that I stumbled across this in my search for one thing regarding this.


Leave a Reply

Your email address will not be published. Required fields are marked *