Class 10 · Unit 5: Natural language processing · Lesson 5.2 · 40 min
Chatbots: script bot and smart bot
Ask the school bot about the Eid holiday and it tells you about winter vacation — confidently. Why?
Today you will: Tell a script bot from a smart bot · Run and extend a script bot in Python · Find the questions that break it
Story
The school office gets forty phone calls a day, all asking the same five things. The head teacher asks the Class 10 club for help. "Can you make something that answers them?"
Bilal writes a bot in twenty lines of Python. It knows timings, fees, the library, the bus, and holidays. Everyone tries it and it's perfect.
Then Hiba types: "Is there a holiday for Eid?"
Bot: Winter vacation starts on 1 December.
Hiba: “That's not what I asked!”
Bilal: “It saw the word holiday. That's all it can see.”
Watch
Bots that follow scripts, and bots that learn — — scan code 10.5.2 in the printed book.
Warm up your fingers
Skill: a Python dictionary (5 min)
-
On typing.com: the symbols lessons.
-
Type three times, eyes on the screen:
answers = {"bus": "The village bus leaves at 3:40."} -
Curly brackets, a colon between key and answer. Goal this term: 38–44 WPM at 95%.
On the laptop
You need: Thonny · programs/school_bot.py
Mission 1: Run it (7 min, in pairs)
- ☐1
Open
school_bot.pyin Thonny. Read the dictionaryanswers: five keywords, five answers. - ☐2
Predict: what will it say if you type "when does the bus leave?" — and "is the canteen open?" Write both.
- ☐3
Run it and ask both. Type
byeto stop.
Mission 2: Break it (8 min)
- ☐4
Take turns asking it real questions a student or parent might ask. Write every question it gets wrong in a list, and next to each, why:
- no keyword it knows
- a keyword, but the wrong meaning (the Eid question)
- two keywords at once
- a spelling it doesn't expect
Mission 3: Extend it (8 min)
- ☐5
Add two new entries to
answersfor questions your list showed people really ask. - ☐6
Fix one problem from Part 2 — for example, put a more specific keyword like
"eid"before"holiday"so it is checked first. Predict, then test.
Finished early?
Make the bot understand "timings" and "time" as well as "timing". How
many spellings would you need to cover everything people type?
No laptop today?
One student is the bot, holding a card with the five keywords and answers. They may only read out an answer when they hear a keyword — no thinking allowed. The class asks questions and keeps the list of failures. Then write two new cards.
Now you know
- A chatbot holds a conversation by text or voice — one of NLP's commonest uses.
- Script bot: follows keywords and written answers. Cheap and predictable; never learns; fails outside its script.
- Smart bot: learns from huge data, handles wider language and context. Needs lots of data and computing — and can be fluently wrong.
- A script bot in Python is a dictionary of keywords, a loop and an
incheck. - Keywords are not meaning. "Holiday" in an Eid question is still the word "holiday".
Debate it
The school office could use a smart bot instead — one of the big AI chatbots.
- What would it do better? What might it say that the school never approved?
- Parents would type their children's names, classes and problems into it. Where would those go? (Unit 1: the ethics review.)
Check yourself — practice, not a test
1. A bot that answers only when it finds a keyword it was given is a:
- ○ Smart bot
- ○ Script bot
- ○ Neural network
- ○ Search engine
2. A script bot gets better on its own the more people use it.
- ○ True
- ○ False
3. In school_bot.py, the keywords and answers are stored in a Python ______.
4. Match each to its kind of bot:
Needs little data; follows a written script · Learns from huge data; handles wider language
Match with: Smart bot · Script bot5. Put these lines in order so the bot answers one keyword (lines inside the loop are indented):
- 1. for keyword in answers:
- 2. print("Bot:", answers[keyword])
- 3. if keyword in question:
- 4. question = input("You: ").lower()
Remember
A script bot matches words. Understanding needs meaning.