Modern Generative AI with ChatGPT and OpenAI Models - Valentina Alto - E-Book

Modern Generative AI with ChatGPT and OpenAI Models E-Book

Valentina Alto

0,0
35,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Generative AI models and AI language models are becoming increasingly popular due to their unparalleled capabilities. This book will provide you with insights into the inner workings of the LLMs and guide you through creating your own language models. You’ll start with an introduction to the field of generative AI, helping you understand how these models are trained to generate new data.
Next, you’ll explore use cases where ChatGPT can boost productivity and enhance creativity. You’ll learn how to get the best from your ChatGPT interactions by improving your prompt design and leveraging zero, one, and few-shots learning capabilities. The use cases are divided into clusters of marketers, researchers, and developers, which will help you apply what you learn in this book to your own challenges faster.
You’ll also discover enterprise-level scenarios that leverage OpenAI models’ APIs available on Azure infrastructure; both generative models like GPT-3 and embedding models like Ada. For each scenario, you’ll find an end-to-end implementation with Python, using Streamlit as the frontend and the LangChain SDK to facilitate models' integration into your applications.
By the end of this book, you’ll be well equipped to use the generative AI field and start using ChatGPT and OpenAI models’ APIs in your own projects.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB

Seitenzahl: 243

Veröffentlichungsjahr: 2023

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Modern Generative AI with ChatGPT and OpenAI Models

Leverage the capabilities of OpenAI's LLM for productivity and innovation with GPT3 and GPT4

Valentina Alto

BIRMINGHAM—MUMBAI

Modern Generative AI with ChatGPT and OpenAI Models

Copyright © 2023 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

Associate Group Product Manager: Ali Abidi

Associate Publishing Product Manager: Dinesh Choudhary

Senior Editor: Tiksha Lad

Technical Editor: Rahul Limbachiya

Copy Editor: Safis Editing

Associate Project Manager: Hemangi Lotlikar

Proofreader: Safis Editing

Indexer: Pratik Shirodkar

Production Designer: Aparna Bhagat

Marketing Coordinators: Shifa Ansari and Vinishka Kalra

First published: May 2023

Production reference: 1230523

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham

B3 2PB, UK.

ISBN 978-1-80512-333-0

www.packtpub.com

Contributors

About the author

Valentina Alto graduated in 2021 in data science. Since 2020, she has been working at Microsoft as an Azure solution specialist, and since 2022, she has been focusing on data and AI workloads within the manufacturing and pharmaceutical industry. She has been working closely with system integrators on customer projects to deploy cloud architecture with a focus on modern data platforms, data mesh frameworks, IoT and real-time analytics, Azure Machine Learning, Azure Cognitive Services (including Azure OpenAI Service), and Power BI for dashboarding. Since commencing her academic journey, she has been writing tech articles on statistics, machine learning, deep learning, and AI in various publications and has authored a book on the fundamentals of machine learning with Python. 

I want to thank my parents, friends, and colleagues who have been close to me and supported me in this amazing journey. Thank you to those at Packt – the editor, the manager, and the whole team – who supported me.

About the reviewer

Supreet Kaur is an accomplished AI product manager at Morgan Stanley, where she serves as the product owner for various AI products and spearheads the development of innovative data-driven solutions. Prior to this, she worked as a technology and data science consultant, delivering impactful data science use cases and launch strategies for pharmaceutical clients.

She is also a prolific writer and speaker on data science and AI topics, having delivered over 50 talks at international and national forums. As a strong advocate for women in technology, Supreet was selected as a Google WomenTech Makers Ambassador and has been recognized as one of the top 25 women in AI in Finance.

Table of Contents

Preface

Part 1: Fundamentals of Generative AI and GPT Models

1

Introduction to Generative AI

Introducing generative AI

Domains of generative AI

Text generation

Image generation

Music generation

Video generation

The history and current status of research

Summary

References

2

OpenAI and ChatGPT – Beyond the Market Hype

Technical requirements

What is OpenAI?

An overview of OpenAI model families

Road to ChatGPT: the math of the model behind it

The structure of RNNs

The main limitations of RNNs

Overcoming limitations – introducing transformers

GPT-3

ChatGPT: the state of the art

Summary

References

Part 2: ChatGPT in Action

3

Getting Familiar with ChatGPT

Setting up a ChatGPT account

Familiarizing yourself with the UI

Organizing chats

Summary

References

4

Understanding Prompt Design

What is a prompt and why is it important?

Zero-, one-, and few-shot learning – typical of transformers models

Principles of well-defined prompts to obtain relevant and consistent results

Avoiding the risk of hidden bias and taking into account ethical considerations in ChatGPT

Summary

References

5

Boosting Day-to-Day Productivity with ChatGPT

Technical requirements

ChatGPT as a daily assistant

Generating text

Improving writing skills and translation

Quick information retrieval and competitive intelligence

Summary

6

Developing the Future with ChatGPT

Why ChatGPT for developers?

Generating, optimizing, and debugging code

Generating documentation and code explainability

Understanding ML model interpretability

Translation among different programming languages

Summary

7

Mastering Marketing with ChatGPT

Technical requirements

Marketers’ need for ChatGPT

New product development and the go-to-market strategy

A/B testing for marketing comparison

Boosting Search Engine Optimization (SEO)

Sentiment analysis to improve quality and increase customer satisfaction

Summary

8

Research Reinvented with ChatGPT

Researchers’ need for ChatGPT

Brainstorming literature for your study

Providing support for the design and framework of your experiment

Generating and formatting a bibliography

Generating a presentation of the study

Summary

References

Part 3: OpenAI for Enterprises

9

OpenAI and ChatGPT for Enterprises – Introducing Azure OpenAI

Technical requirements

OpenAI and Microsoft for enterprise-level AI – introducing Azure OpenAI

Microsoft AI background

Azure OpenAI Service

Exploring Playground

Why introduce a public cloud?

Understanding responsible AI

Microsoft’s journey toward responsible AI

Azure OpenAI and responsible AI

Summary

References

10

Trending Use Cases for Enterprises

Technical requirements

How Azure OpenAI is being used in enterprises

Contract analyzer and generator

Identifying key clauses

Analyzing language

Flagging potential issues

Providing contract templates

Frontend with Streamlit

Understanding call center analytics

Parameter extraction

Sentiment analysis

Classification of customers’ requests

Implementing the frontend with Streamlit

Exploring semantic search

Document embedding using LangChain modules

Creating a frontend for Streamlit

Summary

References

11

Epilogue and Final Thoughts

Recap of what we have learned so far

This is just the beginning

The advent of multimodal large language models

Microsoft Bing and the Copilot system

The impact of generative technologies on industries – a disruptive force

Unveiling concerns about Generative AI

Elon Musk calls for stopping development

ChatGPT was banned in Italy by the Italian “Garante della Privacy”

Ethical implications of Generative AI and why we need Responsible AI

What to expect in the near future

Summary

References

Index

Other Books You May Enjoy

Part 1: Fundamentals of Generative AI and GPT Models

In Part 1 of this book, the fundamentals of Generative AI and GPT models are introduced, including a brief history of the development of OpenAI and its flagship set of models, the GPT family.

This part starts with an overview of the domain of generative AI, providing you with foundation knowledge about this area of research of AI, including its history and state-of-the-art developments. You will also get familiar with the applications of generative AI, ranging from text generation to music composition.

Part 1 then introduces the company that brought the power of generative AI to the general public: OpenAI. You will get familiar with the technology behind OpenAI’s most popular release – ChatGPT – and understand the research journey that, starting from Artificial Neural Networks (ANNs), led to Large Language Models (LLMs).

This part has the following chapters:

Chapter 1, Introduction to Generative AIChapter 2, OpenAI and ChatGPT Beyond the Market Hype

1

Introduction to Generative AI

Hello! Welcome to Modern Generative AI with ChatGPT and OpenAI Models! In this book, we will explore the fascinating world of generative Artificial Intelligence (AI) and its groundbreaking applications. Generative AI has transformed the way we interact with machines, enabling computers to create, predict, and learn without explicit human instruction. With ChatGPT and OpenAI, we have witnessed unprecedented advances in natural language processing, image and video synthesis, and many other fields. Whether you are a curious beginner or an experienced practitioner, this guide will equip you with the knowledge and skills to navigate the exciting landscape of generative AI. So, let’s dive in and start with some definitions of the context we are moving in.

This chapter provides an overview of the field of generative AI, which consists of creating new and unique data or content using machine learning (ML) algorithms.

It focuses on the applications of generative AI to various fields, such as image synthesis, text generation, and music composition, highlighting the potential of generative AI to revolutionize various industries. This introduction to generative AI will provide context for where this technology lives, as well as the knowledge to collocate it within the wide world of AI, ML, and Deep Learning (DL). Then, we will dwell on the main areas of applications of generative AI with concrete examples and recent developments so that you can get familiar with the impact it may have on businesses and society in general.

Also, being aware of the research journey toward the current state of the art of generative AI will give you a better understanding of the foundations of recent developments and state-of-the-art models.

All this, we will cover with the following topics:

Understanding generative AIExploring the domains of generative AIThe history and current status of research on generative AI

By the end of this chapter, you will be familiar with the exciting world of generative AI, its applications, the research history behind it, and the current developments, which could have – and are currently having – a disruptive impact on businesses.

Introducing generative AI

AI has been making significant strides in recent years, and one of the areas that has seen considerable growth is generative AI. Generative AI is a subfield of AI and DL that focuses on generating new content, such as images, text, music, and video, by using algorithms and models that have been trained on existing data using ML techniques.

In order to better understand the relationship between AI, ML, DL, and generative AI, consider AI as the foundation, while ML, DL, and generative AI represent increasingly specialized and focused areas of study and application:

AI represents the broad field of creating systems that can perform tasks, showing human intelligence and ability and being able to interact with the ecosystem.ML is a branch that focuses on creating algorithms and models that enable those systems to learn and improve themselves with time and training. ML models learn from existing data and automatically update their parameters as they grow.DL is a sub-branch of ML, in the sense that it encompasses deep ML models. Those deep models are called neural networks and are particularly suitable in domains such as computer vision or Natural Language Processing (NLP). When we talk about ML and DL models, we typically refer to discriminative models, whose aim is that of making predictions or inferencing patterns on top of data.And finally, we get to generative AI, a further sub-branch of DL, which doesn’t use deep Neural Networks to cluster, classify, or make predictions on existing data: it uses those powerful Neural Network models to generate brand new content, from images to natural language, from music to video.

The following figure shows how these areas of research are related to each other:

Figure 1.1 – Relationship between AI, ML, DL, and generative AI

Generative AI models can be trained on vast amounts of data and then they can generate new examples from scratch using patterns in that data. This generative process is different from discriminative models, which are trained to predict the class or label of a given example.

Domains of generative AI

In recent years, generative AI has made significant advancements and has expanded its applications to a wide range of domains, such as art, music, fashion, architecture, and many more. In some of them, it is indeed transforming the way we create, design, and understand the world around us. In others, it is improving and making existing processes and operations more efficient.

The fact that generative AI is used in many domains also implies that its models can deal with different kinds of data, from natural language to audio or images. Let us understand how generative AI models address different types of data and domains.

Text generation

One of the greatest applications of generative AI—and the one we are going to cover the most throughout this book—is its capability to produce new content in natural language. Indeed, generative AI algorithms can be used to generate new text, such as articles, poetry, and product descriptions.

For example, a language model such as GPT-3, developed by OpenAI, can be trained on large amounts of text data and then used to generate new, coherent, and grammatically correct text in different languages (both in terms of input and output), as well as extracting relevant features from text such as keywords, topics, or full summaries.

Here is an example of working with GPT-3:

Figure 1.2 – Example of ChatGPT responding to a user prompt, also adding references

Next, we will move on to image generation.

Image generation

One of the earliest and most well-known examples of generative AI in image synthesis is the Generative Adversarial Network (GAN) architecture introduced in the 2014 paper by I. Goodfellow et al., Generative Adversarial Networks. The purpose of GANs is to generate realistic images that are indistinguishable from real images. This capability had several interesting business applications, such as generating synthetic datasets for training computer vision models, generating realistic product images, and generating realistic images for virtual reality and augmented reality applications.

Here is an example of faces of people who do not exist since they are entirely generated by AI:

Figure 1.3 – Imaginary faces generated by GAN StyleGAN2 at https://this-person-does-not-exist.com/en

Then, in 2021, a new generative AI model was introduced in this field by OpenAI, DALL-E. Different from GANs, the DALL-E model is designed to generate images from descriptions in natural language (GANs take a random noise vector as input) and can generate a wide range of images, which may not look realistic but still depict the desired concepts.

DALL-E has great potential in creative industries such as advertising, product design, and fashion, among others, to create unique and creative images.

Here, you can see an example of DALL-E generating four images starting from a request in natural language:

Figure 1.4 – Images generated by DALL-E with a natural language prompt as input

Note that text and image generation can be combined to produce brand new materials. In recent years, widespread new AI tools have used this combination.

An example is Tome AI, a generative storytelling format that, among its capabilities, is also able to create slide shows from scratch, leveraging models such as DALL-E and GPT-3.

Figure 1.5 – A presentation about generative AI entirely generated by Tome, using an input in natural language

As you can see, the preceding AI tool was perfectly able to create a draft presentation just based on my short input in natural language.

Music generation

The first approaches to generative AI for music generation trace back to the 50s, with research in the field of algorithmic composition, a technique that uses algorithms to generate musical compositions. In fact, in 1957, Lejaren Hiller and Leonard Isaacson created the Illiac Suite for String Quartet (https://www.youtube.com/watch?v=n0njBFLQSk8), the first piece of music entirely composed by AI. Since then, the field of generative AI for music has been the subject of ongoing research for several decades. Among recent years’ developments, new architectures and frameworks have become widespread among the general public, such as the WaveNet architecture introduced by Google in 2016, which has been able to generate high-quality audio samples, or the Magenta project, also developed by Google, which uses Recurrent Neural Networks (RNNs) and other ML techniques to generate music and other forms of art. Then, in 2020, OpenAI also announced Jukebox, a neural network that generates music, with the possibility to customize the output in terms of musical and vocal style, genre, reference artist, and so on.

Those and other frameworks became the foundations of many AI composer assistants for music generation. An example is Flow Machines, developed by Sony CSL Research. This generative AI system was trained on a large database of musical pieces to create new music in a variety of styles. It was used by French composer Benoît Carré to compose an album called Hello World (https://www.helloworldalbum.net/), which features collaborations with several human musicians.

Here, you can see an example of a track generated entirely by Music Transformer, one of the models within the Magenta project:

Figure 1.6 – Music Transformer allows users to listen to musical performances generated by AI

Another incredible application of generative AI within the music domain is speech synthesis. It is indeed possible to find many AI tools that can create audio based on text inputs in the voices of well-known singers.

For example, if you have always wondered how your songs would sound if Kanye West performed them, well, you can now fulfill your dreams with tools such as FakeYou.com (https://fakeyou.com/), Deep Fake Text to Speech, or UberDuck.ai(https://uberduck.ai/).

Figure 1.7 – Text-to-speech synthesis with UberDuck.ai

I have to say, the result is really impressive. If you want to have fun, you can also try voices from your all your favorite cartoons as well, such as Winnie The Pooh...

Next, we move to see generative AI for videos.

Video generation

Generative AI for video generation shares a similar timeline of development with image generation. In fact, one of the key developments in the field of video generation has been the development of GANs. Thanks to their accuracy in producing realistic images, researchers have started to apply these techniques to video generation as well. One of the most notable examples of GAN-based video generation is DeepMind’s Motion to Video, which generated high-quality videos from a single image and a sequence of motions. Another great example is NVIDIA’s Video-to-Video Synthesis (Vid2Vid) DL-based framework, which uses GANs to synthesize high-quality videos from input videos.

The Vid2Vid system can generate temporally consistent videos, meaning that they maintain smooth and realistic motion over time. The technology can be used to perform a variety of video synthesis tasks, such as the following: