Skip to content
ImagineWorld

Fundamentals of Generative AI

node_idnode-book_building-agentic-ai-systems_chapter-01-fundamentals-of-generative-ai
node_typechapter-node
schema_profileworld.chapter_node.v1
statusactive
entropyhigh
manifoldworld
domainimagineworld.net
authorityinforms
layercorpus
chapter_num1
chapter_titleFundamentals of Generative AI
governed_byCORPUS
constitutional_citationCONSTITUTION
local graph

Chapter 1 — Fundamentals of Generative AI

Section titled “Chapter 1 — Fundamentals of Generative AI”

Generative AI has quickly become a transformative technology in the field of artificial intelligence (AI) and machine learning, revolutionizing creative processes and problem-solving across diverse industries and use cases. It is pushing the boundaries of autonomy in agent-based intelligent systems. In this chapter, we will cover the basics of generative AI. We will explore what generative AI is along with a brief history of generative AI models. We will then discuss the different types of generative models, which include variational autoencoders (VAEs), generative adversarial networks (GANs), autoregressive, and Transformer models. Next, we will delve into the applications of generative AI and wrap up the chapter with a brief discussion of some of the limitations and challenges related to generative AI.

We will cover the following topics in this introductory chapter that will help set the foundations of generative AI as we explore further the capabilities of autonomous intelligent agents powered by generative AI:

  • Introduction to generative AI
  • Types of generative AI models
  • Applications of generative AI
  • Challenges and limitations of generative AI

By the end of this chapter, you will have gained a comprehensive understanding of generative AI, including its fundamental concepts, diverse applications, and current challenges. You will also learn about the technology’s potential and limitations, with a particular focus on its critical role in advancing intelligent agents and agentic systems.

Generative AI refers to a class of AI technologies that is capable of generating various forms of content, including but not limited to text, images, audio, and video. These AI systems can generate new content, based on their training data and input parameters, which usually include text prompts but can also involve other forms of input such as images. The recent buzz around generative AI comes from the simplicity with which new user interfaces powered by this AI technology can create high-quality text, graphics, and videos in seconds.

In very simple terms, generative AI is about making new data that looks like the data from which it has been trained. In other words, learning the underlying patterns, structures, and distributions of input data enables a procedure within the model allowing it to generate new data in a similar way. For instance, if trained on a dataset of human faces, a generative AI model will be able to create completely new faces of people that don’t actually exist in real life but are very realistic. In essence, generative AI models work by learning the probability distribution of a dataset and then sampling from that distribution to create new instances. This approach is different from discriminative models, whose goal is to learn how to tell classes of data apart. For example, a discriminative model could be trained to separate pictures of cats and dogs, but a generative model would be trained to make up completely new pictures of cats or dogs.

The concept of generative AI goes a long way back; in fact, it dates back to the time when machine learning was in its cradle. However, it is only recently that this field has come under the limelight due to neural networks and drastic improvements in computing power over the last 10 years. In the early attempts at generative modeling—Gaussian mixture models and hidden Markov models—many simpler statistical techniques were involved. Methods of modeling arbitrary complex data distributions have much higher potential compatibility with the kinds of methods that were previously dominant but have recently been overcome by deep learning. Deep learning was therefore a watershed development for the field of generative AI. Models, such as VAEs, which started appearing around the beginning of the 2010s, were able to leverage deep neural networks to model more complex data distributions. Around that same period, GANs were proposed; for the first time, they offered a new way for two neural networks to work together to create data, using principles from game theory. In a general sense, these breakthroughs took leaps toward the possibilities of making real, high-quality, realistic creation of data.

This can lead to innovation in most fields across industries, such as healthcare, finance, education, travel and hospitality, manufacturing, and more. Generative AI in creative industries helps artists and designers think outside the box, helping with the conception of new and innovative content. It opens ways for new routes of drug discovery and personalized medicine in health. In the business world, generative AI works by providing efficient and effective customer engagement through personalized content and experiences. The other point involves questioning one’s own stance regarding creativity and originality: when machines are able to pump out very similar material, one is automatically forced to think about what creativity is, who the artist really is, and what the ethical parameters should be for AI-created content.

Having understood what generative AI is and its brief history, let’s explore the different types of generative AI models.

Generative AI is an exciting domain of AI that deals with the generation of new, synthetic data by learning patterns from existing datasets, aiming to generate outputs that share similar statistical properties and characteristics with the training data. Here is a broad overview of some of the most prominent types of generative models: VAEs, GANs, and autoregressive models.

One of the most popular generative models is the VAE. The core idea behind VAE consists of learning a probabilistic mapping between data and a latent space, and vice versa. This means learning how to convert real data into a simplified representation (such as a compressed form) and then back again into data that looks real. VAEs are designed to ensure a high likelihood of the data while preserving a well-structured latent space to enable the generation of new data samples similar to the training data. Some of the most common flavors of VAE are as follows:

  • VAE: The basic model that compresses and reconstructs data. It gives a framework for generating new samples out of the learned latent space. The VAE is a generative model that learns to compress and reconstruct data while also learning a probability distribution of the latent space. In simpler terms, a VAE is like a clever algorithm that learns to understand and recreate data. Imagine it as a skilled artist who can compress a detailed painting into a simple sketch (encoding) and then recreate the full painting from that sketch (decoding). What makes VAEs special is that they don’t just copy data but also learn the essence of it, allowing them to create new, similar data. This is like an artist learning not just to copy specific paintings but also to understand the style so well that they can paint new, original works in that style. In real life, VAEs have been used in many creative ways. For instance, in drug discovery, VAEs have been used to generate novel molecular structures. Researchers at AstraZeneca used VAEs to explore chemical space and propose new drug-like molecules with desired properties, potentially accelerating the drug development process [1].
  • Beta-VAE: An extension of VAE that introduces a hyperparameter to control explicitly the trade-off between the reconstruction quality and the disentanglement of the latent space. The model undertakes the creation of more interpretable disentangled representations. In simpler terms, Beta-VAE is like a more flexible version of the original VAE. It allows researchers to adjust how much the model focuses on recreating exact details versus understanding the underlying features of the data. This is similar to teaching an art student to not just copy a painting but also to understand and separate the key elements such as color, shape, and style. This ability to disentangle features makes Beta-VAE particularly useful in fields such as computer vision and robotics. For example, researchers have used Beta-VAE to teach robots to understand objects better. By learning to separate features such as size, color, and position, robots can more easily recognize and manipulate objects in different situations, making them more adaptable and efficient in various tasks [2].
  • Conditional variational autoencoder (CVAE): A variant that conditions the generation process on some extra information, typically class labels, producing not just data similar to the training set but also samples that can then be drawn from specific classes. Think of CVAE as a more controlled version of VAE, like an artist who can paint in different styles on demand. Instead of just creating random new paintings, this artist can be told to “ Paint a landscape ” or “ Paint a portrait ” and they’ll create new art in that specific category. This added control makes CVAE very useful in practical applications. For instance, in the field of computer games, CVAE has been used for game development and procedural content generation with the generation of game elements such as character design, level layouts, music and sound effects, and so on. By providing different conditions such as “ Create a forest level ” or “ Create a desert level,” the CVAE can produce a wide variety of game environments, saving time for designers and enhancing the player’s experience with more diverse and interesting game worlds [3].

A GAN is basically formed by two neural networks: a generator and a discriminator. The generator generates synthetic data samples; the other trained neural network should then be able to tell the difference between real and created samples. While training these networks, they are trained together antagonistically: the generator tries to fool the discriminator, while the discriminator tries rightly to classify real versus fake data. In this competition, the generator gets better and better at faking data. The following are some of the different types of GANs:

  • GAN: The basic model in which the generator and discriminator are trained adversarially; it is the root model for most innovations in generative modeling. As explained earlier, you can imagine GAN as a game between two players—a counterfeiter (generator) trying to create fake money, and a detective (discriminator) trying to identify the fakes. As they compete, they both get better at their jobs, which means that the counterfeiter gets increasingly better at creating fake money. This clever setup allows GANs to create incredibly realistic fake data, such as images or sounds [4].
  • Deep convolutional GAN (DCGAN): This is a refinement of the base GAN model with deep convolutional neural networks; at the moment, it is one of the best architectures for generating images of high quality. Think of DCGAN as a more sophisticated artist compared to the basic GAN. It’s like upgrading from simple sketching tools to a full digital art studio, allowing for the creation of much more detailed and realistic images. DCGANs are particularly good at understanding and recreating complex patterns in images [5].
  • Wasserstein GAN (WGAN): This proposes a different loss function with the Wasserstein distance. This removes problems while training with a GAN, hence making training more stable and improving sample quality. This helps measure the distance between two probability distributions better. WGAN is like giving the artist (generator) and critic (discriminator) in a GAN a better way to communicate and evaluate each other’s work. Instead of just saying “ good ” or “ bad,” they can now give more nuanced feedback, such as “ You’re getting warmer ” or “ You’re way off.” This leads to more consistent improvement and high-quality results. In practical applications, WGANs have been used in medical imaging to generate synthetic medical images for training purposes. This helps in creating larger, more diverse datasets for training diagnostic AI systems, potentially improving their accuracy in detecting diseases from scans and X-rays [6].
  • StyleGAN: This generates high-quality realistic images. The model is especially good at handling style and content separately. Progressions offered by the introductions of StyleGAN2 and StyleGAN3 are still aimed at improving image fidelity and realism. Think of StyleGAN as an advanced digital artist that can not only create realistic images but also mix and match different styles and contents. It’s like having a painter who can take the style of Van Gogh and apply it to a modern cityscape. This flexibility makes StyleGAN incredibly versatile [7].

Autoregressive models and Transformer architecture

Section titled “Autoregressive models and Transformer architecture”

Autoregressive models generate their data points one at a time, conditioning each of its data points on the previous one. Surprisingly, this ultimately proves very useful in tasks in which the sequence or structure of data is relevant, such as text generation and image generation. The Transformer architecture, introduced in the Attention Is All You Need paper [8], is a model architecture that has revolutionized many sequential data tasks, especially in natural language processing (NLP). Its key components are demonstrated in Figure 1*.1*:

Figure 1.1 – The Transformer architecture

Figure 1.1 – The Transformer architecture

These key components include the following:

  • Self-attention m echanism: A computational technique that allows the model to dynamically focus on different parts of the input when processing each element
  • Multi-head attention: Multiple attention mechanisms running in parallel, allowing the model to focus on different aspects of the input simultaneously
  • Positional encoding: Adds information about the position of each element in the sequence
  • Feed-forward neural networks: Process the output of the attention layers
  • Layer normalization and residual connections: Enhance training stability and information flow

Transformers can be used in both autoregressive and non-autoregressive configurations, making them versatile for various tasks. The following are some examples:

  • PixelCNN: Autoregressively generates images pixel by pixel, conditioning each pixel on the previously generated ones. This model works very well in generating high-quality images with fine details [9].
  • PixelSNAIL: A refinement over PixelCNN that adds attention mechanisms into the model to capture strong dependencies between pixels, and hence, a better quality of an image [10].
  • GPT: Standing for Generative Pre-trained Transformer, it is a line of models specializing in text generation—namely, predicting which words should come next. Among them are GPT-2, GPT-3, and GPT-4, making a huge leap in generating coherent and contextually relevant text [11] [12].
  • BERT: Unlike GPT, BERT, which stands for Bidirectional Encoder Representations from Transformers, is designed to understand the context from both directions in text. It uses the encoder part of the Transformer and is typically used for tasks that require an understanding of the entire input at once, rather than generating text autoregressively [13].
  • Text-To-Text Transfer Transformer (T5): This model frames all NLP tasks in a text-to-text format. It uses the full Transformer architecture (both encoder and decoder) and can handle various text generation tasks [14].

Although it depends on the task, these models demonstrate how the Transformer architecture can be adapted for both autoregressive (such as GPT) and non-autoregressive (such as BERT) tasks, showcasing its versatility in handling sequential data. Strengths differ across generative models. This class of models goes from generating photorealistic images to coherent text to totally new data samples.

Building upon the success of models such as GPT, researchers have scaled up these architectures to create large language models (LLMs). These models, often trained on vast amounts of open web text and other freely available text data, have demonstrated exceptional proficiency in understanding and generating human-like text across diverse applications, showcasing their versatility and advanced linguistic abilities. Examples of LLMs include GPT-3, GPT-4, PaLM, and BERT-large. These models have pushed the boundaries of what’s possible in NLP, showing proficiency in tasks ranging from question-answering and summarization to creative writing and code generation. The following is an overview of the common types of LLMs:

  • Autoregressive LLMs: These language models are typically capable of generating text sequentially, that is, one token at a time. Some of the common tasks that these types of models are used for include text generation, text completion tasks, and creative writing. Some popular examples of autoregressive LLMs are the GPT series (GPT-3, GPT-4), and PaLM.
  • Encoder-only LLMs: These models specialize in natural language understanding (NLU) tasks, which involve analyzing and comprehending input text without generating new text. Encoder-only LLMs, such as BERT and its variants including RoBERTa, focus on understanding the context and meaning of input text. These models process the entire input sequence simultaneously, allowing them to capture the context helping with tasks such as text classification, named entity recognition (NER), and sentiment analysis.
  • Encoder-decoder LLMs: This is a combination of encoder and decoder architecture where the models can not only understand the context of the input text (NLU) but are also capable of generating textual output. The T5 model discussed earlier is a very popular example of an encoder-decoder LLM, along with models such as BERT. These models are capable of language translation, summarization, and question-answering.
  • Multimodal LLMs: Multimodality is a concept where an AI model can not only handle text but also other modalities such as image, video, and audio. Multimodal LLMs can process and generate content in various modalities such as text, image, audio, video, and any combination thereof. These models are rather novel in nature and recent advancements in compute have made it possible to train multimodal LLMs. Some of the well-known multimodal LLMs are DALL-E, Stable Diffusion, Flamingo, GPT-4, and LlaVa.
  • Instruction-tuned LLMs: LLMs are often trained on a large corpus of openly available web or other text. As such, in certain scenarios, these models may not perform effectively for tasks that use data that the model has never seen before and thus may fail to follow the user intent. For example, a manufacturing manual for a proprietary instrument may contain domain-specific proprietary language, which the model may not have been exposed to during training. In such cases, LLMs can be fine-tuned using the domain-specific data to follow specific instructions and prompts (that is, text input to the model). This special fine-tuning enables the model to perform domain-specific tasks on which the model was fine-tuned, in addition to its other capabilities. Think of this as localizing a personal copy of a model to be good at performing a task that is meaningful for your use case. One of the common examples of such a model is InstructGPT, where researchers fine-tuned the GPT-3 model on specific instructions. These types of models are used in a multitude of different tasks such as chatbots, virtual assistants, and task-specific applications.
  • Domain-specific LLMs: As mentioned earlier, while LLMs are often trained on a large set of open, generally available, web data, they may not perform very well in domain-specific environments. While instruction-tuned LLMs are an avenue to make these general-purpose models work for domain-specific tasks, researchers have innovated on training domain-specific LLMs from the ground up. This means that these models were pre-trained on highly specialized, domain knowledge. For example, the BioBERT model is trained on hyper-specialized medical data, whereas LegalBERT is trained on legal documents. These models are useful for specialized tasks in specific fields such as medicine, law, and finance.

Each of the previously discussed LLM types has its own strengths and weaknesses and is well-suited for different applications. However, our focus in this book would be to dive deeper into LLM agent capabilities and explore how advanced systems can be built utilizing them. It is important to note that LLM agents do not fit neatly into a single category, as they represent an advanced application of LLM technology rather than a specific type of model architecture. Agents are typically built using instruction-tuned LLMs as their foundation, often combined with additional components and capabilities as you will learn further in this book.

Let us take a look at a simple example to demonstrate the capabilities of an agentic system powered by an LLM. Our example is a travel website that has a Flight Booking Assistant chatbot that is a conversational interface built with an LLM. It can help customers book travel tickets via human-like conversations. In the backend, the chatbot can perform various tasks as the conversation progresses. Here’s what a sample conversation may look like for a customer who is looking to book a flight ticket: