0% found this document useful (0 votes)
15 views45 pages

Understanding Prompt Engineering Basics

Uploaded by

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

Understanding Prompt Engineering Basics

Uploaded by

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

Module 5

Prompting
What is a Prompt?
• A prompt is a text string that a user provides to a language model
to make it do something useful.
• The prompt acts as input context for the model.
• The language model generates tokens based on the prompt and
its learned patterns.
• The goal is to produce useful, relevant outputs aligned with the
user’s intent.
What is Prompt Engineering?
• The process of finding effective prompts for specific tasks is
called Prompt Engineering.
• It involves designing the right instructions or examples to guide
the model’s behavior.
• Prompt engineering helps achieve more accurate and controlled
results.
Example – Sentiment Classification Using
Prompting
• Task: Determine the sentiment of a hotel review.
• Sample Hotel Review (from BLT corpus):
• “Did not like the service that I was provided when I entered the
hotel.
• I also did not like the area in which the hotel was located.
• Too much noise and events going on for me to feel relaxed.”
Extending the Prompt
• We can help the model classify the review by adding an
incomplete statement at the end.
• Example Prompt:
• “Did not like the service that I was provided when I entered the
hotel.
• I also did not like the area in which the hotel was located.
• Too much noise and events going on for me to feel relaxed.
• In short, our stay was”
• The model will then generate a completion for the sentence.
Model-Generated Completions
• Completions produced by the LLM:
1. “... not a pleasant one. The staff at the front desk were not
welcoming or friendly, and seemed disinterested in providing good
customer service.”
2. “... uncomfortable and not worth the price we paid. We will not be
returning to this hotel.”
Model-Generated Completions
• Completions produced by the LLM:
1. “... not a pleasant one. The staff at the front desk were not
welcoming or friendly, and seemed disinterested in providing good
customer service.”
2. “... uncomfortable and not worth the price we paid. We will not be
returning to this hotel.”
Interpretation
• The overall negative tone of the review leads to negative
completions.
• This shows that the model understands sentiment context.
• We can map these completions to sentiment classes, for
example:
• excellent → positive
• did not like → negative
Power of Prompting
• With proper prompt design, a single LLM can handle many
different tasks, such as:
• Sentiment analysis
• Text completion
• Translation
• Summarization
• Question answering
• The context of the prompt is key to generating meaningful outputs.
Learning from Demonstrations: Few-Shot
Prompting
• Few-shot prompting improves prompts by including labeled
examples, called demonstrations.
• Demonstrations show the model what the task looks like and how
to respond.
• Few-shot prompting contrasts with zero-shot prompting, which
includes only instructions without examples.
• These examples guide the model to generate better, task-specific
outputs.
Definition: Reading
Comprehension Task

• Task: Write a correct


answer for the reading
comprehension question.
• Instruction: Identify the
shortest continuous text
span from the passage that
answers the question.
• Avoid answers that are
incorrect or incomplete.
How Many Demonstrations?
• The number of demonstrations doesn’t need to be large.
• A few examples can significantly improve performance over zero-shot
prompting.
• Most performance gains come from the first few examples; additional
ones add less benefit.
• The purpose of demonstrations is to show the model the task and
response format, not to give all possible answers.
How to Select Demonstrations?
• Demonstrations are created from labeled training examples to
guide model performance.
• Using examples similar to the current input improves accuracy —
selected using embedding similarity (top-T examples).
• The best approach is programmatic selection — choosing
demonstrations that maximize task performance (measured via
accuracy, chrF, or Rouge).
• Frameworks like DSPy (Khattab et al., 2024) automatically optimize
prompt demonstrations, finding the best set to include.
In-Context Learning and Induction Heads
1. Prompting vs. Pretraining:
• Pretraining updates model parameters using gradient descent.
• Prompting does not update parameters but allows the model to learn new tasks as it processes the input.
2. In-Context Learning (Brown et al., 2020):
• Models learn from the context within a prompt to perform new tasks or predict better without retraining.
• The model uses information in the prompt to improve its predictions dynamically.
3. Induction Heads (Elhage et al., 2021; Olsson et al., 2022):
• Circuits in transformer attention layers responsible for pattern recognition.
• They detect repeated patterns (e.g., A B … A → B) using prefix matching and a copying mechanism to predict
what follows.
4. Ablation Studies (Olsson et al., 2022):
• Removing induction heads (ablating) reduces in-context learning performance.
• Confirms induction heads are essential for learning patterns and generalization within prompts.
Post-training and Model Alignment
1. Limitations of Simple Prompting
• LLMs can perform many tasks through prompting without retraining.
• However, pretraining only to predict the next word limits their ability to follow
instructions accurately.
• Example issues:
• Misinterpreting prompts (“Translate to French” → continues text instead of translating).
• Failing to meet user intent — models are not sufficiently helpful or reliable.
2. Problems with Base (Pretrained) Models
• Pretrained models can generate false, misleading, or harmful content.
• Risks include:
• Unsafe misinformation (e.g., incorrect medical advice).
• Toxic or biased outputs, such as hate speech or stereotypes.
• These arise because pretraining is not aligned with human values of being helpful
and safe.
Post-training and Model Alignment
3. Model Alignment
• Goal: Adjust LLMs to align their behavior with human needs and values.
• Two main techniques:
a. Instruction Tuning (Supervised Fine-tuning / SFT)
• Model is finetuned on instruction-based datasets (questions and correct responses).
• Improves the ability to follow natural language instructions.
b. Preference Alignment (RLHF – Reinforcement Learning from Human
Feedback)
• A reward model is trained to measure how well an LLM’s output matches human preferences.
• This reward model then finetunes the base model to align it with desired behavior.
4. Base Model and Post-training
• A base model = a pretrained model not yet aligned through tuning or RLHF.
• Post-training refers to these alignment steps (instruction tuning + preference
alignment) that occur after pretraining.
Future Trends and Opportunities
in Prompt Engineering

Exploring the evolving landscape of prompt engineering and its transformative


impact on artificial intelligence

[Link]
[Link]
The Rise of Advanced Prompting
Techniques

Chain-of-Thought Prompting Tree-of-Thought Methods


Enables AI to reason step-by-step through Explores multiple reasoning paths
through complex problems, dramatically simultaneously, allowing AI to evaluate
dramatically improving accuracy in multi- evaluate alternatives and select optimal
multi-stage tasks and logical reasoning optimal solutions for sophisticated
reasoning challenges. problem-solving.

Least-to-Most Prompting
Breaks complex problems into sequential subproblems, boosting accuracy in mathematics,
mathematics, diagnostics, and other hierarchical reasoning tasks.

[Link]
Multimodal and Autonomous Prompting: The Next Frontier

Prompt engineering has evolved beyond text into a rich, multidimensional discipline spanning images, audio, code, and more.

Text Prompts Visual Inputs Autonomous Agents


Traditional natural language instructions enhanced Image-based prompting enables richer AI Self-directing systems like AutoGPT and BabyAGI
with advanced frameworks like LangChain and interactions for design, e-commerce, and visual generate, evaluate, and refine their own prompts
CrewAI. analysis tasks. with minimal human intervention.

[Link]
Democratising AI: Accessibility and Ethical Prompting
Breaking Down Barriers
Natural language interfaces and adaptive prompting are empowering non-technical users to harness AI
to harness AI without deep technical expertise. These advances are making sophisticated AI accessible
AI accessible to marketing teams, healthcare professionals, and educators.

Ethical Imperatives
As AI becomes ubiquitous, ethical prompting practices are critical to mitigate bias, ensure fairness, and
fairness, and maintain transparency—particularly in high-stakes domains like hiring, healthcare
healthcare diagnostics, and financial services.

Generative AI is increasingly used to create and optimise prompts, making prompt engineering more accessible and scalable than ever before.

[Link]
Industry Impact: Real-World Applications Driving Demand

Marketing & Advertising Legal Technology


AI-crafted campaign headlines and split-tested advertisement copy tailored through Automated clause generation, contract quality assurance, and case summarisation via
through sophisticated prompt design, delivering 40% higher engagement rates. domain-specific prompt chains, reducing review time by 60%.

Healthcare Systems Gaming & Entertainment


Chatbot-based patient intake and diagnostic assistance powered by complex prompt Dynamic non-player character dialogues and procedurally generated quest narratives driven
workflows that improve triage efficiency and patient outcomes. narratives driven by advanced prompt engineering techniques.

[Link]
Essential Skills for Tomorrow's Prompt Engineers
Hybrid Expertise Cost Optimisation Advanced Frameworks
Part UX designer, part software architect— Crafting prompts that reduce token usage by Mastery of prompt chaining frameworks,
architect—fluent in data types, instruction usage by 30% or more can save enterprises frameworks, multi-agent orchestration, and
instruction tuning, and model bias awareness. enterprises thousands in API costs whilst and real-time A/B testing simulations
awareness. The modern prompt engineer whilst maintaining output quality. separates good from exceptional
engineer bridges technical and creative practitioners.
domains.

[Link]
The Future Outlook: Evolution or
Transformation?
1 Current State
Manual prompt crafting dominates, requiring significant human expertise and iteration
to achieve optimal results.

2 Near Future
AI models become more context-aware and self-instructing, potentially reducing routine
reducing routine manual prompt engineering tasks.

3 Long-Term Vision
Human creativity and strategic design remain vital for nuanced, safe, and cost -effective
cost-effective AI applications—shifting from craft to orchestration.

The balance of human-AI collaboration will define prompt engineering's evolving role. Whilst
Whilst automation increases, strategic thinking, ethical considerations, and creative application ensure
application ensure human expertise remains indispensable.

[Link]
Embrace the Prompt Engineering
Engineering Revolution Today
A Career-Defining Skill
Prompt engineering is no longer optional—it's shaping the AI-powered future across
future across every industry and professional domain.

Invest in Mastery
Master advanced techniques, multimodal tools, and ethical frameworks to unlock
to unlock AI's full potential and position yourself at the forefront of innovation.
innovation.

Speak AI's Language


The future belongs to those who can communicate fluently with AI systems—start
your prompt engineering journey now and lead the revolution.

[Link]
Fine-Tuning AI Models with
Custom Prompts
Technical Insights & Ethical Considerations

[Link]
What is Fine-Tuning in AI?

Retraining Foundation Models Beyond Prompt Engineering Specialised Applications


Fine-tuning takes a pre-trained large language Unlike prompt engineering, which guides Examples include customising GPT-3.5 Turbo
language model (LLM) and retrains it on a guides outputs by carefully crafting inputs, Turbo to better understand legal jargon for
a specialised dataset, adjusting internal inputs, fine-tuning fundamentally changes the for contract analysis or medical terminology
parameters to improve performance on changes the model's behaviour by modifying terminology for clinical documentation
specific tasks or domains. modifying its underlying weights and biases. support.
biases.
[Link]
When Does Fine-Tuning Make Sense?
Ideal Use Cases
Fine-tuning delivers exceptional value for highly specialised, repeatable tasks requiring consistent and precise
precise outputs. It works best in controlled environments with stable input types to avoid unexpected failures.
failures.

• Automated legal contract analysis with specific clause identification

• Medical diagnosis support using clinical terminology

• Standardised report generation following strict templates

• Domain-specific customer service responses

• Technical documentation creation in specialised fields

Key consideration: Fine-tuning requires substantial upfront


upfront investment in data preparation and model training but
training but can deliver remarkable accuracy for narrowly
[Link]
defined tasks.
The Downsides of Fine-Tuning
Reduced Generalisation
Fine-tuning narrows a model's focus, reducing its ability to generalise across diverse tasks. The model
becomes highly specialised but loses versatility for broader applications.

Maintenance Burden
Significant maintenance overhead emerges as fine-tuned models require costly retraining whenever
data evolves or base models update. This creates ongoing resource demands.

Rapid Obsolescence
Base models improve at breakneck speed. Fine-tuned versions can quickly become outdated as newer
foundation models offer superior performance without customisation.

High Resource Costs


Financial and computational costs can be substantial, including GPU time, data curation, training
training infrastructure, and ongoing monitoring requirements.

[Link]
Prompt Engineering vs Fine-Tuning
Understanding the key differences helps determine the right approach for your use case.

Aspect Prompt Engineering Fine-Tuning

Definition Modifies input prompts to guide output Adjusts model weights on custom data

Flexibility High, works across domains Lower, specialised to tasks

Resource Cost Low High

Accuracy Limited by prompt quality Generally higher for niche tasks

Time to Deploy Immediate Days to weeks

Maintenance Easy updates Complex retraining cycles

[Link]
Ethical Challenges in Fine-Tuning AI Models

Privacy Breaches Amplified Biases


Risk of embedding Personally Identifiable Information (PII) in training Potential to amplify biases present in training datasets, causing unfair
data, leading to potential privacy violations when the model or prejudiced outputs that perpetuate discrimination and inequality in
inadvertently reproduces sensitive information in outputs. automated decision-making.

Compromised Safety Unintended Consequences


Safety guardrails can be compromised, enabling harmful or malicious Even well-intentioned fine-tuning can degrade a model's safety
outputs post fine-tuning. Research shows GPT-3.5 Turbo with just 10 safety alignment, creating vulnerabilities that weren't present in the
adversarial examples can bypass safety filters. in the original base model.

[Link]
Real-World Safety Risks: Research Insights
Key Research Findings
Stanford and Princeton studies reveal alarming vulnerabilities in fine-tuned models, demonstrating how customisation can
customisation can unintentionally degrade safety measures.

Safety Degradation 10
Fine-tuning can degrade safety alignment even without malicious intent, creating unexpected vulnerabilities.
vulnerabilities.

Harmful Responses
Adversarial Examples
Fine-tuned models may respond affirmatively to harmful prompts, dramatically increasing risks of misuse.
Number needed to bypass safety filters in GPT-3.5 Turbo

73%

Safety Reduction

Decrease in safety alignment observed in some fine-tuned models

Critical insight: Current safety infrastructures are insufficient to fully prevent these risks after fine-tuning, necessitating
tuning, necessitating stronger mitigation strategies and oversight.

[Link]
Best Practices for Ethical Fine-Tuning
01

Rigorous Data Cleansing


Thoroughly cleanse training data to remove PII, toxic content, and embedded biases before fine-tuning begins.

02

Feedback Loops
Implement human and AI feedback loops to continuously monitor and correct model outputs during and after training.

03

Multi-Layered Safeguards
Deploy multi-layered safeguards at data, input, and output stages to catch potential issues before they reach users.
reach users.

04

Transparent Communication
Maintain transparency with users about AI limitations, risks, and the fine-tuning process used to create the model.
model.

[Link]
The Future: Balancing Customisation and Responsibility
Emerging Approaches
The landscape of AI customisation is evolving rapidly, with new strategies emerging to balance
balance performance with ethical considerations.

Improved Base Models

Foundation models continue improving rapidly, offering versatile, cost-effective


alternatives to fine-tuning for many use cases.

Hybrid Approaches

Combining prompt engineering with selective fine-tuning may optimise performance whilst
performance whilst maintaining safety.

Policy & Collaboration

Policymakers and developers must collaborate to enforce ethical standards and effective
effective risk mitigation strategies.

"Ethical AI development is the key to building trust and unlocking AI's full
[Link]
full potential for society."
Fine-Tuning with Care
Powerful but Complex Ongoing Vigilance Required
Fine-tuning offers powerful customisation
capabilities but comes with significant Thoughtful application, continuous
ethical and safety challenges that require oversight, and robust safeguards are
careful navigation. essential to responsible fine-tuning
practices.

A Balanced Path Forward


Embrace a balanced approach: leverage base models, use prompt engineering, and fine-
tune responsibly when truly necessary.

Together, we can harness AI's promise whilst protecting users and society. The future of AI
depends on our collective commitment to ethical development and responsible deployment.

[Link]
Future Trends and Opportunities
in Prompt Engineering

Exploring the evolving landscape where human creativity meets artificial


intelligence

[Link]
The Rise of Prompt Engineering: A
Engineering: A New AI Frontier
The Critical Bridge A Bold Prediction
Prompt engineering serves as the Baidu's Robin Li forecasts: "In 10 years,
essential translator between human half of the world's jobs will be in
intent and AI output, optimising prompt engineering"—signalling a
generative AI systems like GPT-4 and transformative shift in how we work
LLaMA to deliver precise, meaningful with AI.
results.

Today's Reality
Modern prompt engineers craft precise inputs that unlock AI's full potential, driving
driving innovation and efficiency across industries worldwide.

[Link]
From Crafting Prompts to Autonomous AI Agents
Advanced Context Understanding
Emerging AI models such as GPT-4.5, Google Gemini, and Anthropic Claude 3 demonstrate
demonstrate sophisticated contextual awareness, significantly reducing the need for complex,
for complex, carefully structured prompts.

Self-Optimising Systems
Autonomous agents like AutoGPT and BabyAGI represent a paradigm shift—they generate,
generate, evaluate, and refine their own prompts through recursive learning processes.
processes.

The Evolution Ahead


This evolution hints at a future where AI systems self-optimise, transforming prompt
prompt engineering from manual crafting into strategic supervisory roles.

[Link]
Expanding Horizons: Multimodal and Adaptive Prompting
Prompting

Multimodal Integration Adaptive Intelligence New Skill Demands


Future prompt engineering seamlessly Adaptive prompting enables AI to iteratively These trends require mastery beyond text
combines text, images, audio, and video inputs iteratively improve its understanding based on crafting—integrating diverse data types,
inputs to guide AI outputs with unprecedented based on real-time context and continuous dynamic interaction patterns, and cross-modal
unprecedented precision and richness. continuous user feedback loops. modal understanding.
[Link]
Context Engineering: The Next Big
Big Skill
Designing AI Environments
Context engineering goes beyond prompts, designing the complete
environment and data ecosystem AI needs to perform optimally and reliably.
reliably.

Ensuring Data Access


It ensures AI systems have seamless access to relevant CRM data, product
product manuals, knowledge bases, and real-time information—fixing
fixing "incomplete picture" failures.

Holistic Solutions
This comprehensive approach complements traditional prompt engineering,
engineering, creating more reliable, scalable, and production-ready AI
AI solutions.

[Link]
Prompt Engineering's Expanding Job Landscape

Prompt Engineer
£60K–£150K: Crafting and optimising AI prompts for business applications

Conversational AI Designer
£68K–£120K: Designing natural dialogue systems and chatbot experiences

AI Ethicist
£75K–£140K: Ensuring responsible, unbiased AI development and deployment

AI UX Designer
£65K–£130K: Creating intuitive interfaces for AI-powered products

AI Product Manager
£85K–£160K: Strategising AI product development and market positioning

Industries hiring span technology, healthcare, finance, education, and telecommunications—from global tech giants to innovative startups like Telkomsel's AI network optimisation initiatives.
optimisation initiatives.
[Link]
Democratising AI: No-Code Tools and User-Friendly Interfaces
Accessible Platforms

No-code and low-code platforms dramatically simplify prompt creation, making


powerful AI capabilities accessible to non-technical users and domain experts.

Natural Language Interaction

Advanced natural language interfaces allow users to query AI systems using


everyday language, reducing reliance on specialised prompt engineering skills.

Industry Investment

Tech leaders like Microsoft, Google, and OpenAI are investing heavily in intuitive AI
interaction systems that bridge the gap between expert and novice users.

[Link]
Ethical and Responsible Prompting
Prompting
Embedding Guardrails Aligning with Values
As AI systems gain power and influence, Responsible prompting ensures AI
influence, prompt engineers must embed outputs consistently align with societal
embed ethical guardrails, fairness checks, societal values, regulatory standards, and
checks, and bias mitigation strategies and organisational ethics policies.
strategies directly into prompt
architectures.

Emerging Specialists
AI Ethicists and Compliance Specialists
Specialists represent rapidly growing roles
roles focused on addressing these critical
critical challenges at the intersection of
of technology and society.

[Link]
The Future: Collaboration Between Humans and AI

AI Execution
Human Oversight
Autonomous task completion and optimisation
Strategic supervision and goal alignment
optimisation

Innovation Continuous Learning


Creative problem-solving and new opportunities Iterative improvement through feedback loops
opportunities loops

Prompt engineering will evolve from manual prompt crafting to designing sophisticated AI-human workflows. Human-in-the-loop oversight remains vital to supervise
remains vital to supervise autonomous agents and ensure alignment with strategic goals. Mastery of both prompt and context en gineering will become a cornerstone
become a cornerstone skill in the AI-driven economy.
[Link]
Seize the Opportunity in Prompt
Engineering

A Transforming Discipline Embrace Emerging Trends


Prompt engineering isn't fading—it's evolving Master autonomous agents, multimodal
into a multifaceted discipline with vast inputs, context engineering, and ethical AI
opportunities across industries and practices to stay ahead of the curve.
applications.

Lead the Revolution


Prepare now to lead in the AI revolution by mastering both the art and science of guiding
intelligent machines towards meaningful human goals.

"The future belongs to those who can speak the language of machines whilst never
forgetting the voice of humanity."

[Link]

You might also like