Understanding Generative AI Basics
Understanding Generative AI Basics
• Introduction to Generative AI
• Transformer Model
• Examples of Transformer Models
• Synthetic Data
• Large Language Models
• Generative Adversarial Network
• Generative AI in the classroom
What is Generative AI?
• Generative AI is a type of arti cial intelligence technology
that can produce various types of content, including text,
imagery, audio and synthetic data. The recent buzz around
generative AI has been driven by the simplicity of new user
interfaces for creating high-quality text, graphics and videos
in a matter of seconds.
• The main core characteristic of the Transformers architecture is that they maintain the encoder-
decoder model.
• If we start considering a Transformer for language translation as a simple black box, it would take
a sentence in one language, English for instance, as an input and output its translation in English.
fi
• If we dive a little bit, we observe that this black box is composed of two main parts:
• The encoder takes in our input and outputs a matrix representation of that input. For
instance, the English sentence “How are you?”
• The decoder takes in that encoded representation and iteratively generates an output. In
our example, the translated sentence “¿Cómo estás?”
• However, both the encoder and the decoder are actually a stack with multiple layers (same number for
each). All encoders present the same structure, and the input gets into each of them and is passed to
the next one. All decoders present the same structure as well and get the input from the last encoder
and the previous decoder.
• The original architecture consisted of 6 encoders and 6 decoders, but we can replicate as many layers
as we want. So let’s assume N layers of each.
The Encoder WorkFlow
• The encoder is a fundamental component of
the Transformer architecture. The primary
function of the encoder is to transform the
input tokens into contextualized
representations.
• All the encoders receive a list of vectors, each of size 512 ( xed-sized). In the bottom encoder,
that would be the word embeddings, but in other encoders, it would be the output of the
encoder that’s directly below them.
fi
STEP 2 - Positional Encoding
• Since Transformers do not have a recurrence
mechanism like RNNs, they use positional
encodings added to the input embeddings to
provide information about the position of each
token in the sequence. This allows them to
understand the position of each word within the
sentence.
• This mechanism allows the encoder to focus on di erent parts of the input sequence as it
processes each token. It computes attention scores based on:
• A query is a vector that represents a speci c word or token from the input sequence in the attention
mechanism.
• A key is also a vector in the attention mechanism, corresponding to each word or token in the input
sequence.
• Each value is associated with a key and is used to construct the output of the attention layer. When
a query and a key match well, which basically means that they have a high attention score, the
corresponding value is emphasized in the output.
• This rst Self-Attention module enables the model to capture contextual information from the entire
sequence. Instead of performing a single attention function, queries, keys and values are linearly
projected h times. On each of these projected versions of queries, keys and values the attention
mechanism is performed in parallel, yielding h-dimensional output values.
fi
fi
ff
Matrix Multiplication (MatMul) - Dot Product of Query and Key
• Once the query, key, and value vectors are passed through a linear layer, a dot product matrix
multiplication is performed between the queries and keys, resulting in the creation of a score
matrix.
• The score matrix establishes the degree of emphasis each word should place on other words.
Therefore, each word is assigned a score in relation to other words within the same time step. A
higher score indicates greater focus.
ff
Applying Softmax to the Adjusted Scores
• Subsequently, a softmax function is applied to the adjusted scores to obtain the attention
weights. This results in probability values ranging from 0 to 1. The softmax function
emphasizes higher scores while diminishing lower scores, thereby enhancing the model's
ability to e ectively determine which words should receive more attention.
ff
Combining Softmax Results with the Value Vector
• The following step of the attention mechanism is that weights derived from the softmax function are multiplied by the
value vector, resulting in an output vector.
• In this process, only the words that present high softmax scores are preserved. Finally, this output vector is fed into a
linear layer for further processing.
• This careful encoding paves the way for the decoder, guiding it to pay attention to the
right words in the input when it's time to decode.
• Think of it like building a tower, where you can stack up N encoder layers. Each layer in
this stack gets a chance to explore and learn di erent facets of attention, much like
layers of knowledge. This not only diversi es the understanding but could signi cantly
amplify the predictive capabilities of the transformer network.
fi
fi
ff
fi
The Decoder WorkFlow
• The decoder's role centers on crafting text sequences. Mirroring the encoder,
the decoder is equipped with a similar set of sub-layers. It boasts two multi-
headed attention layers, a pointwise feed-forward layer, and incorporates both
residual connections and layer normalization after each sub-layer.
• These components function in a way akin to the encoder's layers, yet with a
twist: each multi-headed attention layer in the decoder has its unique mission.
• The nal of the decoder's process involves a linear layer, serving as a classi er,
topped o with a softmax function to calculate the probabilities of di erent
words.
• The Transformer decoder has a structure speci cally designed to generate this
output by decoding the encoded information step by step.
• This sequential dance of decoding continues until the decoder reaches a pivotal
moment: the generation of a token that signals the end of its output creation.
fi
ff
fi
ff
fi
STEP 1 - Output Embeddings
At the decoder's starting line, the process mirrors that of the encoder. Here, the
input rst passes through an embedding layer
• For instance, when the attention scores for the word "are" are being computed, it's important
that "are" doesn't get a peek at "you", which is a subsequent word in the sequence.
• This masking ensures that the predictions for a particular position can only depend on known
outputs at positions before it.
fl
ff
STEP 3.2 - Encoder-Decoder Multi-Head Attention or Cross Attention
• In the second multi-headed attention layer of the decoder,
we see a unique interplay between the encoder and
decoder's components. Here, the outputs from the encoder
take on the roles of both queries and keys, while the
outputs from the rst multi-headed attention layer of the
decoder serve as values.
• These models are adept at a wide range of tasks, including content creation,
conversation, language translation, and more. GPT's architecture enables it to
generate text that closely resembles human writing, making it useful in
applications like creative writing, customer support, and even coding
assistance.
• Agent-based modeling. This simulation technique involves creating unique agents that
communicate with one another. These methods are especially helpful when examining how
di erent agents -- such as mobile phones, people or even computer programs -- interact with
one another in a complex system. Using pre-built core components, Python packages, such
as Mesa, make it easier to quickly develop agent-based models and view them via a browser-
based interface.
• Generative models. These algorithms can generate synthetic data that replicates the
statistical properties or features of real-world data. Generative models use a set of training
data to learn the statistical patterns and relationships in the data and then use this knowledge
to generate new synthetic data that's similar to the original data. Examples of generative
models include generative adversarial networks and variational autoencoders.
ff
What are the advantages of synthetic data?
• Customizable data. An organization can customize arti cial data can be created in a shorter amount of
synthetic data to its needs, tailoring the data to time.
certain conditions that can't be obtained with
authentic data. They can also generate data sets for • Complete annotation. Perfect annotation eliminates
software testing and quality assurance (QA) the need for manual data collection. Each object in a
purposes for DevOps teams. scene can automatically create a variety of
annotations. This is also one of the main reasons
• Cost-e ective. Synthetic data is an inexpensive synthetic data is so inexpensive when compared to
alternative to real-world data. For example, real real data.
vehicle crash data can cost an automaker more to
collect than simulated data. • Data privacy. While synthetic data can resemble real
data, it shouldn't contain any information that could
• Data labeling. Even when synthetic data is be used to identify the real data. This characteristic
available, it isn't always labeled. For supervised makes the synthetic data anonymous and suitable
learning tasks, manually labeling a multitude of for dissemination and can be a major plus point for
instances can be time-consuming and error-prone. the healthcare and pharmaceutical industries.
Synthetically labeled data can be created to speed
up the model development process. Additionally, it • Full user control. A synthetic data simulation
guarantees labeling accuracy. enables complete control over every aspect. The
person handling the data set can control event
• Faster production. Because synthetic data isn't frequency, item distribution and many other factors.
gathered from actual events, it's possible to create a ML practitioners also have total control over the data
data set more quickly with the right software and set when using synthetic data. Some examples
technology. As a result, a signi cant amount of include controlling the degree of class separations,
sampling size and level of noise in the data set.
fi
ff
fi
What are the use cases for synthetic data?
• Testing. Compared to rules-based test data, synthetic test data is easier to create and o ers exibility,
scalability and realism. For data-driven testing and software development, synthetic data is crucial.
• AI/ML model training. Synthetic data is increasingly being used to train AI models, as it often
outperforms real-world data and is essential for developing superior AI models. Model performance is
enhanced by synthetic training data, which also eliminates bias and adds fresh domain knowledge and
explainability. Besides being completely privacy-compliant, it also enhances the original data thanks to
the nature of the AI-powered synthetization process. For example, in arti cial training data, uncommon
patterns and occurrences can be upsampled.
• Privacy regulations. Synthetic data enables data scientists to abide by data privacy laws, such as the
Health Insurance Portability and Accountability Act, General Data Protection Regulation and California
Consumer Privacy Act. It's also the best option when using sensitive data sets for testing or training.
Synthetic data enables organizations to gain insights without jeopardizing privacy compliance.
• Health and privacy. Health and privacy data are particularly appropriate for a synthetic approach
because privacy rules place signi cant restrictions on these elds. By using synthetic data, researchers
can extract the information they require without invading people's privacy. Because synthetic data
doesn't represent the data of actual patients, it's extremely unlikely that it results in the reidenti cation
of an actual patient or their personal data record. Synthetic data also has a big advantage over data
masking techniques, which pose greater privacy-related risks.
fi
fi
fi
ff
fl
fi
What are examples of synthetic data?
• Media data. In this use case, computer graphics and image processing algorithms are used to generate
synthetic images, audio and video. For example, Amazon uses synthetic data to train Amazon Alexa's
language system.
• Text data. This can include chatbots, machine translation algorithms and sentimental analysis based on
arti cially generated text data. ChatGPT is an example of a tool that uses text data.
• Tabular data. This consists of synthetically generated data tables used for data analysis, model training
and other applications.
• Unstructured data. Unstructured data can include images, video and audio data that are mostly employed
in elds such as computer vision, speech recognition and autonomous vehicle technology. For example,
Google's Waymo uses synthetic data to train its self-driving cars.
• Financial services data. The nancial sector relies heavily on synthetic data, especially for fraud detection,
risk management and credit risk assessments. For example, JPMorgan and American Express use
synthetic nancial data to improve fraud detection.
• Manufacturing data. The manufacturing industry uses synthetic data for quality control testing and
predictive maintenance. For instance, German insurance company Provinzial tests synthetic data for
predictive analytics.
fi
fi
fi
fi
Synthetic data vs. real data
• Financial services and healthcare are two industries that bene t from synthetic data
techniques. The techniques can be used to manufacture data with attributes similar to actual
sensitive or regulated data. This enables data professionals to use and share data more
freely.
• For example, synthetic data enables healthcare data professionals to enable public use of
record-level data but still maintain patient con dentiality.
• In the nancial sector, synthetic data sets, such as debit and credit card payments, that look
and act as typical transaction data can help expose fraudulent activity. Data scientists can
use synthetic data to test or evaluate fraud detection systems, as well as develop new fraud
detection methods. Synthetic nancial data sets can be found on Kaggle, a crowdsourced
platform that hosts predictive modeling and analytics competitions.
• DevOps teams use synthetic data for software testing and QA. They can plug arti cially
generated data into a process without taking authentic data out of production. However,
some experts recommend DevOps teams choose data masking techniques over synthetic
data techniques because production data sets contain complex relationships that make it
hard to manufacture an accurate representation quickly and cheaply.
fi
fi
fi
fi
fi
Synthetic data and machine learning
• Synthetic data is gaining traction within the machine learning domain. ML algorithms are
trained using an immense amount of data, and collecting the necessary amount of labeled
training data can be cost-prohibitive.
• Synthetically generated data can help companies and researchers build data repositories
needed to train and even pre-train ML models, a technique referred to as transfer learning.
• Research e orts to advance synthetic data use in ML are underway. For example, members of
the Data to AI Lab at the Massachusetts Institute of Technology Laboratory for Information
and Decision Systems documented the recent successes it had with its Synthetic Data Vault,
which can construct ML models to automatically generate and extract its own synthetic data.
• Companies are also beginning to experiment with synthetic data techniques. For example, a
team at Deloitte LLC used synthetic data to build an accurate model by arti cially
manufacturing 80% of the training data, using real data as seed data. Computer vision, image
recognition and robotics are additional applications that are bene ting from the use of
synthetic data.
ff
fi
fi
[Link]
• MOSTLY AI is the leader in the
tabular synthetic data category,
enabling safe and insightful data
utilization for all.
• In simpler terms, an LLM is a computer program that has been fed enough examples to be able to
recognize and interpret human language or other types of complex data. Many LLMs are trained on
data that has been gathered from the Internet — thousands or millions of gigabytes' worth of text.
But the quality of the samples impacts how well LLMs will learn natural language, so an LLM's
programmers may use a more curated data set.
• LLMs use a type of machine learning called deep learning in order to understand how characters,
words, and sentences function together. Deep learning involves the probabilistic analysis of
unstructured data, which eventually enables the deep learning model to recognize distinctions
between pieces of content without human intervention.
• LLMs are then further trained via tuning: they are ne-tuned or prompt-tuned to the particular task
that the programmer wants them to do, such as interpreting questions and generating responses, or
translating text from one language to another.
fi
fi
fi
Top 10 Open-Source LLM Models
• LLaMA 3
• BLOOM
• BERT (Bidirectional Encoder Representations from Transformers)
• Falcon 180B
• OPT-175B
• XGen-7B
• GPT-NeoX and GPT-NeoX
• Vicuna 13-B
• YI 34B
• Mixtral 8x7B
Generative Adversarial Network
• GAN stands for Generative Adversarial Network. It's
a type of arti cial intelligence (AI) framework that
uses two neural networks to compete against each
other. One network, called the generator, tries to
create new data that is indistinguishable from real
data. The other network, called the discriminator,
tries to determine whether the data it is seeing is
real or fake.
• TensorFlow Generative Adversarial Networks (TF-GAN): This is a popular library from Google
that provides tools for building and training GANs.
• PyTorch-GAN: This is another popular library, but for the PyTorch deep learning framework.
• StyleGAN: This model is particularly good at generating realistic images of faces.
• DCGAN: This is a classic GAN architecture that is still widely used today.
• ProGAN: This is an improved version of DCGAN that can generate higher-resolution images.
• BigGAN: This model can generate very large and high-resolution images.
• GauGAN: This model is speci cally designed for generating images of landscapes.
• StyleFlow: This model uses a di erent approach to generate images, based on normalizing ows.
• MuseGAN: This model is designed to generate music, rather than images.
• MelGAN: This model is another model for generating music, speci cally focused on generating
singing voices.
fi
ff
fi
fl
Generative AI in the classroom
Personalized learning with Generative AI
Generative AI is like a super-powered tool for creating customized learning experiences.
Here's how it can personalize learning:
• Tailored Content: Imagine a system that analyzes a student's strengths, weaknesses, and learning style.
Generative AI can then create educational materials just for them, like:
• Bite-sized lessons that focus on areas they need the most help with
• Practice problems that target speci c learning gaps
• Interactive simulations or VR experiences to bring concepts to life
• Learning Path Flexibility: Generative AI can create unique learning paths for each student. This means
no more one-size- ts-all curriculum. The system can adjust the pace and di culty of the material based
on the student's progress.
• Engaging Activities: Generative AI can create all sorts of engaging activities that cater to di erent
learning styles. A student who learns best visually might get infographics and concept maps, while an
auditory learner might get personalized podcasts or lectures.
• Motivational Support: Imagine an AI tutor that tailors its approach to keep students motivated. It could
use a student's interests to create relevant examples or even generate a virtual learning companion based
on a role model they admire.
fi
fi
ffi
ff
Here are some of the bene ts of personalized learning with generative AI:
• Boosts Engagement: Students are more likely to be interested in learning if the material is
relevant and caters to their needs.
• Improves Retention: Interactive and personalized experiences can help students remember
information for longer.
• Empowers Learners: Students take more ownership of their learning when they have a say in
how they learn.
It's important to note that generative AI is still under development. There are also challenges
to consider, like ensuring fairness and avoiding bias in the AI algorithms. But overall, generative
AI has the potential to revolutionize education by creating a more personalized and effective
learning experience for everyone.
fi
Content Creation
AI is rapidly transforming the world of content creation, making it faster, more e cient, and even
more creative in some ways. Here's a breakdown of how AI is being used for content creation:
• SEO optimization: AI can analyze search trends • Data analysis: AI can analyze content performance
and suggest keywords and content structures that data and provide insights to help you improve your
will help your content rank higher in search results. future content strategy.
fi
fl
fi
ff
ffi
Some popular AI content creation tools include:
• Jasper
• [Link]
• HubSpot
• Synthesia
• Frase
Here are some key things to consider about AI for content creation:
• AI is a tool, not a replacement: While AI can generate content, it lacks the human touch of creativity
and critical thinking. Use AI to enhance your work ow, but don't rely solely on it.
• Quality control is essential: AI-generated content may require editing and proofreading to ensure
accuracy and avoid factual errors.
• Originality and bias: AI content can sometimes lack originality or perpetuate biases present in its
training data. Be mindful of these limitations.
Overall, AI is a powerful force that can signi cantly improve the content creation process. By using AI
effectively, you can create high-quality content, save time, and reach a wider audience.
fi
fl
Language Learning
Generative AI is like a language learning superpower, personalizing the experience for faster progress and deeper
understanding. Here's how it can be a game-changer:
Conversational Practice: Imagine having a tireless AI companion to converse with! Generative AI can hold
conversations on various topics, tailored to your level. It can:
• Respond to your questions and prompts in a natural way
• Adjust the dif culty and complexity of conversations based on your progress
• Simulate real-life scenarios like ordering food or asking for directions
Personalized Learning Materials: Generative AI can create custom learning materials that target your speci c needs.
This might include:
• Interactive stories or games that reinforce grammar and vocabulary
• Personalized quizzes and exercises to identify and address knowledge gaps
• Learning materials that align with your interests, making learning more engaging
Instant Feedback and Corrections: Generative AI can provide immediate feedback on your pronunciation, grammar,
and sentence structure. This real-time guidance helps you learn from mistakes and improve quickly.
Immersive Learning Experiences: Generative AI can create virtual simulations that immerse you in the target
language environment. Imagine practicing your language skills in a virtual marketplace or restaurant!
fi
fi
Here are some advantages of using generative AI for language learning:
• Increased Engagement: Interactive and personalized practice keeps you motivated and fosters a love for
learning the language.
• Improved Fluency: Regular conversation practice with AI helps you speak the language more naturally
and con dently.
• Focus on Weaknesses: Targeted learning materials address your speci c gaps, leading to faster progress.
• Accessibility and Flexibility: You can learn anytime, anywhere with an AI language partner.
It's important to remember that generative AI for language learning is still evolving. Some challenges
include ensuring the AI can understand diverse accents and slang, and effectively representing cultural
nuances.
However, the potential of generative AI to personalize and enhance language learning is undeniable. It can
be a valuable tool for anyone looking to improve their language skills in a fun and interactive way.
fi
fi
Examples
• TalkPal - This AI chatbot platform uses machine learning to tailor lessons to your needs and
goals. It o ers conversation practice,personalized feedback, and interactive exercises.
• Langotalk - This app uses AI-powered chatbots to provide 24/7 immersion in your target
language. You can converse with the chatbot on various topics, and it will correct your
mistakes and provide feedback.
• Eggbun Education - This language learning platform o ers chatbot tutors like Lanny, who can
guide you through lessons, provide audio examples, and help you practice vocabulary and
grammar. It's designed for learners of Chinese, Japanese, and Korean.
• Memrise - While not exclusively an AI chatbot, Memrise uses a chatbot feature to provide
personalized feedback and practice conversations. It o ers gami ed lessons and interactive
exercises to make learning more engaging.
• Duolingo - Similar to Memrise, Duolingo o ers a chatbot feature for practicing conversations.
It's a popular language learning app with a wide variety of courses and exercises.
ff
ff
ff
ff
fi
Generative AI in accessibility tools
• Generative AI has the potential to be a game-changer in the world of accessibility tools, breaking
down barriers and empowering people with disabilities. Here's how:
• Sign language generation: AI can generate sign language interpretations for audio content,
facilitating communication for those who are deaf or hard of hearing.
• Smart environment navigation: AI-powered tools can create real-time audio descriptions of
surroundings, aiding visually impaired people in navigating unfamiliar environments.
Improving Access to Information:
• Automatic alt text generation: Generative AI can automatically create alt text
descriptions for images, making web content accessible for people who rely on screen
readers.
• Content customization for learning styles: AI can adapt written information to different
learning styles, like converting text to audio for auditory learners or creating visual aids for
kinesthetic learners.
Overall, generative AI holds immense promise for the accessibility landscape. As this
technology continues to develop, we can expect even more innovative tools that
empower people with disabilities and create a more inclusive world.
THE END