Generative AI Introduction
Generative AI Introduction
Generative AI course
Generative AI course 1
what is Generative AI
Generative AI refers to AI technologies that can create new content, ideas, or
data that are coherent and plausible, often resembling human-generated
outputs. It has a plethora of practical applications in different domains such as
computer vision, natural language processing, and music generation.
Construct RNNs and CNNs for unstructured data (text and image).
Generative AI course 2
Understand how to use LLMs for downstream tasks: finetuning, zero-shot,
one-shot, and few-shot learning.
Learn best practices for training LLMs, including scaling laws and efficient
training mechanisms.
Explore cutting-edge models like ChatGPT and BARD and understand their
training process, including reinforcement learning from human feedback,
supervised fine-tuning, and prompt engineering.
Disadvantages :
Generative AI course 3
fabricated information.
It can promote new kinds of plagiarism that ignore the rights of content
creators and artists of original content.
Generative AI course 4
It makes it easier to generate fake news.
Generative AI course 5
Improving dubbing for movies and educational content in different
languages.
Meta’s LLaMA
Generative AI course 6
differentiate between real and generated data. This adversarial training
process helps improve the quality of generated samples.
2.
2.
2.
Generative AI course 7
1. Autoencoders: Autoencoders are neural networks trained to copy their
input to their output. They consist of an encoder network that compresses
Generative AI course 8
the input data into a latent space representation and a decoder network that
reconstructs the original input from the latent space representation.
Variants like denoising autoencoders, sparse autoencoders, and contractive
autoencoders serve different purposes.
2.
At the same time, more efficient training techniques will reduce data and
computing needs to improve sustainability.
Generative AI course 9
Steady Improvements in Output Quality and
Accuracy
As this technology advances, its responses may become indistinguishable
from, and possibly superior to human-generated material.
Autonomous AI Agents
One or more AI agents with the ability to learn and adapt on their own,
without the need for human intervention.
This will allow them to automate tasks and make decisions in real time.
Generative AI course 10
Increased Customization and Specialization :
Generative AI will become more customizable, allowing for more
parameters to be fine-tuned on custom data.
Accessibility :
Generative AI tools will become more accessible to people with less data
and expertise.
Text to Everything
The ability to generate text, images, audio, videos, and 3D environments
from a single platform.
This means users will provide a single text prompt and the model will
generate every content format simultaneously.
For example, a user could provide a prompt like “A beautiful sunset over a
beach” and the model would generate a text description of the sunset, a
video of the sunset, and an audio file of the sound of waves crashing on the
shore.
Generative AI course 11
Ultra Realistic Talking Avatars :
Generative AI models will be able to create videos of talking avatars that
are so realistic that they are indistinguishable from real people.
These avatars will be able to lip sync to speech, have natural facial
expressions, subtle head movements and even generate their own
dialogue.
workers and job requirements will need to transition into more strategic
roles.
Generative AI course 12
free up employees for more impactful and creative responsibilities better
suited to human strengths.
Generative AI course 13
Specifically, to identify new market opportunities from various sources by
analyzing customer data, social media, demographics, economic trends,
etc.
By feeding all these data points together, the AI model will be able to
identify new customer needs and wants that are not currently being met
by existing products and services.
• Then
integrate such findings into the process to generate new ideas for
products and services.
Education Sector:
Healthcare Industry:
Generative AI course 14
2. Drug Discovery: Pharmaceutical companies use Generative AI to
discover new drug compounds by generating molecular structures.
Manufacturing Industry:
Generative AI course 15
Prompt engineering is the practice of designing inputs for AI tools that will
produce optimal output
1.
Zero-Shot Learning: This involves giving the AI a task without any prior
examples. You describe what you want in detail, assuming the AI has no prior
knowledge of the task.
Generative AI course 16
. One-Shot Learning: You provide one example along with your prompt. This
helps the AI understand the context or format you’re expecting.
3. Few-Shot Learning: This involves providing a few examples (usually 2–5) to
help the AI understand the pattern or style of the response you’re looking for.
4. Chain-of-Thought Prompting: Here, you ask the AI to detail its thought
process step-by-step. This is particularly useful for complex reasoning tasks.
5. Iterative Prompting: This is a process where you refine your prompt based
on the outputs you get, slowly guiding the AI to the desired answer or style of
answer.
6. Negative Prompting: In this method, you tell the AI what not to do. For
instance, you might specify that you don’t want a certain type of content in the
response.
Instruction. This is the core directive of the prompt. It tells the model what
you want it to do. For example, "Summarize the following text" provides a
clear action for the model.
Input data. This is the specific information or data you want the model to
process. It could be a paragraph, a set of numbers, or even a single word.
Generative AI course 17
Technical skills for prompt engineering :
Familiarity with LLMs. Experience with models like GPT, PaLM2, and other
emerging models their underlying architectures.
Creativity. Thinking outside the box, experimenting with new prompt styles,
and innovating solutions.
Elements of a Prompt
Generative AI course 18
A prompt can include different elements:
Input Data — It refers to the question or input for which we want the model
to provide a response.
1. Text summarization
2. Information Extraction
3. Question Answering
4. Text Classification
5. Code generation
3. Balance Simplicity and Complexity: Find the right balance between simple
and complex prompts to ensure clarity without overwhelming Large
Language Models.
Generative AI course 19
Task
“Task” is the actual prompt, but without the constraints.
Context
“Context” is the actual detailed content and it is the 2nd most important and
essential part of your prompt
Examples
“Examples” is also an important part of proompting since giving clear and
concise examples tells the large language model about the desired outcome
and style
Persona
Generative AI course 20
“Persona” is the moment when you say: “Write Like You Are” or “Create in
the style of” to create the content as if that person is writing it.
Format
“Format” is about in what shape or form you want your results to be.
Tone
“Tone” is when you say: professional, friendly, casual, concise, emotional, etc.
It is the feeling that you want to convey to your readers.
Prompting Principle :
Generative AI course 21
Principle 1: Write clear and specific instructions
Tactics
Delimiters can be anything like: ```, """, < >, <tag> </tag> , :
2. : Instruct the model to work out its own solution before rushing to a
conclusion
2. Summarizing :
Generative AI course 22
1.Summarize with a word/sentence/character limit
2.summarize with your focus point like price , values
3. Inferring :
1. Entity Recognition: Identifying and categorizing entities mentioned in text,
such as people, organizations, locations, dates, and more.
sentiment analysis
identify the emotion
extract multiple things
4. Transforming :
Generative AI course 23
language correction
language translation
Tone transformation
format coversion
writing essay
explaining topic
Generative AI course 24
In this initial phase, the primary focus is on articulating the specific business
challenge where leveraging a Large Language Model (LLM) strategically for
enterprise applications is crucial. Key selection criteria include:
Ensuring the capabilities of the chosen LLM align with the identified
challenge.
2. Select Model: Choose the Right LLM Model for the Business Case
This stage involves strategically selecting the most suitable LLM model tailored
to meet the unique demands of the identified business use case.
Considerations include:
Generative AI course 25
Introducing Retrieval Augmented Generation (RAG) enriches LLM performance
by providing additional context during text generation, leading to:
Generative AI course 26
Utilize multiple benchmarks like GLUE, SuperGLUE, MMLU, BIG-Bench, and
HELM for comprehensive assessment.
Deploying optimized LLMs can occur on-site, on the cloud, or on edge devices
as per requirements.
Generative AI course 27
1. Data Preparation: Data Preprocessing and Filtering
In this stage, the focus is on preparing the data for training by performing
preprocessing and filtering. This involves:
Filtering the data to ensure it meets quality standards and is relevant to the
model's objectives.
Providing tokenized input data to the model to start the training process.
Generative AI course 28
Documenting model architecture, parameters, and training data.
Generative AI course 29
tasks, including language understanding, text generation, image processing,
and natural language conversation.
Generative AI course 30
Extracting insights from documents
Generative AI course 31
pre training :
Data Collection
Specialized Data
Data Preprocessing
Quality Filtering
Deduplication
Tokenization
Mixture of Sources
Emergent Architectures
Layer Normalization
Attention
Positional Encoding
Pretraining Tasks
Language Modeling
Denoising Autoencoding
Mixture-of-Denoisers
Generative AI course 32
Pre-training is the foundation for the power of Large Language Models (LLMs) .
By training on lots of text data, these models get good at understanding and
generating language.
The size and quality of this data are super important. Good data helps
the model achieve better capabilities.
There are two main types of data used to train Large Language Models
(LLMs): general data and specialized data.
General Data:
Why it's used: It's widely available, varied, and helps LLMs get good at
general language understanding and adaptability.
Specialized Data:
Webpages:
What it offers: A wide range of data from the internet that provides
diverse language knowledge.
Issues: Web data can have both high-quality text (like Wikipedia) and
low-quality text (like spam). It's crucial to clean and process this data to
ensure quality.
Conversation Text:
Generative AI course 33
Why it's useful: Helps LLMs get better at conversation and question-
answering.
How it's used: Conversations from online platforms are structured into
tree-like formats to capture responses. This allows multi-party chats to
be split into smaller conversations for training.
Books:
Why they matter: Books offer formal and lengthy texts which help LLMs
understand complex language structures, grasp long-term context, and
produce coherent narratives.
Multilingual Text:
Scientific Text:
Generative AI course 34
Source: Materials like arXiv papers, scientific textbooks, math websites,
and more.
Challenges & Solutions: Scientific texts have things like math symbols
and protein sequences. To handle this, they're specially tokenized and
pre-processed to fit a format LLMs can use.
Code:
Why it's relevant: Training LLMs on code helps with program synthesis,
a popular research area.
Current State: Even powerful LLMs, like GPT-J, find it tough to produce
good, accurate programs.
Source: Code can come from Q&A communities like Stack Exchange or
public software repositories like GitHub. This includes actual code,
comments, and documentation.
Challenges & Solutions: Code has its own syntax and logic, and is very
different from regular text. Training on code, though, might give LLMs
complex reasoning skills.
Benefits: When tasks are formatted like code, LLMs can produce more
accurate answers. In short, using specialized data gives LLMs specific
skills, from understanding multiple languages to generating code.
FIltering :
Quality Filtering Removing low-quality data from the corpus using either classifier-
based or heuristic-based approaches. Classifier-based methods
train a binary classifier with well-curated data as positive
instances and sample candidate data as negative instances, and
predict the score that measures the quality of each data example.
Generative AI course 35
Heuristic-based methods use rules or heuristics to filter out low-
quality data based on certain criteria.
Mixture of sources
Generative AI course 36
Quality of pretraining data
Pretraining Tasks
There are two commonly used pretraining tasks:
1. Language Modelling
2. Denoising Autoencoding
1. Architecture Choice:
Generative AI course 37
LLMs using a causal decoder architecture with a language
modeling (LM) objective have shown strong zero-shot and
few-shot generalization capabilities.
Scaling Law:
Future Research:
1. Long Context:
Extrapolation:
Generative AI course 38
Position embedding techniques like RoPE and T5 bias have
displayed extrapolation abilities. For example, LMs equipped
with ALiBi have demonstrated consistent performance on
sequences much longer than training sequences.
Furthermore, the xPos method seeks to enhance the
extrapolation capability of RoPE.
Efficiency:
Significance of Fine-Tuning
Efficiency: Compared to training a model from scratch, fine-tuning
significantly reduces time and resource requirements by building
upon a pre-existing model's learned features.
Generative AI course 39
Improved Performance: Leveraging a pre-trained model's
knowledge and representations enhances performance on task-
specific datasets, leading to better results.
Steps in Fine-Tuning
1. Select a Pre-Trained Model: Choose a pre-trained model that aligns
with the nature of your task, ensuring compatibility with the required
features.
Generative AI course 40
Addressing Edge Cases: Ensuring model robustness by handling
rare or unlikely scenarios appropriately.
Fine-Tuning Strategies
Full Fine-Tuning
Update the entire neural network similarly to the pre-training
process, demanding significant computational resources.
Partial Fine-Tuning
Selectively update critical parameters while freezing others to
reduce computational demands and stabilize the model.
Additive Fine-Tuning
Introduce new parameters or layers to the model and train only
these additional components while preserving the original pre-
trained weights.
Generative AI course 41
Data Efficiency: Transfer learning maximizes the utility of available
labeled data by repurposing it for related tasks, making it particularly
beneficial in scenarios with limited data availability.
Generative AI course 42
Semi-Supervised Learning: Combining labeled and unlabeled data to
improve model performance, especially in scenarios with limited labeled
data.
Fine-Tuning
Adjust the internal parameters of a pre-trained model to adapt it to the
target task while leveraging its learned representations, allowing for
minor updates to the pre-trained weights.
Domain Adaptation
Incorporate techniques such as adversarial training or domain-specific
loss functions to align the learned representations of a model with the
target domain.
Generative AI course 43
popular transfer learning approach can lead to significant
strategies is PEFT. changes in the model’s behavior
and performance, tailored to the
specific task or dataset at hand.
Generative AI course 44
Performance can be similar,
Model Typically results in higher
but often a bit lower than full
performance performance
fine-tuning
RAG vs Finetuning
Purpose:
Fine-tuning LLMs: Fine-tuning involves taking a pre-trained LLM (such as
GPT-3 or BERT) and adapting it to specific tasks. It is a versatile approach
used for various NLP tasks, including text classification, language
translation, sentiment analysis, and more. Fine-tuned LLMs are typically
used when the task can be accomplished with just the model itself and
doesn’t require external information retrieval.
RAG: RAG models are designed for tasks that involve both retrieval and
generation of text. They combine a retrieval mechanism, which fetches
relevant information from a large database, with a generation mechanism
Generative AI course 45
that generates human-like text based on the retrieved information. RAG
models are often used for question-answering, document summarization,
and other tasks where accessing local information is crucial.
Architecture:
Fine-tuning LLMs: Fine-tuning LLMs usually start with a pre-trained model
(like GPT-3) and fine-tune it by training on task-specific data. The
architecture remains largely unchanged, with adjustments made to the
model’s parameters to optimize performance for the specific task.
Training Data:
Fine-tuning LLMs: Fine-tuning LLMs rely on task-specific training data,
often consisting of labeled examples that match the target task, but they
don’t explicitly involve retrieval mechanisms.
RAG: RAG models are trained to handle both retrieval and generation, which
typically involves a combination of supervised data (for generation) and
data that demonstrates how to retrieve and use external information
effectively
Use Cases:
Fine-tuning LLMs: Fine-tuned LLMs are suitable for a wide range of NLP
tasks, including text classification, sentiment analysis, text generation, and
more, where the task primarily involves understanding and generating text
based on the input.
RAG: RAG models excel in scenarios where the task requires access to
external knowledge, such as open-domain question-answering, document
Generative AI course 46
summarization, or chatbots that can provide information from a knowledge
base.
Feature Storage: Store the gold standard of features that have been
painstakingly curated and prepped. We do this primarily for AI governance
and consistency across the enterprise and the may project that will be
attached to it; we will want to store and manage features used in training
and inference ; often distinguishing between static and dynamic or train
time and run time feature store capabilities. Looking to provide answers to
questions from development teams around: “Where did we get the data
from? Who touched the data? Did they bias the data during
curation/labeling?” For example, you can use the Vertex AI Feature Store to
support this task.
Data Bias Check. This is an essential step in the machine learning lifecycle,
especially for generative AI models, to ensure that the training data and the
Generative AI course 47
generated content is fair, unbiased, and representative of the underlying
data distribution. Bias in generative AI models can lead to the creation of
outputs that reinforce stereotypes, discriminate against certain groups, or
misrepresent reality. We can address data bias in predictive and generative
AI, right after collecting and curating the data. By incorporating data bias
checks into the machine learning lifecycle for generative AI, we can work
towards creating models that generate fair, unbiased, and representative
content, ultimately ensuring that the AI systems we develop align with
ethical guidelines and societal values.Data Collection and Preparation
Fine-tune models: Update an existing model with new data or for a new
task
Model registry: This is a means and mechanism for Model Governance and
Model Risk Management. To use the Model Registry we would Store and
manage models for versioning, reuse, and auditing, marking the meta-data
of the model to see where the data came from (Data Provenance, Lineage),
how the model was trained, etc.
Distributed Training
Data parallelism: Split data across multiple devices and training them
simultaneously to speed up training
Model parallelism: Split the model across multiple devices and training them
simultaneously to fit larger models into memory
Generative AI course 48
Federated learning: Train models collaboratively across multiple devices or
organizations while preserving privacy and security.
Model Adaptation
Transfer learning
Adapt a pre-trained model to a new domain or task
Fine-tune models
Update an existing model with new data or for a new task
AI Safety Mitigation
Ensure the model is safe, ethical, and trustworthy by mitigating misuse,
improving robustness, and ensuring privacy and security.
Distillation
Train or create a much smaller model with similar performance and
downstream task capabilities by using a student/teacher few-shot learning
approach to train a much smaller model, or, prune a model to arrive at a smaller
footprint deployable model.
There are several methods to distill large language models (LLMs) to arrive at
significantly smaller models with comparable performance. Let’s explore some
common approaches .
2. Quantization: This involves reducing the precision of the LLM’s weights and
activations. For example, weights that were initially represented as 32-bit
floating-point numbers can be quantized to 8-bit integers. This reduces the
model’s memory footprint without significantly impacting its performance.
Generative AI course 49
used to train models that are orders of magnitude smaller than the original
model with only a small reduction in accuracy.
Model Deployment
Let’s discuss how to serve the model using Google Cloud’s Vertex
AI endpoint. Serving a model on a Vertex AI endpoint involves packaging the
model into a container image, uploading the image to a container registry,
creating a model resource and endpoint in the Vertex AI console, deploying the
model to the endpoint, testing the endpoint, and monitoring its performance.
1. Prepare the Model. First, you need to prepare the trained model for
deployment. This typically involves packaging the model and any required
dependencies into a container image, such as a Docker image.
2. Upload the Container Image. Next, you need to upload the container image
to a container registry, such as Google Container Registry. This will allow
you to easily deploy the image to a Vertex AI endpoint.
Generative AI course 50
3. Create a Model Resource. In the Vertex AI console, create a model
resource that will represent your deployed model. This involves specifying
the model’s name, description, and any other metadata that may be
required.
5. Deploy the Model. Once the endpoint is created, you can deploy your
model to the endpoint. This involves specifying the container image to use
and any required settings, such as the number of replicas to deploy.
Model Maintenance
Data and model drift. Monitor and managing changes in data distribution
and model performance over time
Performance optimization
Hardware acceleration. Optimize the model for specific hardware
accelerators to improve inference speed and efficiency
Generative AI course 51