0% found this document useful (0 votes)
4 views27 pages

[Coursera] GenAI

The document outlines a course on Generative AI, detailing its architecture, foundational models, and applications in natural language processing (NLP). It discusses various generative AI architectures, the significance of large language models (LLMs), and highlights key libraries and tools such as PyTorch, TensorFlow, Hugging Face, LangChain, and Pydantic for developing NLP applications. Additionally, it addresses the challenges of AI hallucinations and provides methods for mitigating their impact.

Uploaded by

Ran Bi
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)
4 views27 pages

[Coursera] GenAI

The document outlines a course on Generative AI, detailing its architecture, foundational models, and applications in natural language processing (NLP). It discusses various generative AI architectures, the significance of large language models (LLMs), and highlights key libraries and tools such as PyTorch, TensorFlow, Hugging Face, LangChain, and Pydantic for developing NLP applications. Additionally, it addresses the challenges of AI hallucinations and provides methods for mitigating their impact.

Uploaded by

Ran Bi
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/ 27

[Coursera] GenAI​

https://www.coursera.org/learn/generative-ai-llm-architecture-data-
preparation/home/module/1​
• Course 1: Generative AI and LLMs: Architecture and Data Preparation​
• Course 2: Gen AI Foundational Models for NLP & Language Understanding​
• Course 3: Generative AI Language Modeling with Transformers​
• Course 4: AI Engineering with Transformer-Based LLMs ​
• Course 5: Project: Generative AI Applications with RAG and LangChain​

1. Gen AI Architecture​
• ML​

Semi-supervised (DL)​

What is genAI, what is NOT​

• Generative AI refers to deep-learning models that can generate content, such as text, images,
audio, 3D objects, and music, based on the training data.​
• These models understand the relationship between words and phrases and generate
contextually relevant text. An example of a generative AI model for text generation is a
generative pre-trained transformer (GPT).​
• These models can generate images from text input and seed images. Examples of generative
AI models for image generation are data analysis learning with language model for
generation and exploration (DALL-E) and generative adversarial networks (GANs).​
• Generative AI models can generate natural-sounding speech. An example of this type of
generative AI model is WaveNet.​
1.1 Differentiate between various generative AI architectures and models.​
• Generative AI architectures and models include recurrent neural networks (RNNs),
transformers, GANs, variational autoencoders (VAEs), and diffusion models.​
◦ RNNs use sequential or time series data and a loop-based design for training.​
◦ Transformers utilize the self-attention mechanism to focus on the most important parts of
the information.​
◦ GANs consist of a generator and a discriminator, which work in a competitive mode.​
◦ VAEs operate on an encoder-decoder framework and create samples based on similar
characteristics.​
◦ Diffusion models generate creative images by learning to remove noise and reconstruct
distorted examples, relying on statistical properties.​

RNNs​ Transformers​ GANs​ VAE​ Difussion


Models​



​ ​
​ ​
​ ​ ​
​ ​
​ ​
​ ​ ​
Fine-tuning​ ​ ​ ​
​ ​
​ ​
​ ​ ​
Applications​ ​ ​ ​
​ ​


​ ​
1.2 Describe the use of LLMs for NLP tasks.​
• Generative AI started with rule-based systems that use predefined linguistic rules, followed
by machine-learning approaches focusing on statistical methods. It later moved to deep
learning, which uses neural networks trained on extensive data sets. Transformers represent
the latest in this evolution.​
• The evolution of generative AI has led to advancements in machine translation, chatbot
conversations, sentiment analysis, and text summarization.​
• Large language models (LLMs) are foundation models that use AI and deep learning with vast
data sets. LLMs have training data sets that run into petabytes and contain billions of
parameters. Examples of LLMs are GPT, Bidirectional Encoder Representations from
Transformers (BERT), Bidirectional and Auto-Regressive Transformers (BART), and Text-to-
Text Transfer Transformer (T5).​
• Some libraries and tools you can use to implement generative AI for NLP are PyTorch,
TensorFlow, Hugging Face, LangChain, and Pydantic.​
You can utilize large language models (LLMs) to generate authoritative text across domains.
However, they may generate information that sounds right but is inaccurate. They may also
produce biased content. These problems can be a result of AI hallucinations. In this reading, you
will learn about AI hallucinations.​
In AI hallucinations, the model generates output that it presents as accurate but is seen as
unrealistic, inaccurate, irrelevant, or nonsensical by humans. It is similar to the way humans
experience hallucinations.​
For example, there was an incident where ChatGPT falsely claimed that a mayor in Australia was
found guilty and imprisoned in a bribery case. In reality, the mayor notified the authorities
about a bribery issue. (Reference: Australian mayor readies world's first defamation lawsuit over
ChatGPT content | Reuters)​
The example shows that there can be a significant implication of AI hallucinations. However,
note that such incidents are rare and isolated.​
AI hallucinations are strongly associated with LLMs. Factors such as biases in the training data,
limited training, complexity of the model, and lack of human oversight can cause AI
hallucinations. Also, the outputs generated by the AI models might not be based on the patterns
the models learned from the training data.​
Problems caused by AI hallucinations​
AI hallucinations can have serious implications. For example, if an LLM summarizes pages of a
legal document incorrectly, it can lead to legal disputes and litigation.​
Some of the problems caused are:​
• Generation of inaccurate information​
• Creation of biased views or misleading information​
• Wrong input provided to sensitive applications, such as those used in autonomous vehicles
or medical domain​
Methods for mitigating hallucinations​
• Eliminating any bias in the training data and performing extensive training of the models on
high-quality data​
• Avoiding manipulation of the inputs that are fed into the models​
• Ongoing evaluation and improvement of the models​
• Fine-tuning a pre-trained LLM on domain-specific data​
Preventing the problems caused by AI hallucinations​
It is inevitable for hallucinations to occur within LLMs. What can be frustrating is that the
generated text often contains subtle mistakes that are challenging to identify. There are a couple
of best practices that you can follow. These include:​
• Being vigilant and understanding that these models do not understand the actual meaning
of the words but are focused on predicting the next word in a sequence based on patterns.
These models are trained on vast amounts of data and learn statistical patterns, but they lack
semantic understanding or comprehension like human beings.​
• Ensuring human oversight regularly for fact-checking and continuous testing​
• Providing additional context in the prompt or input. This will enable LLMs to understand the
desired output better and generate more accurate and contextually relevant responses.​

1.3 Describe the key features and significance of the libraries and tools
used in generative AI for language processing.​
Overview of Libraries and Tools​
Objective(s)​
After completing this reading, you will be able to:​
Describe the key features and the significance of the libraries and tools used in generative AI for
natural language processing (NLP).​
Estimated reading time: 20 minutes​
Introduction​
As an AI engineer or NLP engineer, you will design, develop, and deploy generative AI
applications for NLP. However, you may face challenges as these applications require a deep
understanding of linguistic nuances.​
The good news is that due to the rapid advancement and evolution of generative AI for NLP, you
now have increased accessibility to various tools and libraries. The unique capabilities of these
tools and libraries enable you to explore the full potential of what you can achieve using
generative AI.​
Some key libraries and tools are PyTorch, TensorFlow, Hugging Face, LangChain, and Pydantic.​
Let's explore these libraries and tools.​
PyTorch​
PyTorch is an open source deep learning framework originally developed by Facebook's AI
Research lab (now Meta). It is a Python-based library well-known for its ease of use, flexibility,
and dynamic computation graphs. A dynamic computation graph means that the network's
structure can change on the fly during execution, allowing for more intuitive and flexible model
development. This feature is helpful in advanced NLP applications where the neural network
architecture needs to adapt dynamically to varying inputs.​
PyTorch is highly customizable and utilized in many companies such as OpenAI and Tesla.​
Let's look at the key features and the significance of PyTorch.​
Dynamic computation graphs (Autograd)​
PyTorch's Autograd system allows dynamic changes to the network during training, enhancing
flexibility and easing the development process. This adaptability is particularly beneficial for
research and experimentation.​
Rich ecosystem and community​
PyTorch has a comprehensive ecosystem, offering tools for various machine learning domains
such as computer vision and NLP. The vibrant community contributes extensive resources,
including tutorials and third-party extensions. For example, torchtext is a library within the
PyTorch ecosystem. It provides resources such as data sets and pretrained models for loading,
preprocessing, and handling text data.​
Application in NLP​
PyTorch is used to develop and train neural network models that can understand and generate
human language. It is particularly favored for research and development as it provides an
adaptable environment for model experimentation and prototyping.​
You can learn more by visiting PyTorch. (Please note: If the link does not launch the page, right-
click and open the link in a new tab.)​
TensorFlow​
TensorFlow, developed by Google, is an open-source framework for machine learning and deep
learning. It provides tools and libraries to facilitate the development and deployment of
machine learning models.​
TensorFlow stands out for its robust architecture, suitable for both research and production
environments.​
Let's look at the key features and the significance of TensorFlow.​
Scalability​
TensorFlow is designed with a scalable architecture that facilitates a seamless transition from
research prototypes to production. This feature streamlines the training process and large-scale
deployment of machine learning models.​
TensorFlow Extended (TFX)​
TFX is a platform for deploying production-ready machine learning (ML) pipelines. The platform
is built on the TensorFlow foundation. It provides functionality for integrating the various
phases of a machine learning system deployment, such as defining, launching, and monitoring.​
Keras integration​
Keras and TensorFlow are tightly integrated. Keras provides a user-friendly high-level neural
networks API, facilitating rapid prototyping and building and training deep learning models in
TensorFlow.​
Users can use TensorFlow's tf.keras module to define and train neural networks.​
Application in NLP​
You can use TensorFlow for typical NLP tasks such as sentiment analysis, text classification, and
machine translation. It contains the latest AI models and libraries to help you work with raw text.
Its capacity for handling large-scale deployments makes TensorFlow a preferred choice for
enterprise-level NLP applications.​
You can learn more by visiting TensorFlow. (Please note: If the link does not launch the page,
right-click and open the link in a new tab.)​
Hugging Face​
Hugging Face is a platform that offers an open-source library with pretrained models and tools
to streamline the process of training and fine-tuning generative AI models. Hugging Face has
significantly impacted the field of NLP, making state-of-the-art technologies more accessible.​
Let's look at the key features and the significance of Hugging Face.​
Extensive model repository
The Hugging Face Model Hub is a comprehensive online platform that hosts a vast collection of
pretrained machine learning models, primarily focusing on NLP. It allows users to easily share,
discover, and use models across a wide range of applications, including text classification,
translation, and question-answering. The Hub supports models from popular frameworks like
PyTorch and TensorFlow, allowing developers to integrate models into their existing workflows
and applications. It also provides detailed information about each model, including its
architecture, training data, and usage examples. This community-driven platform is a key
resource for researchers, developers, and AI enthusiasts, facilitating easy access and
collaboration in the field of machine learning.​
Simplicity​
The platform simplifies the deployment of complex models, making cutting-edge NLP
techniques accessible to beginners and experts. The Transformers library, a key component for
NLP, provides a user-friendly interface to work with various pretrained models.​
Community-driven development​
With a strong focus on collaboration, Hugging Face fosters a vibrant community. The community
enables a collaborative approach where developers and contributors share resources and
expertise. They participate in creating and sharing NLP models and tools, increasing
accessibility to models that you can use in a wide range of applications.​
Application in NLP​
Hugging Face is extensively used in NLP for tasks such as named entity recognition, sentiment
analysis, and text summarization. Named entity recognition involves classifying named entities
into predefined categories such as persons, locations, and so on. The readily available resources
it provides streamline building and deploying NLP applications.​
Some useful libraries in Hugging Face​
Transformers: This is perhaps the most famous library from Hugging Face. It offers many
pretrained models for working with text. Using these models, you can perform tasks such as text
generation, summarization, translation, classification, and question-answering. The library is
designed for PyTorch and TensorFlow.​
Datasets: This library is designed to easily access and share large-scale data sets and evaluation
metrics for NLP. It includes a wide array of data sets in different languages and for various tasks,
making it easier for researchers and developers to benchmark and evaluate their models.​
Tokenizers: This library is optimized for performance and versatility in tokenization, which is a
critical step in preparing data for NLP models. It can handle all pre-tokenization requirements
needed for models like BERT and GPT.​
You can learn more by visiting Hugging Face. (Please note: If the link does not launch the page,
right-click and open the link in a new tab.)​
LangChain​
LangChain is an open-source framework that helps streamline AI application development using
large language models (LLMs), significantly improving LLM accessibility and functionality for
diverse applications.​
Let's look at the key features and the significance of LangChain.​
Advanced prompt engineering​
LangChain provides sophisticated tools for designing effective prompts, unlocking the full
potential of language models. Prompts refer to specific inputs used to guide the model's
behavior.​
Prompt engineering is crucial for tailoring responses and guiding model outputs towards
desired outcomes.​
Seamless integration with leading models​
LangChain offers compatibility with major models such as generative pre-trained transformers
(GPT). This integration simplifies the development of applications built on these advanced
models, enabling a smoother transition from concept to deployment.​
Application in NLP​
LangChain is an essential tool for developers aiming to leverage LLMs. Its versatility makes it
ideal for creating tools such as interactive chatbots and intricate analytical tools.​
LangChain's ability to harmonize model integration, prompt engineering, and application-
specific customization makes it a pivotal tool in language model utilization.​
You can learn more by visiting LangChain. (Please note: If the link does not launch the page,
right-click and open the link in a new tab.)​
Pydantic​
Pydantic is a Python library that helps you streamline data handling. You can use it to parse and
validate your data. It uses Python-type annotations.​
Let's look at the key features and the significance of Pydantic.​
Robust data validation​
Pydantic ensures the accuracy of data types and formats before an application processes them.
This feature enhances the reliability of applications. In Pydantic, you can use the BaseModel
class to define data models and their validation rules.​
Efficient settings management​
Pydantic manages application settings and environment variables. This functionality is vital for
the scalability of larger projects.​
Application in NLP​
Pydantic has an important role In NLP pipelines for validating and managing data. It ensures
data integrity and consistency, especially when dealing with diverse and large data sets.​
You can learn more by visiting Pydantic. (Please note: If the link does not launch the page, right-
click and open the link in a new tab.)​
Summary​
In this reading, you learned that:​
There are various libraries and tools that you can use to develop NLP applications using
generative AI. Some tools are PyTorch, TensorFlow, Hugging Face, LangChain, and Pydantic.​
PyTorch is an open source deep learning framework. It is a Python-based library well-known for
its ease of use, flexibility, and dynamic computation graphs.​
TensorFlow is an open-source framework for machine learning and deep learning. It provides
tools and libraries to facilitate the development and deployment of machine learning models.​
The tight integration of TensorFlow with Keras provides a user-friendly high-level neural
networks API, facilitating rapid prototyping and building and training deep learning models.​
Hugging Face is a platform that offers an open-source library with pretrained models and tools
to streamline the process of training and fine-tuning generative AI models. It offers libraries such
as Transformers, Datasets, and Tokenizers.​
LangChain is an open-source framework that helps streamline AI application development using
LLMs. It provides tools for designing effective prompts.​
Pydantic is a Python library that helps you streamline data handling. It ensures the accuracy of
data types and formats before an application processes them.​

1.4 Lab: Use Hugging Face libraries in a Jupyter environment to explore


generative AI techniques and build a simple chatbot using the
Transformers library.​
2. Data Preparation​
2.1 Tokenization process, Tokenization methods, and the use of tokenizers.​
What is tocken​


Imagine you're developing an AI model for sentiment analysis on user feedback. The model
must identify and extract keywords such as good and bad. To determine sentiment, this process
requires breaking down user provided text into meaningful parts. The process of breaking a
sentence into smaller pieces, or tokens, is called tokenization. The tokens help the model
understand the text better. For a sentence like, IBM taught me tokenization, tokens can be IBM,
taught, me and tokenization. Different AI models might use different types of tokens. The
program that breaks down text into individual tokens is called a tokenizer. Tokenizers generate
tokens primarily through three tokenization methods, word based, character based, and
subword based.​

2.2 Lab: Implement tokenization.​


2.3 Explain how data loaders are used for training generative AI models.​
2.4 Lab: Create an NLP data loader.​
Summary for Module 2​
• Tokenization and data loading are part of the data preparation activities for natural language
processing (NLP).​
• Tokenization breaks a sentence into smaller pieces or tokens.​
• Tokenizers are essential tools that break down text into tokens. These tokens can be words,
characters, or subwords, making complex text understandable to computers. Examples of
tokenizers are natural language toolkit (NLTK) and spaCy.​
• Word-based tokenization preserves the semantic meaning, though it increases the model’s
overall vocabulary.​
• Character-based tokenization has smaller vocabularies but may not convey the same
information as entire words.​
• Subword-based tokenization allows frequently used words to stay unsplit while breaking
down infrequent words.​
◦ Using the WordPiece, Unigram, and SentencePiece algorithms, you can implement
subword-based tokenization.​
• You can add special tokens such as <bos> at the beginning and <eos> at the end of a
tokenized sentence.​
• A data set in PyTorch is an object that represents a collection of data samples. Each data
sample typically consists of one or more input features and their corresponding target labels.​
• A data loader helps you prepare and load data to train generative AI models. Using data
loaders, you can output data in batches instead of one sample at a time.​
• Data loaders have several key parameters, including the data set to load from, batch size
(determining how many samples per batch), shuffle (whether to shuffle the data for each
epoch), and more. Data loaders also provide an iterator interface, making it easy to iterate
over batches of data during training.​
• PyTorch has a dedicated DataLoader class.​
• Data loaders seamlessly integrate with the PyTorch training pipeline and simplify data
augmentation and preprocessing.​
• A collate function is employed in the context of data loading and batching in machine
learning, particularly when dealing with variable-length data, such as sequences (e.g., text,
time series, and sequences of events). Its primary purpose is to prepare and format
individual data samples (examples) into batches that machine learning models can
efficiently process.​
3. Fundamentals of Language Understanding​

Module 1: Fundamentals of Language Module 2: Word2Vec and Sequence-to-


Understanding​ Sequence Models​
This module is divided into two lessons. The In Module 2, you will learn about the
first lesson, Language Understanding with word2vec embedding model and its types.
Neural Networks, focuses on concepts such as You will also be introduced to sequence-to-
one-hot encoding, bag-of-words, embeddings, sequence models and how they employ
and embedding bags. You will also gain recurrent neural networks (RNNs) to process
knowledge of neural networks, their variable-length input sequences and generate
architecture and hyperparameters, cross- variable-length output sequences. You will
entropy loss, and optimization. ​ gain insights about encoder-decoder RNN
In the second lesson of this module, N-Gram models, their architecture, and how to build
Model, you will delve into the concept of them using PyTorch. The module will give you
language modeling with n-grams and how knowledge about evaluating the quality of
text using perplexity, precision, and recall in
they are used as neural networks with text generation. A reading has also been
PyTorch. The module also includes hands-on included to advance your learning on NLP-
labs on document classification with PyTorch specific metrics.​
and building a simple language model with a You will integrate pre-trained embedding
neural network.​ models for text analysis or classification and
develop a sequence-to-sequence model for
sequence transformation tasks.​
3.1 Language understanding with Neural Networks​

3.2 N-Gram Model​

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy