From the course: Hands-On AI: Build a Generative Language Model from Scratch

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Building a naive Bayes classifier

Building a naive Bayes classifier

- [Instructor] There are various methods of performing sentiment analysis. The one we'll look at is called Naive Bayes. It's a pretty straightforward approach. What I like about it is that while it's not as effective as more advanced approaches, you can implement it using pure Python code. And that's going to really help us wrap our heads around how this mechanism works. So we're going to have this data set, and it's a list of tuples, and each one has a comment and a label. The label is pos for positive, and neg for negative. Now we're going to go over each one of these, break it down into tokens, and we'll keep count of how many times each token exists in negative connotations and how many times it exists in positive connotations. Then we'll take a brand new input that we haven't classified yet, and for each token in that input, we'll ask ourselves what's the likelihood of it coming up in a positive post, and what's…

Contents