Generative AI Models?
AI simulates human intelligence by learning from data through a process called training.
Discriminative AI models classify data by distinguishing between different classes, such as spam vs.
non-spam emails, but cannot generate new content or understand context deeply.
Generative AI is a type of artificial intelligence that doesn’t just recognize or classify information—it
actually creates new content based on what it has learned. Imagine you have a digital artist who has
studied thousands of paintings. Instead of just telling you if a painting is a landscape or a portrait
(which is what traditional AI does), this artist can paint a brand-new picture inspired by all those styles
and colors it has seen before. Generative AI works similarly: it learns patterns from data and then uses
that knowledge to generate fresh text, images, music, or even code.
• Foundation Models and LLMs: Foundation models are a new AI paradigm where a single
large model is trained on vast amounts of unstructured data (like text) in an unsupervised way.
Large language models (LLMs) like ChatGPT are examples of foundation models specialized in
language tasks.
• Training Process: These models are trained by predicting the next word in sentences using
terabytes of data. This generative task enables them to learn language patterns deeply.
• Generative AI: Foundation models belong to generative AI because they generate new content
(e.g., the next word in a sentence).
• Tuning and Prompting: Although trained for generation, these models can be adapted for
specific tasks like classification or named entity recognition by:
• Tuning: Introducing a small amount of labeled data to adjust the model.
• Prompting: Using carefully designed inputs (prompts) to guide the model to perform
tasks without additional training.
• Advantages:
• High performance due to exposure to massive data.
• Productivity gains since less labeled data is needed for specific tasks.
• Disadvantages:
• High computational cost for training and running the models.
• Trustworthiness issues because training data is scraped from the internet, which may
contain biases or toxic content, and the exact data is often unknown.
• Applications Beyond Language: Foundation models are also used in vision (e.g., DALL·E 2
for image generation), code generation (e.g., Copilot), chemistry (e.g., Moleformer for molecule
discovery), and climate science (earth science models).
What is NLP (Natural Language Processing)?
Natural Language Processing (NLP) and its role in converting human language into a form that
computers can understand and process.
NLP involves translating unstructured text (like everyday speech) into structured data that
computers can work with.
It includes two main processes: Natural Language Understanding (NLU) for converting
unstructured text to structured data, and Natural Language Generation (NLG) for the reverse.
Use Cases of NLP
• Machine translation requires understanding context to accurately translate between languages.
• Virtual assistants and chatbots use NLP to interpret commands and respond appropriately.
• Sentiment analysis helps determine the emotional tone of text, such as product reviews or
emails.
• Spam detection identifies unwanted emails by analyzing content patterns.
How NLP Works: Key Techniques
• Tokenization breaks text into smaller units called tokens.
Imagine you have a sentence like "Add eggs and milk to my shopping list." Tokenization is like
cutting this sentence into smaller pieces called tokens, usually words. So, the sentence breaks
down into tokens: ["Add", "eggs", "and", "milk", "to", "my", "shopping", "list"]. This makes it
easier for a computer to analyze each part separately.
• Stemming reduces words to their base form by removing prefixes and suffixes.
Words can have different forms, like "running," "runs," and "ran." Stemming chops off the extra
bits (prefixes or suffixes) to get to the base form or stem. For these words, the stem is "run." It's
like trimming a tree branch to its main trunk. However, stemming is a rough cut and sometimes
can be inaccurate, like turning "better" into "bet," which doesn't capture the true meaning.
• Lemmatization finds the root form of a word based on its meaning.
This is a smarter way to find the root form of a word by understanding its meaning. For
example, "better" is linked to the root word "good." Lemmatization uses a dictionary-like
approach to find this root, so it’s more precise than stemming. Think of it as finding the original
seed from which a plant grew.
• Part of speech tagging identifies the grammatical role of words depending on context.
Words can play different roles depending on the sentence. Take the word "make": in "I will
make dinner," "make" is a verb (an action). But in "What make is your laptop?" it’s a noun (a
thing). Part of speech tagging helps the computer figure out these roles based on context, like a
detective solving a mystery.
• Named entity recognition detects specific entities like names or locations within text.
This tool spots special names or entities in text. For example, in "Arizona is sunny," "Arizona"
is recognized as a U.S. state. In "Ralph is here," "Ralph" is identified as a person's name. NER
helps computers understand important details in sentences.
In-Context Learning
In-context learning involves providing task demonstrations within the prompt itself, allowing
the model to learn new tasks without additional training.
It reduces the need for fine-tuning on specific datasets, saving time and resources, but is limited
by the amount of context that can be provided.
Prompt Engineering
Prompts are inputs consisting of instructions and context that guide LLMs to perform specific
tasks or generate desired outputs.
Prompt engineering is the process of designing and refining these prompts to maximize the
relevance and accuracy of AI responses.
Advantages of Prompt Engineering
• Enhances the effectiveness and accuracy of LLMs by providing clear, context-rich instructions.
• Helps meet user expectations and reduces misunderstandings without requiring continual model
fine-tuning.
Components of a Well-Structured Prompt
• Instructions: Clear commands specifying the task.
• Context: Background information to help the model understand the scenario.
• Input Data: The actual data the model processes.
• Output Indicator: A marker indicating where the model should provide its response.
LangChain
LangChain, a Python framework designed to simplify the development of large language model
(LLM) applications by integrating and processing text data efficiently.
LangChain Purpose and Benefits
LangChain helps developers pinpoint relevant information in large texts and respond to
complex prompts by chaining retrieval, extraction, processing, and generation steps.
Key benefits include modularity (building applications from reusable components), extensibility
(easy to add features and integrate with external systems), and decomposition (breaking down
complex tasks into manageable steps).
Advanced Methods of Prompt Engineering
Zero-shot prompting instructs an LLM to perform a task without prior examples, relying on its
general knowledge.
One-shot and few-shot prompting provide one or a few examples to guide the LLM in
performing similar tasks more accurately.
Chain-of-thought (CoT) prompting guides the LLM through step-by-step reasoning for complex
problems, improving transparency and accuracy.
Self-consistency involves generating multiple independent answers to the same question and
selecting the most consistent result to enhance reliability.
Tools and Applications for Prompt Engineering
• Tools like OpenAI Playground, LangChain, Hugging Face Model Hub, and IBM AI Classroom
facilitate prompt development, testing, and deployment.
• LangChain uses prompt templates to create consistent and adaptable prompts, and supports
agents that perform complex tasks across various domains using LLMs and integrated tools.
LangChain LCEL Chaining Method
LangChain Expression Language (LCEL) chaining method for building flexible and
composable AI application workflows.
LCEL Basics and Benefits
• LCEL uses the pipe (|) operator to connect components, creating a clean and readable data flow
from input to output.
• It offers better composability, clearer visualization, and more flexibility compared to traditional
chain approaches.
Core Components and Syntax
• Prompts are defined using templates with variables inside curly braces.
• Chains are built by connecting prompt templates, LLMs, and other components using the pipe
operator.
• LCEL automatically converts functions and dictionaries into runnable components, supporting
parallel and sequential execution.
Runnable Composition and Execution
• RunnableSequence chains components sequentially, passing output to the next.
• RunnableParallel runs multiple components concurrently with the same input.
• LCEL simplifies syntax by replacing RunnableSequence with the pipe operator and handles
type coercion behind the scenes.
Practical Usage and Recommendations
• LCEL is ideal for simpler orchestration tasks and supports parallel execution, async, streaming,
and tracing.
• For complex workflows, LangGraph is recommended while still using LCEL within nodes.
• The video demonstrates creating chains that format prompts, run LLMs, and parse outputs using
LCEL’s chaining method.
•