CHAPTER 6

Reading Minds 💭

Computers don't understand feelings. They only understand numbers.
But can Robo read a text message and know if you are Happy or Sad?

This is called Natural Language Processing (NLP).

🎒 Bag of Words

Robo counts special "feeling" words.

Good Words: ["love", "great", "happy"]
Bad Words: ["hate", "sad", "awful"]

Sentence: "I love this great game!"
Score: 2 Positive Words -> HAPPY!

EMOTION DETECTOR 😃😭

Step 1: The Input

Our message is a list of words. (The computer has already split them for you).

message = ["i", "love", "this", "great", "game"]
happy_score = 0
Waiting for you to run code...

Step 2: Hunt for Happy Words

Check each word. If it's "love" or "great", add to score.

for word in message:
    if word == "love":
        happy_score = happy_score + 1
    if word == "great":
        happy_score = happy_score + 1
print(happy_score)
Locked 🔒

Step 3: The Verdict

If the score is bigger than 0, it's a Positive message.

if happy_score > 0:
    print("This person is Happy!")
else:
    print("No happiness found.")
Locked 🔒
📃

Logic Check 📝

1. The sentence is: "The movie was not great". What score does our primitive robot give it?

⌨️ NLP LAB
Waiting...