0% found this document useful (0 votes)
14 views128 pages

GenAI 1

The document outlines the evolution of Artificial Intelligence (AI) over seven decades, detailing its progression from rule-based systems to machine learning, deep learning, and the recent generative AI era. It highlights the impact of generative AI on various applications, the emergence of new job roles, and the differences between traditional and generative AI systems. Additionally, it discusses the foundational concepts of generative AI, including data distribution, model behavior, and practical exercises for understanding AI capabilities.

Uploaded by

shaiksharmila185
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)
14 views128 pages

GenAI 1

The document outlines the evolution of Artificial Intelligence (AI) over seven decades, detailing its progression from rule-based systems to machine learning, deep learning, and the recent generative AI era. It highlights the impact of generative AI on various applications, the emergence of new job roles, and the differences between traditional and generative AI systems. Additionally, it discusses the foundational concepts of generative AI, including data distribution, model behavior, and practical exercises for understanding AI capabilities.

Uploaded by

shaiksharmila185
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

Evolution of Artificial Intelligence

• Artificial Intelligence has evolved through multiple phases over the


last seven decades.
• Early AI (1950s–1980s):
Focused on rule-based systems where intelligence was explicitly
programmed using IF–THEN rules. These systems worked well only
in limited, well-defined environments and failed when faced with
uncertainty.
• Machine Learning Era (1990s–2010s):
Shift from rules to learning from data. Algorithms such as linear
regression, decision trees, and support vector machines enabled
systems to make predictions, but required heavy feature engineering
by humans.
• Deep Learning Era (2012 onwards):
Neural networks with multiple layers learned features automatically
from large datasets. This led to breakthroughs in image recognition,
speech recognition, and natural language processing.
• Generative AI Era (Post-2022):
Introduction of foundation models capable of generating human-like
text, images, code, audio, and video. Unlike earlier AI systems,
these models are general-purpose and adaptable across domains.

• SAME PROBLEM SOLVED USING DIFFERENT AI EVOLUTIONS
• Problem: Email Handling System
• Rule-Based AI:
Emails are filtered using fixed keyword-based rules such as “free”,
“offer”, or “win”.
• Machine Learning:
Emails are classified as spam or not spam using trained
classification models.
• Deep Learning:
Email content is analyzed for context and intent using neural
networks.
• Generative AI:
The system automatically drafts email responses based on the
email content.
• Sample Problems:
Student attendance system
Customer support system
Online examination evaluation
Resume screening system
Traffic management system
• Explosion of Generative AI After 2022
• reasons for this explosion include:
• Availability of very large datasets (internet-scale text and multimodal
data)
• Advances in transformer architectures
• Massive improvements in computational power (GPUs/TPUs)
• Release of user-friendly interfaces that made AI accessible to non-
experts
• For the first time, AI systems demonstrated:
• Human-like conversation
• Context understanding
• Content creation
• Code generation
• This led to rapid adoption across education, industry, research, and
governance.
• Career Impact of Generative AI
• New roles emerging:
• AI Engineer
• Prompt Engineer
• AI Product Manager
• AI Research Scientist
• Data Scientist (GenAI specialization)
• Transformation of existing roles:
• Software developers using AI-assisted coding
• Analysts using AI for insights and reporting
• Educators using AI for personalized learning
• What Makes Artificial Intelligence “Generative”?
• Not all AI systems generate new content
• Generative AI creates new data similar to what it has seen
before
• Examples include text, images, audio, and video
• Traditional AI vs Generative AI
• Traditional AI Systems
• Make decisions or predictions
• Choose from existing options
• Do not create new content
• Generative AI Systems
• Learn patterns from data
• Create new content similar to training data
• Outputs were not explicitly stored

• Generative vs Discriminative Models
• Discriminative Models
• Learn boundaries between classes
• Answer the question: Which category does this belong to?
• Output is a label or class
• Generative Models
• Learn how data looks internally
• Answer the question: How can I generate something similar?
• Output is new data
• : Data Distribution Modeling (Intuition)
• What is Data Distribution?
• Data follows certain patterns
• Not all values are equally likely
• Generative AI
• Learns these patterns
• Understands what is common and what is rare
• Uses this understanding to generate new data
• Probability-Based Generation (No Math)
• Key Idea
• Generative AI does not copy answers
• It predicts what is likely to come next
• Example (Text)
• Input: “The sun rises in the”
• Likely output: “east”
• Example – Text Generation
• What the Model Learns
• Grammar
• Sentence structure
• Meaning relationships
• What the Model Generates
• Essays
• Emails
• Code
• Summaries
• Example – Image Generation
• What the Model Learns
• Shapes
• Colors
• Object relationships
• What the Model Generates
• New images
• Artistic styles
• Realistic photos
• Example – Audio Generation
• What the Model Learns
• Sound patterns
• Pitch and tone
• Rhythm
• What the Model Generates
• Speech
• Music
• Sound effects
• Classify the following ML models as Discriminative or Generative
and justify.
• Models:
• Logistic Regression
• Support Vector Machine
• Decision Tree
• Naive Bayes
• k-Means
• Autoencoder
• Expected Outcome:
Logistic Regression – Discriminative
Support Vector Machine – Discriminative
Decision Tree – Discriminative
Naive Bayes – Generative
k-Means – Generative
Autoencoder – Generative
• Given a text dataset (reviews, tweets, or feedback), answer the
following:
• How would a discriminative model solve this problem?
• How would a generative model solve this problem?
• Discriminative Approach:
Classify reviews as positive or negative.
• Generative Approach:
Generate a summary of reviews or create new sample reviews.
• Deliverable:
• TASK 1: IDENTIFY GENERATIVE vs DISCRIMINATIVE BEHAVIOR
• Objective:
Understand the difference between discriminative and generative
systems through observation.
• Steps:
• Open any generative AI tool available to you.
• Enter the following prompts one by one.
• Prompt A:
Classify the sentiment of this sentence:
“I enjoyed the movie but the ending was disappointing.”
• Prompt B:
Write a short movie review based on the sentence:
“I enjoyed the movie but the ending was disappointing.”
• Observation:
Prompt A produces a label.
Prompt B produces new text.
• PROBABILITY-BASED GENERATION
• Objective:
Observe how probability influences generation.
• Steps:
• Enter the same prompt three times:
• Prompt:
“The future of machine learning is”
• Compare the outputs.
• Questions to Answer:
Are all outputs identical?
Are all outputs acceptable?
Which output sounds more natural?
• TASK 3: PROMPT VARIATION EXPERIMENT
• Objective:
Understand how prompts guide generation.
• Steps:
• Enter the following prompts:
• Prompt 1:
Explain overfitting in machine learning.
• Prompt 2:
Explain overfitting in machine learning using a real-life analogy.
• Compare the tone, depth, and clarity of outputs.
• Conclusion:
The model behavior is controlled by prompt structure.
• FOUNDATION MODELS & LARGE LANGUAGE MODELS (LLMs)
– CONCEPTUAL VIEW
• This is the natural bridge from “What is generative?” to “How does
ChatGPT actually work?”
• What is a Foundation Model?
• Single model trained on massive data
• Can be adapted to many tasks
• General-purpose, not task-specific
• 2. Why Foundation Models Replaced Traditional ML
• Earlier: one model per task
• Now: one model, many tasks
• Prompt instead of retraining
• What is a Large Language Model (LLM)?
• Language-focused foundation model
• Predicts next token
• Works probabilistically
• 4. Why LLMs Are Not Databases
• Do not store facts
• Generate responses
• Can be wrong confidently
• 5. High-Level Training Pipeline
• Pre-training
• Fine-tuning
• Human feedback (conceptual)

• Same prompt → different tasks
• Observe multi-task behavior
• Understand “one model, many uses”
• HANDS-ON 1: ONE MODEL, MANY TASKS
• Prompt 1:
Summarize the following text in two lines:
“Machine learning enables systems to learn from data and improve
over time.”
• Prompt 2:
Translate the following sentence into simple English:
“Machine learning enables systems to learn from data and improve
over time.”
• Prompt 3:
Generate three questions based on the following sentence:
“Machine learning enables systems to learn from data and improve
over time.”
Observation
The same model performs summarization,
simplification, and question generation.
• HANDS-ON 2: NEXT-TOKEN PREDICTION (INTUITION)
• Objective
• To observe how LLMs predict the next token.
• Steps
• Enter the following prompt multiple times:
• Prompt:
“The future of artificial intelligence depends on”
• Compare the generated outputs.
• Questions
• Are the outputs identical?
Are all outputs meaningful?
Which output sounds more likely?
• Conclusion
• LLMs generate text probabilistically by predicting the next
token.
• HANDS-ON 4: LLM IS NOT A DATABASE
• Objective
• To understand hallucination and limitations.
• Steps
• Ask the model:
• Prompt:
What is the population of Atlantis?
• Observe the response.
• Discussion
• Did the model answer confidently?
Is Atlantis a real place?
• Conclusion
• LLMs generate responses even when facts are missing.
Module 2: Foundations of Generative AI
• Definition
• Generative AI models are designed to learn the underlying
probability distribution of data and generate new samples from
that distribution.
• Data Distribution
• A data distribution describes how likely different data points are
in a dataset.
• Example:
• Common words appear more frequently
• Rare words appear less frequently
• Learning the Distribution
• What Generative Models Learn
• Which patterns are common
• Which patterns are rare
• How elements relate to each other
• Speaker Notes:
“The model builds an internal map of what ‘normal’ looks like.”
• # Simple GenAI-like Text Generator Rule Based

• prompt = input("Enter your prompt: ")

• if "hello" in [Link]():
• print("AI Response: Hello! How can I help you today?")

• elif "capital of india" in [Link]():
• print("AI Response: The capital of India is New Delhi.")

• elif "ai" in [Link]():
• print("AI Response: Artificial Intelligence is the ability of machines to think and learn.")

• elif "bye" in [Link]():


• print("AI Response: Goodbye! Have a nice day.")

• else:
• print("AI Response: Sorry, I am still learning. Please ask something else.")
• import random

• prompt = input("Enter your prompt: ").lower()

• knowledge_base = {
• "capital_of_india": [
• "New Delhi is the capital of India and serves as the administrative center of the country.",
• "The capital city of India is New Delhi, which plays a major role in governance and politics."
• ]
• }

• if "india" in prompt and "capital" in prompt:


• print("\nAI Generated Response:\n")
• print([Link](knowledge_base["capital_of_india"]))
• else:
• print("\nAI Generated Response:\n")
• print("Sorry, I am not able to understand the question yet.")
• Student Exercise:
• Add 3 to 4 topics in your knowledge base and execute.
• Give the input as head quarters and experiment the ouput
• Adding Intent:
• Conversational AI Reasoning Pipeline:
• Step 1 – Intent Detection
• Content:
• Intent = What the user wants
• AI identifies the purpose of the user message
• Step 2 – Confidence Scoring
• Content:
• AI measures how sure it is about the detected intent
• Confidence is a value between 0 and 1
• Higher confidence → safer response
import random

# Take user input


prompt = input("Enter your prompt: ").lower()

# Knowledge base with intents


intents = {
"capital_of_india": {
"keywords": ["india", "capital", "capital city", "headquarters"],
"responses": [
"New Delhi is the capital of India and serves as the administrative and political center of the country. "
"It houses important institutions such as the Parliament, Supreme Court, and Rashtrapati Bhavan. "
"The city plays a key role in national governance and decision-making.",

"India's capital city is New Delhi, which is known for its historical importance and political significance. "
"It is the seat of the central government and represents the core of India's administration."
]
}
}
# Initialize variables
best_intent = None
highest_score = 0

# Match intent using keyword scoring


for intent_name, intent_data in [Link]():
score = sum(1 for word in intent_data["keywords"] if word in prompt)

if score > highest_score:


highest_score = score
best_intent = intent_name

# Generate output
print("\nAI Generated Response:\n")

if best_intent and highest_score >= 2:


print([Link](intents[best_intent]["responses"]))
else:
print(
"I am still learning and could not clearly understand your question. "
"Please try rephrasing it or ask something related to my knowledge base."
)
• 1)Improvise the above program by displaying intent and
confidence score.
• 2)Give input as India.. And check the output.. Modify your
program such that if input is just india also Your program has to
respond.
• Ans 1)Program to print intent and confident level;
• import random

• prompt = input("Enter your prompt: ").lower()

• intents = {
• "capital_of_india": {
• "keywords": ["india", "capital", "capital city", "headquarters"],
• "responses": [
• "New Delhi is the capital of India and serves as the political and administrative center of the country.",
• "India's capital city is New Delhi, which is the seat of the central government."
• ]
• },
• "artificial_intelligence": {
• "keywords": ["ai", "artificial intelligence", "intelligence"],
• "responses": [
• "Artificial Intelligence enables machines to perform tasks that require human intelligence.",
• "AI is widely used in automation, chatbots, and data analysis."
• ]
• }
• }
• best_intent = None
• highest_score = 0
• matched_keywords = []

• for intent_name, intent_data in [Link]():


• current_matches = [word for word in intent_data["keywords"] if word in prompt]
• score = len(current_matches)

• if score > highest_score:


• highest_score = score
• best_intent = intent_name
• matched_keywords = current_matches

• print("\nAI Generated Response:\n")

• if best_intent and highest_score >= 2:


• print([Link](intents[best_intent]["responses"]))
• print("\nConfidence Details:")
• print("Detected Intent:", best_intent)
• print("Matched Keywords:", matched_keywords)
• print("Confidence Score:", highest_score)
• else:
• print(
• "I am still learning and could not clearly understand your question. "
• "Please try rephrasing it."
• )
• Ans 2)Program with primary keyword.
• import random

• prompt = input("Enter your prompt: ").lower()

• intents = {
• "capital_of_india": {
• "keywords": ["india", "capital", "capital city", "headquarters"],
• "primary_keywords": ["india"],
• "responses": [
• "New Delhi is the capital of India and serves as the administrative and
political center of the country.",
• "India's capital city is New Delhi, which is the seat of the central government."
• ]
• }
• }
• best_intent = None
• highest_score = 0

• for intent_name, intent_data in [Link]():


• score = sum(1 for word in intent_data["keywords"] if word in prompt)

• if score > highest_score:


• highest_score = score
• best_intent = intent_name

• print("\nAI Generated Response:\n")

• # High confidence case


• if best_intent and highest_score >= 2:
• print([Link](intents[best_intent]["responses"]))

• # Medium confidence fallback


• elif best_intent and highest_score == 1 and "india" in prompt:
• print([Link](intents[best_intent]["responses"]))

• # Low confidence
• else:
• print(
• "I am not fully sure what you are asking. "
• "Please include more details in your question."
• )
• Level 3:
• Intent → Confidence → Context → Slot filling → Decision-
• Context Management
• Content:
• Context = memory of previous conversation
• AI remembers:
• Last intent
• Previous user answers
• Enables multi-turn conversation
• Step 4 – Slot Filling
• Content:
• Slots are missing details required to answer
• AI checks what information is incomplete
• AI asks questions to fill missing slots
• Step 5 – Decision & Response
• Content:
• AI checks:
• Intent confirmed
• Confidence acceptable
• All slots filled
• Only then final response is generated
• Simulating a Chatbot using
• Intent → Confidence → Context → Slot Filling → Decision
• What is a Chatbot?
• • A chatbot is a program that interacts with users using natural
language
• It understands user queries and responds automatically
• Chatbots follow a fixed processing pipeline before responding
User Input

Intent Detection

Confidence Scoring

Context Identification

Slot Filling

Decision Making

Bot Response
• Knowledge Base Used
• • Domain: General Knowledge
• Example Topic: Capital of a Country
• Knowledge is stored as keywords, entities, and responses
• import random

• print(" AI Chatbot Started (type 'exit' to stop)\n")

• # --------------------------------
• # KNOWLEDGE BASE
• # --------------------------------
• intents = {
• "capital_query": {
• "keywords": ["capital", "capital city", "headquarters"],
• "countries": ["india"],
• "responses": {
• "india": [
• "The capital of India is New Delhi.",
• "India's capital city is New Delhi."
• ]
• }
• }
• }
• # --------------------------------
• # MEMORY (Intent + Context)
• # --------------------------------
• memory = {
• "intent": None,
• "country": None
• }

• # --------------------------------
• # CHAT LOOP
• # --------------------------------
• while True:
• user_input = input("You: ").lower()

• if user_input == "exit":
• print(" Bot: Goodbye! ")
• break

• # -------------------------------
• # 1. INTENT DETECTION
• # -------------------------------
• detected_intent = None
• intent_score = 0
• for intent, data in [Link]():
• score = sum(1 for word in data["keywords"] if word in user_input)
• if score > intent_score:
• intent_score = score
• detected_intent = intent

• # If no intent detected, reuse previous intent


• if detected_intent is None:
• detected_intent = memory["intent"]

• # -------------------------------
• # 2. CONFIDENCE CALCULATION
• # -------------------------------
• confidence = (
• intent_score / len(intents[detected_intent]["keywords"])
• if detected_intent and intent_score > 0 else 0
• )
• # -------------------------------
• # 3. CONTEXT IDENTIFICATION
• # -------------------------------
• context = None

• if detected_intent:
• for country in intents[detected_intent]["countries"]:
• if country in user_input:
• context = country
• memory["country"] = country

• # If user just gives country name


• if context is None and user_input in intents["capital_query"]["countries"]:
• context = user_input
• memory["country"] = user_input
• # -------------------------------
• # 4. SLOT FILLING
• # -------------------------------
• slots = {}
• if memory["country"]:
• slots["country"] = memory["country"]
• # -------------------------------
• # 5. DECISION MAKING
• # -------------------------------
• print("\n Bot:")

• if detected_intent == "capital_query" and "country" not in slots:


• print("Which country are you asking about?")
• memory["intent"] = detected_intent

• elif detected_intent == "capital_query" and "country" in slots:


• print([Link](
• intents[detected_intent]["responses"][slots["country"]]
• ))
• memory["intent"] = detected_intent

• else:
• print("I am not sure I understood that. Please rephrase your question.")
• # -------------------------------
• # INTERNAL PROCESSING (FOR TEACHING)
• # -------------------------------
• print("\n--- Internal Processing ---")
• print(f"Intent : {detected_intent}")
• print(f"Confidence : {round(confidence, 2)}")
• print(f"Context : {memory['country']}")
• print(f"Slots : {slots}")
• print("-" * 40)
• Overview of Major LLMs and Diffusion Models
• MAJOR LARGE LANGUAGE MODELS (LLMs)
• Popular LLM Families
• GPT Series – OpenAI (ChatGPT)
• Gemini – Google
• Claude – Anthropic
• LLaMA – Meta
• Mistral – Open-source
• Core Capability:
Text generation using next-token prediction

• WHERE LLMs ARE USED
• Applications of LLMs
• Chatbots & virtual assistants
• Code generation & debugging
• Text summarization
• Question answering
• Document analysis
• MAJOR DIFFUSION MODELS
• Popular Diffusion Models
• Stable Diffusion
• DALL·E
• Midjourney
• Core Capability:
Image generation using noise removal
• TRANSITION TO PROMPTING
• Why Prompting Matters
• Models are pre-trained
• We control behavior via prompts
• Prompting = programming interface
• No retraining required
• Transformer Architecture:
• : Why Transformers?
• Natural language has context
• Meaning depends on surrounding words
• Earlier models processed words sequentially
• Transformers overcome these limitations
• Limitations of Earlier Models
• Slide Content
• Limitations of Traditional Models
• RNNs process words one by one
• Long-term dependencies are difficult
• Information may be forgotten
• Computation is slow
• What is a Transformer?
• Deep learning architecture
• Processes entire sentence at once
• Uses attention instead of memory
• Enables parallel processing
• Attention Mechanism
• Focuses on important words
• Assigns different importance to words
• Helps understand context
• Example:
“Attention helps models focus on important words”
• Why Attention Matters
• Understands context
• Handles ambiguity
• Improves language understanding
• Core of Transformer architecture
• # Hands-on 1: Simple Attention Simulation (Toy Example)

• sentence = "Attention helps models focus on important words"


• question = "What does attention do?"

• words = [Link]()

• attention_scores = {}

• for word in words:


• if [Link]() in ["focus", "important"]:
• attention_scores[word] = 0.9
• else:
• attention_scores[word] = 0.1
• print("Input sentence:")
• print(sentence)

• print("\nAttention scores assigned to words:")


• for word, score in attention_scores.items():
• print(word, ":", score)

• print("\nFinal Answer:")
• print("focus on important words")
• Sentence:Transformers use attention to understand context
• Which TWO words should get the highest attention?
• Why?
• Which words can get the lowest attention?
• Why?
• Transformers & Attention Mechanism
• Fill in the blanks using the words below:
• A __________________ processes all words at once.
• Earlier models processed words __________________.
• The meaning of a word depends on its __________________.
• The __________________ mechanism focuses on important
words.
• Transformers allow __________________ processing.
• Attention gives higher weight to __________________ words.
• Write True or False in the space provided.
• Attention treats every word equally.
• Transformers solve long-term dependency problems.
• RNNs process all words at the same time.
• Context helps in understanding ambiguity.
• Transformers use attention instead of memory.
• Problem With LLMs
• Hallucination (confident wrong answers)
• No access to private company data
• Knowledge cutoff
• Cannot read internal documents
• Basic RAG Architecture
• User Question

Retriever (Search)

Relevant Documents

LLM

Final Answer
• GPT vs LLM vs RAG
• LLM = Category
GPT = Type of LLM
RAG = Technique to improve LLM
• RAG (Retrieval + Generation )System Design Layers
• Data Ingestion
• Processing & Chunking
• Embedding Generation
• Vector Storage
• Retrieval
• LLM Generation
• Monitoring
• import difflib
• from sklearn.feature_extraction.text import TfidfVectorizer
• from [Link] import cosine_similarity

• # Knowledge Base
• documents = [
• "The university offers [Link], [Link], and MBA programs.",
• "The placement percentage is 92%.",
• "The highest package offered is 18 LPA.",
• "Minimum attendance required is 75%."
• ]
• # Convert documents into vectors
• vectorizer = TfidfVectorizer()
• doc_vectors = vectorizer.fit_transform(documents)

• def retrieve(query):

• # Step 1: Fix spelling (simple fuzzy match)


• words = " ".join(documents).split()
• corrected = []
• for word in [Link]():
• match = difflib.get_close_matches(word, words, n=1, cutoff=0.6)
• [Link](match[0] if match else word)
• query = " ".join(corrected)
• # Step 2: Convert query to vector
• query_vector = [Link]([query])

• # Step 3: Find most similar document


• similarity = cosine_similarity(query_vector, doc_vectors)
• index = [Link]()

• return documents[index]

• # Ask Question
• query = input("Ask your question: ")
• print("\nRetrieved Information:")
• print(retrieve(query))
• Modify program so that:
• If question contains multiple keywords,
print all matching answers.
• Example:
• Question:
"What is placement eligibility and attendance requirement?"
• Output:
• Placement rule
• Attendance rule
• Project Idea
• Improve this chatbot

• Use semantic search


• Use embeddings
• Add LLM for better answer formatting
• Store data in database
• Build web interface
• Interview Expected Questions:
• What is RAG (Retrieval-Augmented Generation)?
• Why do we need RAG when we already have Large Language
Models?
• What are the two main components of a RAG system?
• How is RAG different from fine-tuning?
• What problem does RAG solve in LLMs?
• Explain the difference between:
• Keyword search
• Semantic search
• LLM Frame Works
• LLM Frameworks = Application Builders for LLMs
• Examples:
• LangChain
• LlamaIndex
• Haystack
• Semantic Kernel
• They manage:
• Prompts
• Chains
• Memory
• Tools
• RAG pipelines
• Architecture:
• User

Framework

Retriever + Memory + Tools

LLM

Response
• When to Use RAG vs Framework
• Use RAG:
• Simple document Q&A
• Static knowledge base
• Use Framework:
• Chatbots
• AI Agents
• API integration
• Multi-step reasoning
• Production systems
• Coding Demo – Building a Simple LLM App
• Build a simple AI assistant using LangChain.
• We will:
• Connect to LLM
• Create prompt template
• Build a chain
• Run the application
• generator = pipeline(
• "text-generation",
• model="distilgpt2"
• )
• from transformers import pipeline

• generator = pipeline("text-generation", model="gpt2")


• while True:
• user_input = input("Ask something (type 'exit' to stop): ")

• if user_input.lower() == "exit":
• break

• response = generator(user_input, max_length=100)


• print("\nResponse:")
• print(response[0]["generated_text"])
• print("\n" + "-"*50)
• Fine-Tuning
• Fine-Tuning = Adapting a Pretrained Model to a Specific Task
• Start with a pretrained large model
• Train further on task-specific data
• Adjust weights slightly
• Improves performance on target task
• Example:
• GPT → fine-tuned for legal chatbot
• BERT → fine-tuned for sentiment analysis
• Fine-Tuning vs RAG (Very Important for Placements)
• This is one of the most common interview questions.
• Fine-Tuning:
• Changes model weights.
• Permanent behavior change.
• Expensive.
• Good for behavior/style control.
• RAG (Retrieval-Augmented Generation):
• Does NOT change model.
• Retrieves information from documents.
• Cheaper.
• Good for dynamic knowledge.
• Types of Fine-Tuning
• Content
• Full Fine-Tuning
• Parameter Efficient Fine-Tuning (PEFT)
• LoRA (Low Rank Adaptation)
• Fine-Tuning Process (Pipeline)
• Content
• Collect domain dataset
• Clean & format data
• Select base model
• Train model
• Evaluate
• Deploy
• Placement Questions
• What is fine-tuning?
• Fine-tuning is adapting a pre-trained model using domain-specific data.
• 2. Why not train from scratch?
• Training from scratch requires huge data and computational resources.
• 3. What is a pre-trained model?
• A model already trained on large general datasets.
• 4. What changes during fine-tuning?
• Model weights get updated.
• 5. What is RAG?
• Retrieval-Augmented Generation uses external documents without modifying model weights.
• 6. Fine-tuning vs RAG difference?
• Fine-tuning changes the model. RAG retrieves knowledge dynamically.
• 7. Which is cheaper?
• RAG is generally cheaper.
• 8. When is fine-tuning useful?
• What is PEFT?
• Parameter Efficient Fine-Tuning — trains only small parts of the model.
• 10. What is LoRA?
• A lightweight PEFT method that adds small trainable matrices.
• 11. Why is full fine-tuning expensive?
• Because it updates billions of parameters.
• 12. What type of data is needed?
• Clean, structured, domain-specific data.
• Can fine-tuning reduce hallucinations?
• It can reduce domain errors but not completely eliminate hallucinations.
• 14. Is fine-tuning permanent?
• Yes, the behavior change remains in the model.
• 15. What do companies prefer?
• PEFT/LoRA for cost and scalability reasons.
• Simple Fine-Tuning Program
• import torch
• import [Link] as nn
• import [Link] as optim

• # Step 1: Create Base Model


• model = [Link](1, 1)

• criterion = [Link]()
• optimizer = [Link]([Link](), lr=0.01)
#Step 2: Pre-Training (General Data)
# Learn y = 2x

X_general = [Link]([[1.0], [2.0], [3.0], [4.0]])


y_general = [Link]([[2.0], [4.0], [6.0], [8.0]])

for epoch in range(200):


output = model(X_general)
loss = criterion(output, y_general)
• optimizer.zero_grad()
• [Link]()
• [Link]()

• print("Before Fine-Tuning:")
• print("Prediction for 5:", model([Link]([[5.0]])).item())
• # Step 3: Fine-Tuning (New Domain Data)
• # Now learn y = 3x

• X_domain = [Link]([[1.0], [2.0], [3.0], [4.0]])


• y_domain = [Link]([[3.0], [6.0], [9.0], [12.0]])

• for epoch in range(100):


• output = model(X_domain)
• loss = criterion(output, y_domain)

• optimizer.zero_grad()
• [Link]()
• [Link]()

• print("\nAfter Fine-Tuning:")
• print("Prediction for 5:", model([Link]([[5.0]])).item())
• Add on
• Print the weights before and after fine tuning
• Experiment my removing [Link]().. And discuss the output
• Change the program so that:
• Pre-training learns y = 2x
Fine-tuning learns y = 2x + 1
• What is Responsible AI?
• Responsible AI refers to designing and using AI systems
in a way that is:
• Ethical
• Fair
• Transparent
• Accountable
• Safe
• Goal: AI should benefit humans without causing harm.
• Your AI hiring model selects mostly male candidates. What would
you do?
• Your chatbot gives incorrect medical advice. What action will you
take?
• Users complain that your AI system is not transparent. What can
you improve?
CONTAINERS WITH DOCKER:
• Problems in Deployment:

• • “Works on my machine” issue


• Dependency conflicts
• Different OS environments
• Hard to scale applications
• Difficult to reproduce ML experiments
• What is Docker?
• Docker is a containerization platform.
• It:
• • Packages app + dependencies
• Runs isolated environments
• Shares host OS kernel
• Lightweight alternative to Virtual Machines
• Core Components:
• • Docker Image
• Docker Container
• Dockerfile
• Docker Hub
• Virtual Machine vs Container
• Virtual Machine:
• • Full OS per VM
• Heavy (GBs)
• Slow startup
• Uses hypervisor
• Container:
• • Shares host OS
• Lightweight (MBs)
• Fast startup
• Efficient resource usage
• 1) What is the difference between Docker image and container?
• Image → Blueprint/template
Container → Running instance of image
• 2) Dfference between VM and Container?
• VM:
• Full OS
• Heavy
• Slow
• Container:
• Shares host OS
• Lightweight
• Fast

• 3) Why are containers preferred in AI deployment?
• Reproducibility
• Dependency isolation
• Easy scaling
• CI/CD compatibility

• 4)What happens if a container crashes?
• It stops.
• If using orchestration (Kubernetes):
It automatically restarts.

• 5) What is Docker Hub?


• Online repository to store and share Docker images.

• Important Docker Commands
• docker run <image>
• docker ps
• docker stop <container_id>
• docker logs <container_id>
• docker exec -it <container_id> bash
• Port Mapping Concept
• docker run -p 8080:80 nginx
• 8080 → Host Port
• 80 → Container Port
• Without -p → App not accessible from browser
•Why containers are lightweight?
•Difference between docker run and docker start?
•What is container isolation?
•What happens if we rebuild image after code change?
•Why Dockerfile instruction order matters?
• LLMOps and Monitoring
• Managing Large Language Models in Production
• LLMOps = Practices for deploying, managing, monitoring, and
improving LLM applications in production.
• It is similar to:
• DevOps
• MLOps
• But specialized for:
• Prompt management
• Model monitoring
• Cost control
• Hallucination detection
• Why LLMOps is Needed?
• Challenges in Production
• Hallucinations
• Unstable outputs
• Prompt drift
• High API cost
• Latency issues
• Security & data privacy
• LLM Lifecycle in Production
• Model Selection
• Prompt Engineering
• Testing & Evaluation
• Deployment
• Monitoring
• Continuous Improvement
• What Do We Monitor?
• Model Performance
• Response accuracy
• Relevance
• Hallucination rate
• System Metrics
• Latency
• Throughput
• Error rate
• Cost Monitoring
• Tokens used
• API cost
• User Feedback
• Ratings
• Satisfaction
• Evaluation Techniques
• Offline Evaluation
• Test dataset
• Expected outputs
• Automated scoring
• Online Evaluation
• A/B testing prompts
• User feedback tracking
• What is Hallucination?
• When LLM generates incorrect but confident answers.
• Detection Methods:
• Ground truth comparison
• RAG verification
• Confidence scoring
• Human review
• Prompt Management in LLMOps
• Why Prompt Versioning?
• Small prompt change → Big output difference
• Hard to track changes
• Solution:
• Version control prompts
• Store prompt templates
• Maintain experiment logs
• Monitoring Metrics
• Key Metrics
• Latency (response time)
• Token usage
• Cost per request
• Failure rate
• User satisfaction score
• Continuous Improvement Loop
• User Input
• ↓
• LLM Response
• ↓
• Monitoring
• ↓
• Evaluation
• ↓
• Prompt/Model Update
• ↓
• Redeploy
• What is Agentic AI?
• Definition
• Agentic AI refers to AI systems that:
• Take goals as input
• Plan actions
• Use tools
• Make decisions
• Execute tasks
• Iterate until goal is achieved
• Not just answering questions.
• Traditional LLM
• Input → Output
• Agentic AI
• Goal

Plan

Tool Use

Memory

Reflection

Final Output

• Core Components
• LLM (Brain)
• Tools
• Memory
• Planner
• Execution Loop
• Example Use Cases
• Resume Agent
• Research Agent
• Code Debugging Agent
• Travel Booking Agent
• Stock Analysis Agent
• Orchestration Frameworks
• Managing Multi-Step AI Workflows in Production
• What is Orchestration?
• Definition
• Orchestration = Coordinating multiple components to work together in a
structured workflow.
• In AI systems, it manages:
• LLM calls
• Tools
• Memory
• Agents
• External APIs
• Control flow

• Why Orchestration is Needed?
• As AI systems grow:
• Multiple prompts
• Multiple tools
• Conditional logic
• Memory handling
• Error handling
• Retry logic
• Manual coding becomes messy.
• Popular Orchestration Frameworks
• Examples:
• LangChain
• LlamaIndex
• Haystack
• Semantic Kernel
• CrewAI
• Popular Orchestration Frameworks
• Content:
• Kubernetes
• Docker Swarm
• Apache Mesos
• OpenShift
• Ansible (for orchestration + automation)
• Kubernetes Architecture
• Content:
• Master Node
• Worker Nodes
• Pods
• Services
• etcd
• kube-apiserver
• Advantages of Orchestration Frameworks
• Content:
• Reduced Manual Work
• Faster Deployment
• Improved Reliability
• Scalability
• Cost Efficiency

You might also like