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?"
Rahat 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!”
Rahat: “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.
Learn it
A chatbot is a program that holds a conversation, by text or voice, and it is one of NLP's commonest uses. There are two kinds. A script bot looks for keywords and gives the answer someone wrote for them: cheap, predictable, and unable to learn. A smart bot learns from huge amounts of data and handles far wider language, and can be wrong in fluent, confident sentences. The Eid question broke Rahat's bot because a script bot matches words, not meaning.
Words to know
- Chatbot a program that holds a conversation by text or voice: help desks, shop websites, government services.
- Script bot follows a script: looks for keywords and gives written answers. Needs little data and computing, and never learns.
- Smart bot learns from large amounts of data, handles wider language and context, and improves with use. Needs huge data and computing.
- Keyword a word the bot looks for in your question, like
"bus". - Dictionary (Python) — pairs of keys and values:
{"bus": "The bus leaves at 3:30."}. - ELIZA a script bot from 1966 that pretended to be a counsellor by turning your words back into questions.
Step by step: a three-line script bot
answers = {"bus": "The bus leaves at 3:30.", "fees": "Fees are due on the 10th."}
question = input("You: ").lower()
for keyword in answers:
if keyword in question:
print("Bot:", answers[keyword])
.lower()turns "When does the BUS leave?" into lowercase, so"bus"can be found.- The loop checks each keyword in turn: is
"bus"in the question? Yes → print its answer. - No keyword? Ask "Is the canteen open?" and nothing prints: it has no answer outside its script.
- Wrong meaning: "Can I pay the bus fees?" contains both keywords and gets two answers, neither quite right.
- Order matters: put a specific keyword (
"eid") before a general one ("holiday") so it is checked first.
Careful: a script bot does not learn from its mistakes. If it answers wrongly, it will
answer wrongly forever, until a person changes its keywords. And forget .lower() and "When
does the BUS leave?" never matches "bus".
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.
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.
Typing practice
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%.