0% found this document useful (0 votes)
107 views49 pages

Module 1 - Intro To GenAI - PEC - Gen - AI - Training

The PEC Generative AI Training Program - Cohort 2 focuses on educating engineers about generative AI, including its models, applications, and interaction methods. The program covers topics such as deep learning, language models, APIs, and techniques like stemming and lemmatization. Additionally, it introduces Retrieval-Augmented Generation (RAG) to enhance the accuracy and relevance of AI responses.

Uploaded by

regata4
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)
107 views49 pages

Module 1 - Intro To GenAI - PEC - Gen - AI - Training

The PEC Generative AI Training Program - Cohort 2 focuses on educating engineers about generative AI, including its models, applications, and interaction methods. The program covers topics such as deep learning, language models, APIs, and techniques like stemming and lemmatization. Additionally, it introduces Retrieval-Augmented Generation (RAG) to enhance the accuracy and relevance of AI responses.

Uploaded by

regata4
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
You are on page 1/ 49

Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Pakistan Engineering Council

Training Program - Cohort 2

Module 1 - Day 2, April 14, 2025


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Ubaid Ullah
Chemist from University of Sialkot (USKT)
Trainer and Moderator at ICodeGuru.

Feel Free to Connect:


https://www.linkedin.com/in/ubaid-ullah24/
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Pak Angels Essential Gen-AI Training


Introduction to Generative AI

Trainer: Ubaid Ullah


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Module 1 Agenda
Understanding A Generative AI Model
○ Finding a Generative Model
○ Transformer
○ Understanding ChatGPT Model Process
○ Stemming and lemmatization
○ Understating its parameters, inputs required, performance requirement
○ Creating and using an API Key
○ Vector Database
○ RAG and its different Techniques Theoretical
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Deep Learning
DL is a type of machine learning that uses Artificial Neural Networks to learn complex patterns from
the data.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Generative AI
• Generative AI is a subset of AI that aims to generate new content from given instructions
(Prompt).
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

What are Language Models (LLM)


A language model is a type of Gen AI that generates text.

Autocomplete is a language model. We use LLMs everyday!!


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Understanding Machine Learning Models and Large


Language Models (LLMs)
Machine Learning Models:
• Algorithms that learn patterns from data to make predictions or decisions.
• Types:
• Supervised Learning: Learns from labeled data (e.g., predicting house prices).
• Unsupervised Learning: Finds patterns in unlabeled data (e.g., clustering customers).
• Reinforcement Learning: Learns by trial and error (e.g., game playing AI).
• Deep Learning: Identifies patterns in data using neural networks
Large Language Models (LLMs):
• A type of deep learning model designed to understand and generate human language.
• Examples: GPT-4, BERT.
• Capabilities:
• Text Generation: Writing essays, stories, code.
• Language Translation: Translating between languages.
• Chatbots: Engaging in conversations with users.
• Training: Trained on vast amounts of text data to understand context, grammar, and nuances of
language.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

How can I interact with these models?


● Chat Interfaces
○ ChatGPT
○ Google Gemini
○ Claude

● LLM APIs
○ GPT (3.5, 4, 4 turbo, 4-o, 4-o turbo)
○ Gemini
○ Mistral
○ Whisper

● Specialized models
○ YOLO
○ Google T5-base
○ Whisper
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Chat Interfaces
• Simplest way to interact with LLMs (Large Language Models)
• These interfaces exist for most of the big LLMs available today e.g.
• ChatGPT
• Gemini
• Claude
• Groq
• Most of these services have a free plan that limits usage (certain number of prompts per day) or
limits the models available (ChatGPT 3.5 vs. 4)
• These chat interfaces are a great way to play around with LLMs, work on prompting skills and
getting everyday tasks done like writing emails, documentation, study questions, etc.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Chatgpt.com
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

What is an API?
• APIs, or Application Programming Interfaces, are like waiters at a restaurant. They
take requests from you (the customer), tell the kitchen (the server) what you
want, and then bring the response back to you.
• Imagine a Restaurant:
• You (the customer): Want to order food (ask for data or action).
• Waiter (API): Takes your order to the kitchen (server).
• Kitchen (Server): Prepares the food (processes the request).
• Waiter (API): Brings the food back to you (returns the data).
• Simple Breakdown:
• You make a request: "What’s the weather in New York?"
• API delivers the request: Takes it to the server.
• Server processes: Finds the weather data.
• API brings back: "The weather is sunny!"
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Accessing LLMs through APIs


• Most of the LLMs from the big tech companies have APIs available to interact with their LLMS
• Pros:
• Easy to setup and use
• Faster prototyping
• You do not need expensive equipment like GPUs to run these models locally, everything runs on their servers
• Access to the most powerful LLMs available (GPT 4-o, Gemini Ultra, etc.)
• Cons:
• The API usage usually costs money
• The application can be slower because the data has to go to the companies server and come back.
• Any application using LLM APIs must be connected to the internet when being used and the speed of the internet
connection can impact performance.
• Links
• Open AI API documentation
• Google Gemini API Studio
• Claude by Anthropic Console
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Accessing LLMs through APIs


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

What are pre-trained specialized


models?
• These are smaller models that are trained and fine-tuned to perform specific tasks. For
example:
• whisper - speech to text
• Google T5 base - text-to-text translation
• YOLO - Object detection
• Depth-Anything-V2-Small - to measure depth in pictures
• faces_age_detection - to classify pictures of faces into age group (Young, Middle, old)
• These specialized models are far more accurate at accomplishing specific tasks
• These models can be further fine tuned using your own data to increase their accuracy
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Where can I find these specialized


models?
• Many of these specialized models are open sourced which means that they are freely available on the internet for anyone
to download, use and modify.
• There are specific platforms that are built to upload pre trained models with instructions on how to use them. For
example:
• Hugging Face
• Kaggle
• TensorFlow Hub
• Model Zoo
• Hugging Face is the most popular source for pre-trained models and has easy to use instructions for most models
• Most of these websites also have communities and forums for each model so you can ask questions in there as
well.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Hugging Face Example


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Hugging Face Example


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Hugging Face Example


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Hugging Face Example


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

What is “GPT”?
Generative Pre-trained Transformer
(attention is all you need)

Already trained on large The core neural


Produces output corpuses including network architecture
like text (including millions of webpages, that every
code), image, and books etc
generative model is
GPT3 was trained on all of
voice Wikipedia amongst other
built on
things

Leaves room for additional Iteratively calculates the


probability of what the next
training (fine-tuning) for specific piece of information might
tasks like classifying news be based on current inputs
articles into categories like the next note in
Beethoven’s 5th Symphony
or the next word in Fee Fi
Fo
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

What happens to a “cleaned” Input?


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

• Breaking inputs into chunks


Tokenizing • Words/characters for text, sound snippets for voice, pixels
groups for image
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

• Encoding chunks into vectors in an N-dimensional vector space

Embedding • Similar chunks end up as vectors close to each other (words with similar meaning,
pixels that have similar RGB values)
• Can do vector operations like add, subtract, dot, and cross products
• [Vector for “King”] – [Vector for “Man”] + [Vector for “Woman”] = [Vector for “Queen”]
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

•Aftermany rounds of Attention and MLPs, a final vector is


produced which is the official next bit of information
Unembedding •Now we reverse the embedding into a useful token that is the
same as the input tokens like words or pixels
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

“Clean Inputs” – TEXT - Stop words


• Human languages, like English, have a lot of filler words that are grammatical but
don’t add any meaning to the context, these are called stop words

• Some examples in English are “a”, “the”, “an”

• Removing these stop words will lower tokens used and will help you get a more
bang for your buck when fine-tuning a Large Language Model

• Utilities to remove them: NLTK, a python package, is the most used way to
remove them, the full list of stop words can be found here.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

“Clean Inputs” – TEXT - Stemming


• A way to remove prefixes and suffixes from words to distill meaning and “stem”

each word to its basic forms

• Doing this standardizes words and allows models to be sure of each word’s
meaning

• Simple examples are: “walks” becomes “walk”, “retrieval” becomes “retrieve”

• Done using algorithms that, thankfully, we don’t have to develop

• The most common one is PorterStemmer, which uses rules such as removing

common suffixes like “ed”, “ing”, converting plurals to singulars (cars to car), and

reducing adjectives to their base forms (happier to happy)


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

“Clean Inputs” – TEXT – Stemming CONTD.


• Stemming is useful in information retrieval, search, and data mining

• Use it wisely! Be cautious of ”over stemming” – All stemmers have false positives where a
word might be reduced to a form that is meaningless, like “university” might be reduced
to “univers”

• Stemming words can make them lose their contextual meaning e.g. agreement -> agree

• Compound words are poorly handled (e.g “Whiteboard”)

• Stemmers usually don’t handle proper nouns like names well.


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

“Clean inputs” – Text - Lemmatization


• More sophisticated than stemming: better contextual awareness

• Reduces words to their dictionary basic form (lemma) so ”university” will remain as such

• “Running” and “ran” will both be reduced to “run”

• This helps models group certain words (and sentences) together

• Helps reduce overhead and reduce dimensionality of vectors that words produce

• Helps info retrieval: “Best coffee” will also retrieve results for “good coffee”

• Done using NLTK as well, (WordNetLemmatizer) (code demo)


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

“Clean inputs” – Text – Lemmatization


CONTD.
• Beware! Lemmatization is not king.

• Context can still be lost. E.g. “running" and "run" have different nuances in certain contexts, which might be
lost after lemmatization.

• It is computationally expensive and slow because of the complex linguistic analysis

• Rules are specific to each language, requiring different approaches and tools for different languages.

• Ambiguous words can lead to incorrect lemmatization. For example, "bats" can be the plural of "bat" (the
animal) or a form of the verb "to bat".

• Different lemmatization tools might produce inconsistent results for the same text. (so use the same tool
please)
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

STEMMING & LEMMATIZATION DEMO


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

What is RAG?

•Hybrid Approach: Combines LLMs with


information retrieval systems to enhance
response accuracy and relevance.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Why RAG?
Language Models (LMs) like GPT-4 are powerful for generating human-like text
but face key limitations in certain tasks.
Challenges with LLMs:
● Static Knowledge: LLMs are limited to knowledge up to their last training cut-off and lack real-time
updates.

● Contextual Limits: They struggle with generating accurate responses for highly specific or less
common topics without sufficient context.

● Large Scale Data Handling: Handling vast amounts of information and ensuring relevance and
accuracy in responses can be challenging.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

How RAG Works?


Retrieval Component: Fetches relevant documents or data from
a knowledge base or database.

Generation Component: LLM generates responses based on


both retrieved information and its own capabilities.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Benefits of RAG
Updated Knowledge: Access to real-time or recent information.

Enhanced Accuracy: More precise and contextually relevant


answers.

Scalability: Handles large-scale data more effectively, improving


response quality.
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Types of RAG
● Simple RAG
● Simple RAG with Memory
● Branched RAG
● Adaptive RAG
● Corrective RAG (CRAG)
● Self-RAG
● Agentic RAG
Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

Feel free to ask!


Leading Engineers Forward: PEC Generative AI Training Program - Cohort 2

You might also like