From the course: Delivering and Analyzing a Software Pilot: GitHub Copilot

Techniques to identify sentiments and themes - Github Copilot Tutorial

From the course: Delivering and Analyzing a Software Pilot: GitHub Copilot

Techniques to identify sentiments and themes

- [Instructor] Have you ever read a review and instantly known whether it was positive or negative? Our brains are wired to pick up on sentiments and themes, but when it comes to large data sets, we need the help of technology to do it effectively. In this video, we're going to explore the techniques to identify sentiments and themes within text data. We'll walk through a coding example where we extract sentiments from individual product reviews, and by the end, you'll be able to automate this process and apply it to your own data sets. So in my jupyter notebook, let's say I have seven reviews for GitHub Copilot or whatever software I happen to be piloting. If I were to sit and read through these, I could ascertain whether or not they were positive, negative, or neutral. But if there was multiple or hundreds or thousands of these, that would be impossible. So in order to have code do this for me, what I'm going to need to do is say from textblob, import textblob, and then I will need those sample reviews. So I will say reviews = square bracket, very important. And then paste those reviews in there, making sure that at the end of each review or line of text, I have a comma and everything is encapsulated in its own set of double quotes. So I now need to analyze the sentiment for each review and classify it as positive, negative, or neutral. So for this, I'm going to say for review in reviews, blob = Text Blob (review) then sentiment = blob.sentiment.polarity. Okay, so now I need to classify the statements. So if I say if, just scroll down a bit as well, if sentiment > 0: then the sentiment_type = "Positive". And I'm going to say elif the sentiment == 0 oops, 0: then the sentiment_type = "Neutral." And also else if the sentiment_type = "Negative." So what this does is it looks at the sentiment score. If it's higher than zero, it'll be positive. If it's zero, it'll be neutral. And if it's lower than zero, it'll be negative. And now I need to output the sentiment type and score. So if I say print and then f " Review: and then space ' { }. I want review, which will then be in those single quotes that I mentioned a second ago, instead of being there, has a sentiment score of, and then whatever the sentiment is {sentiment} and is classified as the sentiment_type. And then close curly bracket, close quotations, and close parentheses. And that should be everything. Now, if I've run this, we can see that it has taken those reviews, scored them, and given us an actual type classifier for it. So the first review, you can see that it has scored it as 0.46875, which is very specific, and it's classified as positive because it's more than zero. The second one is 0.0, and therefore it's neutral. And the third one is minus 0.4, and it's classified as negative and so on and so on. So by analyzing these sentiment scores, you can quickly assess the overall tone of the reviews. This is particularly useful when dealing with large volumes of text data where manual analysis would be far too time consuming. To summarize, sentiment analysis is a powerful technique for understanding the emotional tone of text data. And by using libraries like Text Blob, you can easily extract sentiments from reviews, social media posts, and other textual content. And coming up next, we'll explore not only how to get the qualitative data from your reviews and feedback, but the quantitative data that are the hard metrics that will fuel your visualizations and your charts. So stay tuned.

Contents