0% found this document useful (0 votes)
4 views26 pages

Ai Module 4 Notes

Module 4 introduces prompt engineering, the practice of crafting effective prompts to enhance AI responses, particularly with Large Language Models (LLMs) like ChatGPT. It discusses the evolution of language models from simple prediction systems to advanced architectures like Transformers, highlighting the importance of prompt engineering in obtaining accurate and creative outputs. The module also covers various levels of prompt sophistication, from basic instructions to advanced agency, emphasizing the role of static and dynamic content in prompts.

Uploaded by

namithaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views26 pages

Ai Module 4 Notes

Module 4 introduces prompt engineering, the practice of crafting effective prompts to enhance AI responses, particularly with Large Language Models (LLMs) like ChatGPT. It discusses the evolution of language models from simple prediction systems to advanced architectures like Transformers, highlighting the importance of prompt engineering in obtaining accurate and creative outputs. The module also covers various levels of prompt sophistication, from basic instructions to advanced agency, emphasizing the role of static and dynamic content in prompts.

Uploaded by

namithaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

MODULE 4 INTRODUCTION TO AI

MODULE 4
CHAPTER 1:Introduction to Prompt Engineering
What is Prompt engineering?
Prompt engineering simply means crafting good questions or instructions
so that AI (like chatgpt) gives the best possible answer.
Prompt engineering is the skill of writing clear, structured prompts
(questions or commands) to get accurate, useful, or creative outputs from
AI models.
Why it’s needed

AI responds based on the input you give.


A small change in how you ask → big change in the answer.

What is LLM
A Large Language Model(LLM) is an AI system trained on huge
amounts of text so it can understand language and generate human-like
answers. What LLMs can do?
Examples of LLMs Answer questions

Write essays, emails, code


ChatGPT
Summarize and explain information
Google Gemini
Help with programming

Translate languages

Chat like a human

Introduction to Prompt Engineering


ChatGPT launched in November 2022 and quickly reached 100 million
users within two months — faster than any other app like TikTok or
Instagram. People loved it because Large Language Models (LLMs)
changed how we search, learn, and work.
Instead of Googling, reading blogs, or going through tutorials, users can
now directly ask an LLM for personalized answers, explanations, or even
working code.
In the future, LLMs will likely be everywhere — in customer support
calls, ATMs, smart home assistants, email tools, travel booking systems,

NAMITHA AV/ASST. PROF/SJEC 1 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

and shopping assistants. These AIs will help summarize news, write
emails, plan trips, and handle daily tasks.
Even though LLMs seem magical, they are actually simple prediction
machines:they take text and predict the next word based on patterns
learned during training. That’s their core function.

Because they operate based on the prompts we give them, the way we
write instructions—called prompt engineering—is extremely important. It
helps us control and guide the AI to produce useful, accurate, and creative
results.

LLMs Are Magic


Two developers (Albert and John) worked on GitHub Copilot, an AI tool
that helps you write code. Both of them experienced a moment where
they realized LLMs are unbelievably powerful, almost like magic.
Albert’s Story (2020)

Albert was working in a team that researched AI for writing code.

Every 6 months someone would say:


“One day AI will write code like humans… but not anytime soon.”
Everyone believed it would take 5+ more years.

But then Albert tested the early model that later became OpenAI Codex.
Suddenly he saw:
The AI could write entire lines and functions,
Just by reading a small comment (docstring).
The functions actually worked!

This was the moment he realized:


👉 The future had arrived earlier than expected.
They tested it with actual GitHub engineers:
Some tasks were easy, some were very hard.
Copilot solved most of them if you gave it a few tries.

Albert knew:
This is the engine for a new era of coding.

NAMITHA AV/ASST. PROF/SJEC 2 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

John’s Story (2023)


John experienced the magic while using the finished product — GitHub Copilot.

He gave the AI a challenge:


👉 Write a function that converts any number into words, but in Rust (a language he did NOT know).
Normally, learning a new language requires:

Googling syntax

Reading documentation

Checking Stack Overflow

Then:

He wrote comments explaining what he wanted.

Copilot filled in loops, vectors, and logic.

Copilot even taught him Rust while writing code!

Then something amazing happened:

NAMITHA AV/ASST. PROF/SJEC 3 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

What does this all mean?


LLMs like ChatGPT, Copilot, Bard, etc. are incredibly powerful.
They can:
Understand what you want
Generate code

Help you learn

Solve problems faster than traditional methods

But this didn’t happen overnight.


It took years of research to reach this level.

Language Models: How Did We Get Here?

A language model is a system that predicts the next word in a sentence.


Example:
If you type “I am going to the…”, it might predict “store”, “gym”, or
“park”.
This is similar to the suggestion bar on your phone keyboard.
But modern AI like ChatGPT is FAR more powerful than simple next-
word guessing.
How did we go from simple predictions to advanced AI that can translate,
summarize, chat, and reason?
Let’s see.
Early Language Models
1. Markov Models (1948)
These early models looked only at a few previous words and guessed the
next word.
Simple → Not very smart
They gave us things like basic autocorrect or predictive text.
2. 2014: Seq2Seq (Sequence-to-Sequence) Models
The next big breakthrough was Google’s seq2seq models.
Seq2Seq was one of the most important early models for tasks like:
Translation,Summarization,Chatbots,Text classification

NAMITHA AV/ASST. PROF/SJEC 4 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

These used recurrent neural networks (RNNs) to process text one token at
a time.
How Seq2Seq Works
It has two parts:
️Encoder
Reads the input text token-by-token.
Builds an internal “memory” of the sentence.
Produces a thought vector (A thought vector is a single, fixed-size
numerical summary of an entire sentence.).
️Decoder
Uses the thought vector to generate the output sentence.
Produces tokens one-by-one until it finishes
It processes text one token at a time, like humans reading.

It updates an internal memory for every new word.

It can handle any length of input text.

The figure shows how Seq2Seq translates:


English → Spanish
Example input:

NAMITHA AV/ASST. PROF/SJEC 5 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

NAMITHA AV/ASST. PROF/SJEC 6 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

STEP 5 — Decoder loops using its own output


So the steps repeat:

Decoder reads previous output token


Uses the thought vector
Predicts next word

NAMITHA AV/ASST. PROF/SJEC 7 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

The thought vector cannot store too much information → leads to poor results for long text

The 2015 Solution — Attention Mechanism (Soft Search)

Problem in Seq2Seq
Previously, the encoder created only one thought vector to summarize the entire input
sentence.
But this caused:
loss of information
poor quality translation for long sentences
Instead of giving a single summary, the encoder would give the decoder all hidden
states — one for EACH word.

So instead of:

Now :

This idea became known as the attention mechanism.

Transformer Architecture – “Attention Is All You Need” (2017)

In 2017, Google researchers published the famous paper “Attention Is All You Need”,
which introduced a new neural network design called the Transformer.
This architecture completely changed the direction of AI and Natural Language
Processing.
Before 2017, most models used RNNs, LSTMs, and seq2seq with recurrent
connections. These models processed sentences one word at a time, making them
slow and difficult to train.

NAMITHA AV/ASST. PROF/SJEC 8 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

The Transformer removed recurrence completely and instead used only:


➡ Attention mechanism
This mechanism allows the model to look at all words at the same time and
understand how each word relates to every other word in the sentence.

Key Features of the Transformer


1. Encoder–Decoder Structure
encoder takes input tokens (words) and converts them into meaningful embeddings.
Decoder produces the output tokens (e.g., translated sentence).
2. No recurrent layers (No RNN, No LSTM)
The transformer completely removed recurrence.
Everything is parallelized → much faster training.
3. Uses Only Attention
The model depends fully on attention to:
●Identify important words
●Capture relationships across long distances
●Represent context better
This is why the paper is titled “Attention Is All You Need”.

Difference between Seq2Seq and Transformer

Limitation
Transformers can process only a fixed sequence length (e.g., 512, 2048, etc.).
That’s why modern LLMs work on expanding their context window.

Transformers enabled the creation of models like:


●GPT-2, GPT-3, ChatGPT, Bard, Claude, LLaMA
These models understand language, answer questions, write content, generate code,
and perform many tasks that old models could never do. This is how we reached
today’s AI revolution.

NAMITHA AV/ASST. PROF/SJEC 9 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

GPT Enters the Scene (evolution)

[Link] of GPT (2018)


GPT stands for Generative Pre-trained Transformer.
Introduced in “Improving Language Understanding by Generative Pre-Training”.
The first GPT (2018) was basically:A transformer decoder only,(no encoder section)
What made GPT special?
Not the architecture…
But HOW it was trained:
Phase 1 – Pre-training
Feed massive amounts of unlabeled text .The model learns general patterns of
language.
Phase 2 – Fine-tuning
The model is trained on a specific task using labeled data, e.g., document
classification or answering questions
But once fine-tuned, GPT-1 could do ONLY that one task well.

2. GPT-2 (2019)
GPT-2 took the same architecture but:
Increased parameters from 117M → 1.5B
Increased training data 4.5GB → 40GB
With this scale, GPT-2 demonstrated emergent capabilities:
Trained to predict next word; could perform many tasks without task-specific fine
tuning.
Emergent capabilities:GPT-2 can answer questions,Do translation,Summarize
paragraphs,Understand pronouns ,Fill missing words,Write essays.
This is why the paper was titled:
“Language models are unsupervised multitask learners.”
concerns:Fake news generation,
Impersonating people,
Writing spam & phishing,Producing harmful or abusive content

3. GPT-3 (2020)
Another order-of-magnitude increase in both model size and training data: 175 billion
parameters.
Introduced few-shot learning:
By giving a few examples in the prompt, GPT-3 could perform almost any language
task.
This is where prompt engineering became crucial—users could condition the model to
perform specific tasks by crafting the right prompts.

[Link] and GPT-3.5 (2022)


ChatGPT was released in November 2022, built on GPT-3.5.
Offered conversational abilities and better fine-tuned performance for general-purpose
[Link] became the first AI to feel usable by everyone.
[Link]-4 (2023)
Rumored to be another order of magnitude larger in both parameters and training data.
Far more capable than GPT-3/GPT-3.5.

NAMITHA AV/ASST. PROF/SJEC 10 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Continued improvements in quality and versatility.

[Link] LLMs
■Llama (Meta)
■Claude (Anthropic)
■Gemini (Google)
Shows rapid innovation in the LLM space; capabilities continue to grow.

Prompt Engineering
Prompt engineering is simply the skill of giving good instructions (prompts) to a
language model (LLM) like ChatGPT so that it gives the answer you want.

Scope levels of sophistication :

[Link] Level
When you type directly into ChatGPT:
Your message = the prompt
Model reads it and completes it
Very simple

Example:
“You are a tutor. Explain AI simply.”
→ ChatGPT completes it.

This is the simplest form of prompt engineering.

[Link] Level(Improving the Prompt Automatically)


In real applications (like Copilot, Bing Chat, helpdesk bots), the application adds
extra helpful information to the prompt.
Example 1: Tech support bot
User speaks → App converts speech → Text goes into LLM
Plus:
Previous support tickets
Related documentation

Stateful interactions: LLM remembers previous context, like chat conversations, but
prompts must be managed to avoid overload or irrelevant content.

NAMITHA AV/ASST. PROF/SJEC 11 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Old exchanges can be dropped or summarized.


3. Tool-Augmented Level
LLMs can interact with APIs or external tools.
Example:
“Send John a meeting invite for May 5.”
The app must:
Let LLM search for “John ” in contacts
Check his availability
Compose and send the email
The prompt engineer must design:
How the LLM decides which tool to use
How to show tool results to the LLM
What to do if the tool fails
This is advanced prompt engineering.

[Link] Level:Giving LLMs Agency


LLM can make decisions to achieve broad [Link] modern systems try to let the
LLM act on its own to reach a [Link] can plan and execute multi-step tasks
autonomously.
Example:AutoGPT
You give:
“Research digital marketing and write a report.”
It will:
Break the task into steps,Search the web,Collect data,Write content
But these systems often fail unless the goals are small and clear.
Still, this is the future direction of AI apps.

NAMITHA AV/ASST. PROF/SJEC 12 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Chapter 2:Prompt Content

LLMs give better recommendations when you give them rich, descriptive text .
Prompt = Instructions + Information
When you talk to an LLM, you give it a prompt.

That prompt contains two types of content:


[Link] Content
[Link] Content

Static Content
Fixed instructions
Static content is the part of the prompt that does not change.
It gives fixed instructions, rules, or format to the model.
Think of it as the permanent [Link] by the developer
Same for every user
Used to define and clarify the task
Example:
Explain the concept of inheritance in object-oriented programming.
Here, the prompt is fixed. Every time you run it, the instruction is the same.
Why is clarification important?
Humans resolve misunderstandings by asking questions

LLMs cannot ask for clarification in programmatic use


Any confusion → wrong output
Good clarification gives:
Correct answers
Same behavior every time
User trust
This is called consistency

Two types of clarification

A. Explicit clarification-Explicit clarification is when instructions, constraints, or


expectations are directly and clearly stated in the prompt.
You directly tell the model what to do
Uses rules and instructions
Examples:
Use markdown
Don’t use hyperlinks
Don’t mention dates after 2024
✔ Easy to write
❌ Model may not follow all rules perfectly

NAMITHA AV/ASST. PROF/SJEC 13 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

[Link] clarification
Implicit clarification is when guidance is indirectly provided through context or
examples rather than direct instructions.
Instead of telling rules, you show behavior.
This is where few-shot prompting comes in.

Example :Implicit clarification using examples (few-shot)

NAMITHA AV/ASST. PROF/SJEC 14 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Zero-shot vs Few-shot prompting

Zero-shot prompt
Zero-shot prompting means asking the model to perform a task without giving any
examples.
The model relies only on:
Its pre-training
The instruction in the prompt and Model must infer everything
Structure:
Introduction
Main Question
Advantage
✅ Simple ,Gives quick results
Disadvantage
❌ More ambiguity
❌ Less consistent

NAMITHA AV/ASST. PROF/SJEC 15 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Few-shot prompt
Few-shot prompting means giving a small number of examples (2–5) in the prompt
before asking the actual question.
The model learns the pattern from examples.
Structure:
Introduction
Example Question 1 → Answer 1
Example Question 2 → Answer 2
...
Main Question
✅ More reliable
✅ More consistent
❌ Uses more tokens

NAMITHA AV/ASST. PROF/SJEC 16 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Why few-shot prompting works so well

LLMs have a strong tendency to:


Continue patterns they see in the prompt
So examples silently teach:
Output format
Tone
Style
Rules you never explicitly stated
This is why:

Implicit instructions often work better than explicit rules

Few-Shot Prompting: Why It’s Useful but Risky

Few-shot prompting is easy and powerful, but it has three major


drawbacks.
Drawback 1: Poor scalability with large context
Problem
Few-shot prompting works well when the examples are similar in
size and complexity to your main question.
•But If the main question contains lots of context (e.g., long user
profiles), adding examples makes the prompt too long and complex.

NAMITHA AV/ASST. PROF/SJEC 17 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

If your users have lots of information Even if the model


could read it all, repetitive, detailed examples can confuse
• If your prompt is too long, the AI might miss important
details
EX:For Person A, we know: {...lots of info...}, recommend Book X
For Person B, we know: {...lots of info...}, recommend Book Y
For Person C, we know: {...lots of info...}, recommend Book Z
Now you want the model to make a recommendation for a new user.
Problem: The model’s context window might not be large enough to process all that
information.
To be consistent, each example must include similar full context.

Drawback 2: Few-shot examples bias the model (Anchoring Effect)


What is anchoring?
Anchoring means:
Early information sets expectations that influence later decisions.
Humans do this — and LLMs do too.

NAMITHA AV/ASST. PROF/SJEC 18 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Drawback 3: Few-shot prompts create spurious (fake) patterns

Why it happens

Few examples It is a pattern that appears in the few-shot examples by accident,


but the model assumes it is meaningful and follows it.
LLMs are highly pattern-sensitive LLMs are very sensitive to patterns, especially when only a few
examples are given.

Why this happens?


Few-shot prompts contain very few examples
The model cannot know whether a pattern is designed or accidental
So it copies the pattern instead of reasoning from the input.

NAMITHA AV/ASST. PROF/SJEC 19 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Even if the new problem is actually easy, the model predicts failure because it followed the order
pattern, not the content.

What is Dynamic Content?


Dynamic content is the part of the prompt that changes each time based
on:
User input
Variables
External data
Context
Think of it as the fillable part of the prompt.
Example 1:
Explain the topic: {TOPIC}
Here, {TOPIC} is dynamic content.

NAMITHA AV/ASST. PROF/SJEC 20 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Dynamic content( consider book app)


Who is the user?
What books did they read?
What did they like or dislike?
Their preferences
This changes per user, so it must be collected dynamically.
The information is different for each user, so you cannot fix it in
[Link] have to collect it at the time the app is running, based on
who the user is.

What is “Context Preparation”?


Context preparation = collecting useful background information(mainly about the
user)
Example context:
User’s past reading history
Favorite genres
Recently liked books
Age, education level (if relevant)
This is the most time-consuming part of building such apps(dynamic app).

Key Considerations in Dynamic Content

First consideration: Latency (Time constraint)


Latency = how much time you have to collect context
Types of applications:
Low urgency
Can take long time
Example: Monthly book report email
Medium urgency
Can take 1–2 seconds
Example: Book recommendation after clicking a button
High urgency

Every millisecond matters


Example: Real-time chatbot reply

Second consideration: Preparability


Some dynamic data can be prepared in advance.
Example:
User’s favorite genre → rarely changes
Education level → almost never changes
So you:
Store it beforehand
Reuse it instantly when needed
Third consideration: Comparability
You should collect more context than needed first
Then later filter the most useful parts.
To filter, you ask:

NAMITHA AV/ASST. PROF/SJEC 21 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

Key comparison questions:


Is one item more useful than another?
Does one item depend on another?
Does one item cancel or contradict another?

Fourth consideration: Scoring Context Information


•Each piece of context is assigned a usefulness score:
• High → Must include
• Medium → Include if space allows
• Low → Optional

Dynamic context is user-specific information gathered at runtime.


Because time and space are limited, you must prepare what you can, collect wisely,
and score every piece of information by usefulness before giving it to the model.
How to find context? Two approaches:
A. Mind map approach (creative brainstorming)
A mind map is a diagram that starts with a central idea and expands into related
questions or subtopics.
Mind map for “What book shall I read next?”

This diagram is a mind map.


At the center (red box):
“What book shall I read next?”
From this question, you explore everything that could help answer it.
How to read the mind map
🔹 Center question
What book should I read next?

NAMITHA AV/ASST. PROF/SJEC 22 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

NAMITHA AV/ASST. PROF/SJEC 23 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

[Link] availability approach (what you can get)


This diagram helps answer:
Which context is easy to get, and which is hard?
It uses two axes (directions) so Gathering can be based on :
1. Proximity (how close the info is to your app)
2. Stability (how fast the info changes)

1.X-axis (horizontal): Proximity to the user/app


Left → Near
Easy to access
Right → Far
Harder to access (needs APIs, permissions)

NAMITHA AV/ASST. PROF/SJEC 24 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

2.Y-axis (vertical): Stability


Bottom → Changes slowly
Easy to prepare in advance
Top → Changes quickly
Hard to prepare

NAMITHA AV/ASST. PROF/SJEC 25 1SEM-CSDS/ICBS/SJEC


MODULE 4 INTRODUCTION TO AI

C. Combining both approaches


make a mind map of things the model might want to know, make a list of
things your application can find out, start implementing the most
obvious sources, and go on to more exotic sources as the project matures.

NAMITHA AV/ASST. PROF/SJEC 26 1SEM-CSDS/ICBS/SJEC

You might also like