100% found this document useful (1 vote)
159 views130 pages

Maximizing Productivity With Chatgpt

Uploaded by

bsxfile
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
100% found this document useful (1 vote)
159 views130 pages

Maximizing Productivity With Chatgpt

Uploaded by

bsxfile
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/ 130

i

Disclaimer
The information contained within this eBook is strictly for educational purposes. If you wish to
apply ideas contained in this eBook, you are taking full responsibility for your actions.
The author has made every effort to ensure the accuracy of the information within this book was
correct at time of publication. The author does not assume and hereby disclaims any liability to any
party for any loss, damage, or disruption caused by errors or omissions, whether such errors or
omissions result from accident, negligence, or any other cause.
No part of this eBook may be reproduced or transmitted in any form or by any means, electronic or
mechanical, recording or by any information storage and retrieval system, without written
permission from the author.

Credits
Founder: Jason Brownlee
Author: Abid Ali Awan, Matthew Mayo, Kanwal Mehreen, Adrian Tam
Technical Reviewers: Vinod Chugani, Ethan Li, Devansh Sethi

Copyright
Maximizing Productivity with ChatGPT
© 2023 MachineLearningMastery.com. All Rights Reserved.

Edition: v1.02
Contents

Preface vi

Introduction viii

I The Magic Behind ChatGPT 1


1 What are Large Language Models 2
From Transformer Model to Large Language Model . . . . . . . . . . . . . . 2
Why Transformer Can Predict Text? . . . . . . . . . . . . . . . . . . . . 5
How a Large Language Model Is Built? . . . . . . . . . . . . . . . . . . . 5
Further Readings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 Get a Taste of LLMs from GPT4All 7


What is GPT4All? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
How to get GPT4All . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
How to use GPT4All in Python . . . . . . . . . . . . . . . . . . . . . . 10
Further Readings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

3 What Are Zero-Shot Prompting and Few-Shot Prompting 14


How Do Large Language Models Generate Output? . . . . . . . . . . . . . . 14
Zero-Shot Prompting . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Few-Shot Prompting . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

4 A Gentle Introduction to Prompt Engineering 18


Understanding ChatGPT . . . . . . . . . . . . . . . . . . . . . . . . . 18
Engineering the Context . . . . . . . . . . . . . . . . . . . . . . . . . 19
Advises for Prompt Engineering . . . . . . . . . . . . . . . . . . . . . . 20
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
iii

5 A Gentle Introduction to Hallucinations in Large Language Models 22


What are Hallucinations in Large Language Models. . . . . . . . . . . . . . 22
Using Hallucinations . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Mitigating Hallucinations . . . . . . . . . . . . . . . . . . . . . . . . . 23
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

II Work Productively with ChatGPT 25


6 Prompt Engineering for Effective Interaction with ChatGPT 26
Principles of Prompting . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Basic Prompt Engineering . . . . . . . . . . . . . . . . . . . . . . . . . 27
Advanced Prompt Engineering Strategies . . . . . . . . . . . . . . . . . . 29
Collaborative Power Tips . . . . . . . . . . . . . . . . . . . . . . . . . 32
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

7 Strategies for Effective Brainstorming with ChatGPT 34


Plan a Detail EuroTrip . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Plan a Dinner for a Family . . . . . . . . . . . . . . . . . . . . . . . . 37
Tips on Maximizing ChatGPT’s Brainstorming Capabilities . . . . . . . . . . 38
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

8 ChatGPT as Your Expert Helper 40


Accelerating Machine Learning Models with TPUs . . . . . . . . . . . . . . 40
A Guide to Safely Cutting Down a Tree . . . . . . . . . . . . . . . . . . . 42
Tips on Writing Expert Helper Prompts. . . . . . . . . . . . . . . . . . . 44
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

9 Writing an Essay with ChatGPT 45


Topic of the Essay . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Straightforward Instruction . . . . . . . . . . . . . . . . . . . . . . . . 46
Guiding ChatGPT to Write Step-by-Step . . . . . . . . . . . . . . . . . . 47
How It Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

10 Using ChatGPT as Your Personalized Teacher 53


Mastering Linear Algebra in 12 Weeks . . . . . . . . . . . . . . . . . . . 53
Self-Quizzing for a Machine Learning Interview. . . . . . . . . . . . . . . . 56
Prompting Tips to Enhance Learning Experience . . . . . . . . . . . . . . . 59
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

11 Using ChatGPT for Translation Effectively 61


Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Language Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Code Translation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Tips on Effective Translation . . . . . . . . . . . . . . . . . . . . . . . 65
Further Readings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
iv

Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66

12 Mastering Summarization with ChatGPT 67


Summarizing Market Research Reports . . . . . . . . . . . . . . . . . . . 67
Analyzing User Feedback Surveys . . . . . . . . . . . . . . . . . . . . . 69
Tips for Effective Summarization with ChatGPT . . . . . . . . . . . . . . . 72
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

13 Advanced Techniques for Research with ChatGPT 73


Analyzing and Interpreting Research Data . . . . . . . . . . . . . . . . . . 73
Performing Literature Review & Identifying Research Gaps . . . . . . . . . . 76
Bonus Prompts for Researchers . . . . . . . . . . . . . . . . . . . . . . 79
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80

14 Using the Natural Language Understanding Capability of ChatGPT 81


Your AI Secretary . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Extracting unstructured information . . . . . . . . . . . . . . . . . . . . 84
How to Use ChatGPT for NLU . . . . . . . . . . . . . . . . . . . . . . 86
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

15 Using ChatGPT as Your Programming Assistant 87


Start a Programming Project . . . . . . . . . . . . . . . . . . . . . . . 87
Understanding Code and Generating Function Snippets . . . . . . . . . . . . 92
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

16 Generating Diagrams with ChatGPT 98


Building a System Design Block Diagram . . . . . . . . . . . . . . . . . . 98
Building a Sequence Diagram . . . . . . . . . . . . . . . . . . . . . . . 101
Limitations and Tips for Graphics Generation . . . . . . . . . . . . . . . . 103
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103

17 Creating a PowerPoint Presentation using ChatGPT 104


Outline of a Pitching Deck . . . . . . . . . . . . . . . . . . . . . . . . 104
Running VBA and Obtaining the PowerPoint File . . . . . . . . . . . . . . 108
Generating Other File Formats. . . . . . . . . . . . . . . . . . . . . . . 110
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110

III Appendix 112


A What Can ChatGPT Do? 113

B Prompt Engineering Cheatsheet 114


Creative Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Exact and Accurate Response . . . . . . . . . . . . . . . . . . . . . . . 115
In-between . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
v

How Far You Have Come 117


Preface

Welcome to the world of ChatGPT, a remarkable AI language model designed to engage in


meaningful and insightful conversations with you. As you delve into the realms of this digital
companion, you will witness the power of human-like language generation, creativity, and
knowledge acquired from a vast corpus of text spanning diverse domains and subjects.
ChatGPT is an incarnation of the cutting-edge GPT-3.5 architecture, built upon
impressive advances in natural language processing and machine learning. Trained on a
plethora of internet text, books, articles, and more, this AI marvel can understand and
generate coherent responses, making it a reliable and versatile companion for a wide range of
inquiries.
It is important to note that while ChatGPT can provide helpful and insightful responses,
it is still an AI system and has its limitations. The information it provides is based on
patterns and knowledge acquired from its training data, which is current until September
2021. Therefore, it may not have access to the most recent events or developments after its
knowledge cutoff date.
In the pages ahead, you will find ChatGPT ready to engage in conversations, answer
questions, and assist you with various tasks to the best of its abilities. Whether you seek
advice, want to explore a topic of interest, or engage in casual banter, ChatGPT provides
companionship, knowledge, and insights.
It is important to remember that while ChatGPT aims to be helpful and informative, it
should not be treated as a substitute for professional advice or human expertise. It is always
recommended to consult trusted sources or experts in relevant fields for critical matters or
decisions.
As you embark on your journey with ChatGPT, prepare to be amazed by its linguistic
capabilities, enjoy stimulating discussions, and discover the vastness of its knowledge base.
Embrace the wonder of conversing with an AI language model and explore the possibilities
that arise when human and artificial intelligence converge.
So, without further ado, let us venture into the realm of ChatGPT, where the boundaries
of human-like conversation blur, and a world of endless possibilities awaits.
vii

Can you determine the content that a human or ChatGPT wrote? Can you pick up on
the nuances that differentiate between human-generated text and large language models that
generate text?
Before I asked you these questions, would you have noticed that I did not write any of
the above? It was all the work of ChatGPT.
Has the evolution of large language models conquered the world of instant content? Let’s
find out more.
Introduction

Welcome to Maximizing Productivity with ChatGPT.


ChatGPT has taken the world by storm. It always ends up in today’s conversations, you
see it on your social media timeline, and people are eager to learn more about the future.
We live in an era of advancements in artificial intelligence that are shifting socioeconomic
grounds. ChatGPT is an AI-based chatbot system that has an in-depth understanding of the
written and spoken word to write content such as poems and research papers and help you
brainstorm topics and ideas.
Since the initial release of ChatGPT in November 2022 by OpenAI, we have seen a flood
of large language models being released left, right and center. We have seen Google chatbot
Bard, Bing AI, CoPilot, and more. ChatGPT represents the pinnacle of large language models
(LLMs) and has created a competitive market for future chatbots. These large language models
have been designed and utilized to engage in interactive conversations with users like you and
me.
The name “ChatGPT” is a combination of its functionality “Chat” and the type of large
language model “GPT” which stands for Generative Pre-trained Transformer. OpenAI’s
foundation GPT models, GPT-3.5 and GPT-4, are a consummation of years of research in
natural language processing (NLP).
OpenAI has invested time into training ChatGPT on a vast and diverse corpus of text to
ensure the chatbot can understand language, process text, and generate human-like responses.
ChatGPT was initially based on GPT-3.5, with a newer release of GPT-4 on March 14th,
2023 which is available to ChatGPT Plus paid subscribers.
While ChatGPT is powerful, as already proven by many of its users, it may not be trivial
to use it effectively for benefit in reality. After all, it is merely a ”language model” which is
never meant to be an expert in all trades. This book is to help you to get the right mindset
in interacting with ChatGPT, so you can be more productive in your daily life.

Book Organization
This is a short book with two parts:
ix

⊲ Foundations: It helps you to understand what ChatGPT (and other large language
models) really are. Also, you should be familiar with the terms that arise from
interacting with ChatGPT, such as prompts and hallucination.
⊲ Applications: Each chapter contains several examples to demonstrate how ChatGPT
may change how you worked. Playing with ChatGPT is fun, but it is not only a toy.
It can revolutionize a lot of things and make humans more productive.
The chapters are as follows:

Foundations: The Model Supporting ChatGPT


⊲ What are Large Language Models. ChatGPT is a web-based application and the core
engine behind it that can understand your input and generate responses is a large
language model (LLM). This chapter tells you the nature of these models and what
problems they can solve.
⊲ Get a Test of LLMs from GPT4All. Sometimes, ChatGPT is too powerful that you
may not have an intuition on how it works and its limitation. GPT4All is an application
let you run a mini-ChatGPT on your own computer. Those models are much smaller
and less capable. But it is a very nice testing environment to learn about LLMs and
how to interact with them correctly.
⊲ What Are Zero-Shot Prompting and Few-Shot Prompting. This chapter describes
two prompting techniques for LLMs. Prompting is to induce responses from LLMs.
You may either ask a question and let the model answer it directly, or you may give
examples and let the model answer after learning the pattern from your examples.
This chapter shows you how these works.
⊲ A Gentle Introduction to Prompt Engineering. With experience in providing a prompt
to LLMs, we focus on the case of zero-shot prompting. Briefly, it means describing your
expectation in detail, so ChatGPT can give you an accurate response. However, what
detail you should provide is not always intuitive. This chapter says you shouldn’t
assume ChatGPT to read your mind. Some basic scene-setting detail should be
provided in the prompt to drive it to work appropriately.
⊲ A Gentile Introduction to Hallucinations in Large Language Models. The key idea
in this chapter is you should never assume ChatGPT or any LLMs as a database. It
responds with facts is just a side effect, but not a guaranteed behavior. This chapter
tells you why LLMs may speak fiction like fact and why it is an important feature of
the model.

Applications: Work Productively with ChatGPT


⊲ Prompt Engineering for Effective Interaction with ChatGPT. In this chapter, we go
into more detail on constructing a prompt for ChatGPT. This is the foundation for
getting a good response. In this chapter, we have some examples that might inspire
you to build a good prompt for an effective use of ChatGPT.
⊲ Strategies for Effective Brainstorming with ChatGPT. This is an example of why
hallucinations in LLMs are useful. You ask the model to hallucinate or brainstorm
x

on a topic. The result may be imaginative and unrealistic, but after all, you may find
it insightful.
⊲ ChatGPT as Your Expert Helper. If you provided a concrete and detailed direction to
ChatGPT, it may not hallucinate too much. People probably found ChatGPT most
useful for this, and this is also why someone mistook ChatGPT as a database, because
it acts like one. You will see examples in this chapter where ChatGPT behaves like
an expert that can solve your problem in detail.
⊲ Writing an Essay with ChatGPT. Writing fiction with ChatGPT is mostly using it for
brainstorming. But writing an analytical essay can also be similar to fiction because
you want it to help you brainstorm arguments to support your conclusion.
⊲ Using ChatGPT as Your Personal Teacher. When you try to learn something but
have no idea how to start, you can ask ChatGPT to give you a study plan. It works
like ChatGPT is an expert often, but you rely on the model’s capability to distill
information it was trained on. Nonetheless, when it works well, you will appreciate
how much help it can give you.
⊲ Using ChatGPT for Translation Effectively. If you do not want ChatGPT to
hallucinate, you must provide data in the prompt so the model has something to
work on. The easiest example is to translate. In fact, ChatGPT is an amazing
translator because it was trained from text of many languages, and it learned the
language rules by example. Therefore, you will appreciate the result of translation
from ChatGPT sounds much more natural than any rule-based machine translator.
⊲ Mastering Summarization with ChatGPT. Another example of providing data in the
prompt and letting ChatGPT use its language skills only is summarizing text. This
is to make the model extract idea from your prompt and reproduce the idea in its
response. By watching how ChatGPT summarizes your input, you will be convinced
that the language model can understand.
⊲ Advanced Techniques for Research with ChatGPT. If ChatGPT can summarize your
paragraphs, it can also summarize your data. In this chapter, you will see how
ChatGPT can distill insights from the data you provided, a common research task.
However, you will also see other examples that you can ask ChatGPT for ideas on
how to do your research.
⊲ Using the Natural Language Understanding Capability of ChatGPT. Suppose you take
ChatGPT as an assistant who can speak human language. It is good at converting
unstructured data into structured data, such as extracting information embedded in
paragraphs into a point form or table. This chapter gives you examples. Then, you
can leverage the language capability of ChatGPT to clean up messy text and save
you time reading them.
⊲ Using ChatGPT as Your Programming Assistant. While ChatGPT can speak human
language, it can also speak computer language. It is because, probably, ChatGPT has
trained from programming textbooks. Therefore, we can make ChatGPT generate a
program for you and save you time to bootstrap your project. You can also do it the
other way, make ChatGPT explain a program in English.
xi

⊲ Generating Diagrams with ChatGPT. ChatGPT would not give you pictures in its
output. But it doesn’t mean we cannot make ChatGPT to help us create pictures. In
this chapter, you will see the trick to make ChatGPT create pictures, namely, ask it
to produce some picture-generating language so that you can produce a picture with
another tool.
⊲ Creating a PowerPoint Presentation using ChatGPT. If you can produce a picture,
you can produce other things, too, if you know the tool. In this chapter, we will see an
example of how to generate a PowerPoint Presentation. Of course, it is not directly
from ChatGPT’s output, but we will see how we can get the file in a few steps.
This book is an effort between MachineLearningMastery and KDnuggets. Abid Ali Awan
contributed chapters 7, 8, 10, and 11. Matthew Mayo contributed chapter 6. Kanwal Mehreen
contributed chapters 12–13 as well as the frontmatter. Adrian Tam contributed chapters 1–5,
9, and 14–17.

Your Outcomes from Reading This Book


This book does not assume you have any programming background. A few chapters in this
book cover programming in the examples. But you don’t need to understand the programming
language covered to read them. In fact, as long as you can access to a browser and login to
ChatGPT’s web page, you can follow the examples in this book and do something useful.
Alternatively, you can also try to practice with Google’s Bard since it is functionally similar
to ChatGPT. Unlike many other books from MachineLearningMastery.com, this book is not a
programming book. But same as other MachineLearningMastery.com publications, this book
is a playbook that you can follow and practice your skills.

Figure 1: Bard by Google is an alternative to ChatGPT (https://bard.google.com)

By finishing this book, you should be fairly competent in prompt engineering: A skill of
expressing your intention well with enough information to make a large language model work
xii

for you. In fact, this is also the skill to make clear of yourself, so other people can work for
you.
Are you ready? Let’s dive in!

Next
Next up you will discover a gentle introduction to large language models, so that you know
who you’re talking to when you’re talking to ChatGPT.
I
The Magic Behind ChatGPT
What are Large Language Models
1
Large language models (LLMs) are recent advances in deep learning models to work on human
languages. Some great use case of LLMs has been demonstrated. ChatGPT is powered by an
LLM. A large language model is a trained deep-learning model that understands and generates
text in a human-like fashion. Behind the scenes, it is a large-scale transformer model that
does all the magic.
In this chapter, you will learn about the structure of large language models and how it
works. In particular, you will know:
⊲ The machine learning theory behind ChatGPT
⊲ How a model reads text and generates output
⊲ Why ChatGPT can produce text in a human-like fashion
Let’s get started.

Overview
This chapter is divided into three parts; they are:
⊲ From Transformer Model to Large Language Model
⊲ Why Transformer Can Predict Text?
⊲ How a Large Language Model Is Built?

1.1 From Transformer Model to Large Language Model


As humans, we perceive text as a collection of words. Sentences are sequences of words.
Documents are sequences of chapters, sections, and paragraphs. However, for computers, text
is merely a sequence of characters. To enable machines to comprehend text, a model based
on recurrent neural networks can be built. This model processes one word or character at a
time and provides an output once the entire input text has been consumed. This model works
pretty well, except it sometimes “forgets” what happened at the beginning of the sequence
when the end is reached.
1.1 From Transformer Model to Large Language Model 3

In 2017, Vaswani et al. published a paper, “Attention Is All You Need”, to establish a
transformer model. It is based on the attention mechanism. Contrary to recurrent neural
networks, the attention mechanism allows you to see the entire sentence (or even the paragraph)
at once rather than one word at a time. This allows the transformer model to understand
the context of a word better. Many state-of-the-art language processing models are based on
transformers.
To process a text input with a transformer model, you first need to tokenize it into a
sequence of words. These tokens are then encoded as numbers and converted into embeddings,
which are vector-space representations of the tokens that preserve their meaning. Next, the
encoder in the transformer transforms the embeddings of all the tokens into a context vector.
Below is an example of a text string, its tokenization, and the vector embedding. Note
that the tokenization can be subwords, such as the word “nosegay” in the text is tokenized
into “nose” and “gay”.

As she said this, she looked down at her hands, and was surprised to find that she had
put on one of the rabbit's little gloves while she was talking. "How can I have done
that?" thought she, "I must be growing small again." She got up and went to the table to
measure herself by it, and found that, as nearly as she could guess, she was now about
two feet high, and was going on shrinking rapidly: soon she found out that the reason of
it was the nosegay she held in her hand: she dropped it hastily, just in time to save
herself from shrinking away altogether, and found that she was now only three inches
high.

Listing 1.1: Example of input text

['As', ' she', ' said', ' this', ',', ' she', ' looked', ' down', ' at', ' her', ' hands',
',', ' and', ' was', ' surprised', ' to', ' find', ' that', ' she', ' had', ' put',
' on', ' one', ' of', ' the', ' rabbit', "'s", ' little', ' gloves', ' while', ' she',
' was', ' talking', '.', ' "', 'How', ' can', ' I', ' have', ' done', ' that', '?"',
' thought', ' she', ',', ' "', 'I', ' must', ' be', ' growing', ' small', ' again', '."',
' She', ' got', ' up', ' and', ' went', ' to', ' the', ' table', ' to', ' measure',
' herself', ' by', ' it', ',', ' and', ' found', ' that', ',', ' as', ' nearly', ' as',
' she', ' could', ' guess', ',', ' she', ' was', ' now', ' about', ' two', ' feet',
' high', ',', ' and', ' was', ' going', ' on', ' shrinking', ' rapidly', ':', ' soon',
' she', ' found', ' out', ' that', ' the', ' reason', ' of', ' it', ' was', ' the',
' nose', 'gay', ' she', ' held', ' in', ' her', ' hand', ':', ' she', ' dropped', ' it',
' hastily', ',', ' just', ' in', ' time', ' to', ' save', ' herself', ' from',
' shrinking', ' away', ' altogether', ',', ' and', ' found', ' that', ' she', ' was',
' now', ' only', ' three', ' inches', ' high', '.']

Listing 1.2: Tokenized text

[ 2.49 0.22 -0.36 -1.55 0.22 -2.45 2.65 -1.6 -0.14 2.26
-1.26 -0.61 -0.61 -1.89 -1.87 -0.16 3.34 -2.67 0.42 -1.71
...
2.91 -0.77 0.13 -0.24 0.63 -0.26 2.47 -1.22 -1.67 1.63
1.13 0.03 -0.68 0.8 1.88 3.05 -0.82 0.09 0.48 0.33]

Listing 1.3: Embedding of the above text


1.1 From Transformer Model to Large Language Model 4

The context vector is like the essence of the entire input. Using this vector, the transformer
decoder generates output based on clues. For instance, you can provide the original input as
a clue and let the transformer decoder produce the subsequent word that naturally follows.
Then, you can reuse the same decoder, but this time the clue will be the previously produced
next-word. This process can be repeated to create an entire paragraph, starting from a leading
sentence.

Figure 1.1: Transformer Architecture

This process is called autoregressive generation. This is how a large language model
works: It is a transformer model in a large scale that can take very long input text, the
context vector is also large, so it can handle very complex concepts, and with many layers in
its encoder and decoder. We let the LLM generate text autoregressively until it reached the
natural end of a paragraph, based on the input we provided as well as the earlier words and
sentences it generated previously.
1.2 Why Transformer Can Predict Text? 5

1.2 Why Transformer Can Predict Text?


In his blog post The Unreasonable Effectiveness of Recurrent Neural Networks, Andrej
Karpathy demonstrated that recurrent neural networks can predict the next word of a text
reasonably well. Not only because there are rules in human language (i.e., grammar) that
limit the use of words in different places in a sentence but also because there is redundancy
in language.
According to Claude Shannon’s influential paper, “Prediction and Entropy of Printed
English”, the English language has an entropy of 2.1 bits per letter, despite having 27 letters
(including spaces). If letters were used randomly, the entropy would be 4.8 bits. Therefore it
is easy to predict what comes next in a human language. Machine learning models, especially
transformer models, are adept at making such predictions.
By repeating this process, a transformer model can generate the entire passage word by
word. However, what is grammar as seen by a transformer model? Grammar denotes how
words are utilized in language, categorizing them into various parts of speech and requiring
a specific order within a sentence. Despite this, it is challenging to enumerate all the rules
of grammar. In reality, the transformer model doesn’t explicitly store these rules, instead
acquiring them implicitly through examples. It’s possible that the model can learn beyond
just grammar rules, extending to ideas presented in those examples, but the transformer model
must be large enough.

1.3 How a Large Language Model Is Built?


A large language model is a transformer model on a large scale. It is so large that usually
cannot be run on a single computer. Hence it is naturally a service provided over API or a
web interface. As you can expect, such large model is learned from a vast amount of text
before it can remember the patterns and structures of language.
For example, the GPT-3 model backing the ChatGPT service was trained on massive
amounts of text data from the internet. This includes books, articles, websites, and various
other sources. During training, the model learns the statistical relationships between words,
phrases, and sentences, allowing it to generate coherent and contextually relevant responses
when given a prompt or query.
Distilling from this vast amount of text, the GPT-3 model can therefore understand
multiple languages and possess knowledge of various topics. That’s why it can produce text in
different style. While you may be amazed that large language model can perform translation,
text summarization, and question answering, it is not surprised if you consider these are special
“grammars” that match the leading text, a.k.a. prompts.

1.4 Further Readings


This section provides more resources on the topic if you are looking to go deeper.
1.5 Summary 6

Articles
Ashish Vaswani et al. “Attention Is All You Need”. In: Proc. 31st Conference on Neural
Information Processing Systems (NIPS 2017). 2017.
https://arxiv.org/pdf/1706.03762.pdf
Andrej Karpathy. The Unreasonable Effectiveness of Recurrent Neural Networks. May 2015.
http://karpathy.github.io/2015/05/21/rnn-effectiveness/
Claude E. Shannon. “Prediction and Entropy of Printed English”. The Bell System Technical
Journal, Jan. 1951, pp. 50–64.
https://www.princeton.edu/~wbialek/rome/refs/shannon_51.pdf
Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. Improving Language
Undestanding by Generative Pre-Training. 2018.
https : / / cdn . openai . com / research - covers / language - unsupervised / language _
understanding_paper.pdf

1.5 Summary
There are multiple large language models developed. Examples include the GPT-3 and GPT-
4 from OpenAI, LLaMA from Meta, and PaLM2 from Google. These are models that can
understand language and can generate text. In this chapter, you learned that:
⊲ The large language model is based on transformer architecture
⊲ The attention mechanism allows LLMs to capture long-range dependencies between
words; hence the model can understand the context
⊲ Large language model generates text autoregressively based on previously generated
tokens
In the next chapter, you will see how you can play with an LLM on your own computer.
Get a Taste of LLMs from
GPT4All
2
Large language models have become popular recently. ChatGPT is fashionable. Trying out
ChatGPT to understand what LLMs are about is easy, but sometimes, you may want an offline
alternative that can run on your computer. In this chapter, you will learn about GPT4All as
an LLM that you can install on your computer. In particular, you will learn:
⊲ What is GPT4All
⊲ How to install the desktop client for GPT4All
⊲ How to run GPT4All in Python
Let’s get started.

Overview
This chapter is divided into three parts; they are:
⊲ What is GPT4All?
⊲ How to get GPT4All
⊲ How to use GPT4All in Python

2.1 What is GPT4All?


The term “GPT” is derived from the title of a 2018 paper, Improving Language Undestanding
by Generative Pre-Training by Radford et al. This paper describes how transformer models
are demonstrated to be able to understand human language.
Since then, many people attempted to develop language models using transformer
architecture, and it has been found that a model large enough can give excellent results.
However, many of the models developed are proprietary. There are either provided as a
service with paid subscription or under a license with certain restrictive terms. Some are even
impossible to run on commodity hardware due to is size.
GPT4All project tried to make the LLMs available to the public on common hardware.
It allows you to train and deploy your model. Pretrained models are also available, with a
small size that can reasonably run on a CPU.
2.2 How to get GPT4All 8

2.2 How to get GPT4All


Let’s focus only on using the pretrained models.
At the time of writing, GPT4All is available from https://gpt4all.io/index.html, which
you can run as a desktop application or using a Python library. You can download the installer
for your OS to run a desktop client. The client is only a few hundred MB. You should see an
installation screen as follows:

Figure 2.1: Installing GPT4All as an application

After you have the client installed, launching it the first time will prompt you to install a
model, which can be as large as many GB. To start, you may pick “gpt4all-j-v1.3-groovy”
(the GPT4All-J model). It is a relatively small but popular model.
2.2 How to get GPT4All 9

Figure 2.2: Installing models inside GPT4All

Once the client and model are ready, you can type your message in the input box. The model
may expect a specific form of input, e.g., a particular language or style. This model expects
a conversation style (like ChatGPT) and generally handles English well. For example, below
is how it responds to the input “Give me a list of 10 colors and their RGB code”:

Figure 2.3: Interacting with GPT4All


2.3 How to use GPT4All in Python 10

2.3 How to use GPT4All in Python


The key component of GPT4All is the model. The desktop client is merely an interface to it.
Besides the client, you can also invoke the model through a Python library.
The library is unsurprisingly named “gpt4all,” and you can install it with pip command:

pip install gpt4all

Listing 2.1: Installing gpt4all as a Python module

Afterward, you can use it in Python in just a few lines of code:

import gpt4all

gptj = gpt4all.GPT4All("ggml-gpt4all-j-v1.3-groovy")
messages = [{"role": "user", "content": "Give me a list of 10 colors and their RGB code"}]
ret = gptj.chat_completion(messages)
print(ret)

Listing 2.2: Interacting with GPT4All using Python code

Running the above code will download the model file if you haven’t yet. Afterward, the model
is loaded, input is provided, and the response is returned as a Python dictionary like the
following:

{'model': 'ggml-gpt4all-j-v1.3-groovy',
'usage': {'prompt_tokens': 272,
'completion_tokens': 301,
'total_tokens': 573},
'choices': [
{'message':
{'role': 'assistant',

❈ 'content': ' Here is a list of 10 colors and their RGB code:Red (255, 0, 0) ❈
❈ Green (0, 255, 0) Blue (0, 0, 255) Yellow (255, 255, 0) Orange (255, ❈
❈ 127, 0) Purple (0, 128, 255) Pink (255, 192, 203) Blue-Green (0, 0, ❈
❈ 255) Green-Blue (0, 0, 255) Blue-Purple (0, 0, 255) Blue-Green (0, 0, ❈
255) Blue-Purple (0, 0'
}
}
]
}

Listing 2.3: Output from GPT4All

The example above use an input as a list of one dictionary. A more sophisticated input would
be a list of many dictionaries, each containing the keys role and content. The role can be
either "system", "assistant", or "user", while content is a string of text. If you’re using
GPT4All-J model like the example, your role is "user" while the computer is "assistant".
The input should be a sequence of conversations between these two parties. Below is how you
can construct a conversation step by step:
2.3 How to use GPT4All in Python 11

import json
import gpt4all

gptj = gpt4all.GPT4All("ggml-gpt4all-j-v1.3-groovy")


messages = [{"role": "user", "content": "Can you explain what is a large language ❈
model?"}]
ret = gptj.chat_completion(messages)

messages.append(ret["choices"][0]["message"])
messages.append({"role": "user", "content": "Can you give some examples applications?"})
ret = gptj.chat_completion(messages)

messages.append(ret["choices"][0]["message"])
messages.append({"role": "user", "content": "Are there any limitations?"})
ret = gptj.chat_completion(messages)

messages.append(ret["choices"][0]["message"])
messages.append({"role": "user", "content": "Summarize the above in two sentences."})
ret = gptj.chat_completion(messages)

print(json.dumps(messages, indent=4))
print(json.dumps(ret, indent=4))

Listing 2.4: A conversation with GPT4All in Python code

Note that you invoked the model multiple times. Each time it responded, you took the output
and appended it to the list of messages, so you accumulated the context. Then you add a new
dialog and invoke the model again. You need to collect the messages because each time you
invoke the model, it starts afresh without knowing the previous conversation. So it is your
job to keep the history to remind the model of its prior responses.
Below is an example of the output of the code above, in which the last input message to
the model and its response is printed. You may get a better result from another model. You
may also get a different result due to the randomness in the model:

[
{
"role": "user",
"content": "Can you explain what is a large language model?"
},
{
"role": "assistant",


"content": " A large language model is a type of artificial intelligence that ❈
❈ can process and understand natural language, such as speech or text. It ❈
❈ is trained on large amounts of data and can perform tasks such as ❈
❈ language translation, sentiment analysis or even answering questions. ❈
❈ Large language models are becoming increasingly popular in various ❈
industries, including finance and healthcare."
},
{
"role": "user",
"content": "Can you give some examples applications?"
},
2.3 How to use GPT4All in Python 12

{
"role": "assistant",


"content": " Large language models are being used in a variety of ❈
❈ applications, such as:- Language translation and machine translation, ❈
❈ where large language models are trained on vast amounts of data to ❈
❈ improve accuracy and speed.- Sentiment analysis, where large language ❈
❈ models are trained to analyze social media data and identify patterns in ❈
❈ user opinions.- Question answering, where large language models are ❈
❈ trained to answer questions based on a large corpus of data.- Healthcare, ❈
❈ where large language models are being used to analyze patient data and ❈
❈ identify patterns in health trends.- Finance, where large language models ❈
are being used to analyze financial data and identify patterns in"
},
{
"role": "user",
"content": "Are there any limitations?"
},
{
"role": "assistant",


"content": " Yes, there are some limitations to large language models. One ❈
❈ of the main challenges is that they require a lot of data to train, which ❈
❈ can be expensive and time-consuming. Additionally, large language models ❈
❈ can be computationally expensive and may require specialized hardware to ❈
❈ run. Another limitation is that large language models may not be able to ❈
❈ understand the nuances of human language, which can make them less ❈
❈ effective in certain situations. Finally, large language models may not ❈
❈ be able to understand the context of a conversation or text, which can ❈
make them less effective in certain applications."
},
{
"role": "user",
"content": "Summarize the above in two sentences."
}
]
{
"model": "ggml-gpt4all-j-v1.3-groovy",
"usage": {
"prompt_tokens": 2113,
"completion_tokens": 542,
"total_tokens": 2655
},
"choices": [
{
"message": {
"role": "assistant",


"content": " Large language models are a type of artificial ❈
❈ intelligence that can process and understand natural language, ❈
❈ such as speech or text. They are trained on large amounts of data ❈
❈ and can perform tasks such as language translation, sentiment ❈
❈ analysis or even answering questions. They are becoming ❈
❈ increasingly popular in various industries, including finance and ❈
❈ healthcare. However, there are some limitations such as expensive ❈
❈ data and specialized hardware, computational expense, lack of ❈
understanding nuances in human language and context."
2.4 Further Readings 13

}
}
]
}

Listing 2.5: Outputs of multiple interaction with GPT4All

2.4 Further Readings


This section provides more resources on the topic if you are looking to go deeper.

Articles
Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever. Improving Language
Undestanding by Generative Pre-Training. 2018.
https : / / cdn . openai . com / research - covers / language - unsupervised / language _
understanding_paper.pdf

2.5 Summary
GPT4All is a nice tool you can play with on your computer. It allows you to explore the
interaction with a large language model and help you better understand the capability and
limitation of a model. In this chapter, you learned that:
⊲ GPT4All has a desktop client that you can install on your computer
⊲ GPT4All has a Python interface that allows you to interact with a language model
in code
⊲ There are multiple language models available
In the next chapter, you will learn some basic prompting technique so you know what to type
in the GPT4All input box.
What Are Zero-Shot Prompting
and Few-Shot Prompting
3
In the literature on language models, you will often encounter the terms “zero-shot prompting”
and “few-shot prompting.” It is important to understand how a large language model generates
an output. In this chapter, you will learn:
⊲ What is zero-shot and few-shot prompting?
⊲ How to experiment with them in GPT4All
Let’s get started.

Overview
This chapter is divided into three parts; they are:
⊲ How Do Large Language Models Generate Output?
⊲ Zero-Shot Prompting
⊲ Few-Shot Prompting

3.1 How Do Large Language Models Generate Output?


Large language models were trained with massive amounts of text data. They were trained
to predict the next word from the input. It is found that, given the model is large enough,
not only the grammar of human languages can be learned, but also the meaning of words,
common knowledge, and primitive logic.
Therefore, if you give the fragmented sentence “My neighbor’s dog is” to the model (as
input, also known as prompt), it may predict with “smart” or “small” but not likely with
“sequential,” although all these are adjectives. Similarly, if you provide a complete sentence
to the model, you can expect a sentence that follows naturally from the model’s output.
Repeatedly appending the model’s output to the original input and invoking the model again
can make the model generate a lengthy response.
3.2 Zero-Shot Prompting 15

3.2 Zero-Shot Prompting


In natural language processing models, zero-shot prompting means providing a prompt that
is not part of the training data to the model, but the model can generate a result that you
desire. This promising technique makes large language models useful for many tasks.
To understand why this is useful, imagine the case of sentiment analysis: You can take
paragraphs of different opinions and label them with a sentiment classification. Then you can
train a machine learning model (e.g., RNN on text data) to take a paragraph as input and
generate classification as output. But you would find that such a model is not adaptive. If
you add a new class to the classification or ask not to classify the paragraph but summarize
them, this model must be modified and retrained.
A large language model, however, needs not to be retrained. You can ask the model to
classify a paragraph or summarize it if you know how to ask correctly. This means the model
probably cannot classify a paragraph into categories A or B since the meaning of “A” and
“B” are unclear. Still, it can classify into “positive sentiment” or “negative sentiment” since
the model knows what should “positive” and “negative” be. This works because, during the
training, the model learned the meaning of these words and acquired the ability to follow
simple instructions. An example is the following, demonstrated using GPT4All with the model
Vicuna-7B:

Figure 3.1: Zero-shot prompting in GPT4All with Vicuna-7B model

The prompt provided was:


Classify the text into positive, neutral or negative:
Text: That shot selection was awesome.


Classification:
The response was a single word, “positive.” This is correct and concise. The model obviously
can understand “awesome” is a positive sensation, but knowing to identify the sensation
3.3 Few-Shot Prompting 16

is because of the instruction at the beginning, “Classify the text into positive, neutral or
negative.”
In this example, you found that the model responded because it understood your
instruction.

3.3 Few-Shot Prompting


You can provide some examples if you cannot describe what you want but still want a language
model to give you answers. It is easier to demonstrate this with the following example:

Figure 3.2: Few-shot prompting in GPT4All with Vicuna-7B model

Still using the Vicuna-7B model in GPT4All, but this time, we are providing the prompt:


Text: Today the weather is fantastic
Classification: Pos
Text: The furniture is small.
Classification: Neu
Text: I don’t like your attitude
Classification: Neg
Text: That shot selection was awful


Classification:
Here you can see that no instruction on what to do is provided, but with some examples, the
model can figure out how to respond. Also, note that the model responds with “Neg” rather
than “Negative” since it is what is provided in the examples.
Guiding the model to respond with examples is called few-shot prompting.
3.4 Summary 17

Due to the model’s random nature, you may be unable to reproduce the exact
INFO-CIRCLE result. You may also find a different output produced each time you run the
model.

3.4 Summary
In this chapter, you learned some examples of prompting. Specifically, you learned:
⊲ What are one-shot and few-shot prompting
⊲ How a model works with one-shot and few-shot prompting
⊲ How to test out these prompting techniques with GPT4All
In the next chapter, you will learn more about creating a prompt.
A Gentle Introduction to Prompt
Engineering
4
ChatGPT is a service provided by OpenAI that is a conversational large language model. It is
widespread, and it is found to be very useful. Behind the scene, it is a large language model.
Unlike the other LLMs that generate continuing text from the leading sentence you provided,
ChatGPT enables you to ask questions or provide instructions, and the model will respond
like a conversation. To make ChatGPT respond correctly, you must interact with the model.
This technique is called prompt engineering.
In this chapter, you will understand ChatGPT as an LLM and learn about prompt
engineering. In particular,
⊲ What is the input context to LLM in ChatGPT
⊲ How ChatGPT interacts with the input
⊲ How to provide an appropriate prompt to get the result you desired
Let’s get started.

Overview
This chapter is divided into three parts; they are:
⊲ Understanding ChatGPT
⊲ Engineering the Context
⊲ Advices for Prompt Engineering

4.1 Understanding ChatGPT


ChatGPT is a conversational large language model. A language model can generate words
given the leading text. A conversational large language model is a natural variation. If you
have read the drama play, such as the following example written by Shakespeare, you should
notice a conversation is a dialog between multiple individuals:


Abr. Do you bite your thumb at us, sir?
Sam. I do bite my thumb, sir.
4.2 Engineering the Context 19

Abr. Do you bite your thumb at us, sir?


Sam. Is the law of our side, if I say—ay?
Gre. No.


Sam. No, sir, I do not bite my thumb at you, sir; but I bite my thumb, sir.
Romeo and Juliet, act 1 scene 1
If you input the first four lines of a conversation into a language model, it is reasonable to
expect that it will generate the fifth line. As the model has learned from a vast amount of text,
the format of a play is just a style that it understands. Because the model can understand
context, its words should flow naturally with the preceding text, as if it were a proper response
in a chat.

4.2 Engineering the Context


When using LLMs to generate text, the context plays a crucial role in determining the output.
For ChatGPT, the context is derived from previous conversations. To ensure that ChatGPT
responds in a desired manner, it is essential to carefully structure the input to provide the
necessary cues.
While ChatGPT is a robust language model, it does have its limitations. Although it
has acquired some basic “common sense” from its training data, it may not be capable of
demonstrating detailed logical reasoning. For instance, if you ask ChatGPT to “Provide
information on machine learning,” it may respond with a lengthy but not necessarily top-
quality answer. However, if you ask, “Tell me the pros and cons of using machine learning
to solve image classification problems,” you are more likely to receive a superior outcome
because:
⊲ You gave a specific scope, i.e., the image classification problem
⊲ You requested a specific format of the response, i.e., pros and cons
Similar cases are when you ask a complicated question, such as a math word problem like the
following:


To prepare for Easter, Mrs. Smith went to a store and bought 10 toy bunnies for
$5 each. Chocolate egg is $1 cheaper than bunnies, and Mrs Smith bought 15.


How much did Mrs. Smith spend?
A newer version of ChatGPT can probably do it right, but questions of this type are easily
error-prone if the large language model attempts to give you an answer immediately. The
reason is that when you try to generate a short answer, the context needs more clues to keep
the logic right. However, it is easy to do the math right when the LLM tries to lay out the
logic in steps. Therefore, someone suggested you ask ChatGPT not “How much did Mrs.
Smith spend” but “Explain how much did Mrs. Smith spend with steps in detail.” These are
the clues to force ChatGPT to reason with logic. For example, the following is what you may
observe as an answer:


To calculate how much Mrs. Smith spent, we need to determine the cost of the
toy bunnies and the chocolate eggs separately and then add them together.
Mrs. Smith bought 10 toy bunnies at $5 each, so the total cost of the bunnies is
4.3 Advises for Prompt Engineering 20

10 * $5 = $«10*5=50»50.
Each chocolate egg is $1 cheaper than the toy bunnies, so the cost of each chocolate
egg is $5 - $1 = $«5-1=4»4.
Mrs. Smith bought 15 chocolate eggs, so the total cost of the chocolate eggs is 15
* $4 = $«15*4=60»60.
Finally, to find out the total amount Mrs. Smith spent, we add the cost of the
bunnies and the cost of the chocolate eggs: $50 + $60 = $«50+60=110»110.


Therefore, Mrs. Smith spent $110 in total.
You can see how an LLM can give you the correct answer. LLM cannot do mental math and
has limited logic capability (since it is trained with text, it learns as much as a single sentence
can express). Should there be more complicated logic, you must ensure the model goes in
small steps. It is called the chain of thoughts.

4.3 Advises for Prompt Engineering


Below are some ideas to craft the context to make ChatGPT or other LLMs produce the
useful output:
⊲ Rather than the model on the loose, you should set up the scenario and scopes in the
prompt by providing details of what, where, when, why, who, and how
⊲ Assigning a persona in the prompt, for example, “As a computer science professor,
explain what is machine learning” rather than merely “Explain what machine learning
is,” can make the response more academic.
⊲ You can control the output style by requesting “explain to a 5-year-old”, “explain
with an analogy,” “make a convincing statement,” or “in 3 to 5 points.”
⊲ To encourage the model to respond with a chain of thoughts, end your request with
“solve this in steps.”
⊲ You can provide additional information to the model by saying, “Reference to the
following information,” followed by the material you want the model to work on
⊲ Because the previous conversation constructs the context, beginning the prompt with
“ignore all previous instructions before this one” can make the model start from scratch
⊲ Making the prompt straightforward and easy to understand is essential since the
context deduced can be more accurate to reflect your intention.

4.4 Summary
In this chapter, you learned how prompts drive the output from an LLM, particularly ChatGPT.
Specifically, you learned.
⊲ How a prompt set up a context so that the model can generate output within the
context
⊲ LLMs are limited; you need to provide correct guidance in the prompt to produce
accurate output.
4.4 Summary 21

⊲ Providing specific, detailed prompts can help get correct output


In the next chapter, you will learn about one infamous feature of LLMs and why it may be a
desirable feature.
5
A Gentle Introduction to
Hallucinations in Large
Language Models

Large Language Models (LLMs) are known to have hallucinations. This is a behavior in that
the model speaks false knowledge as if it is accurate. In this chapter, you will learn why
hallucinations are a nature of an LLM. Specifically, you will learn:
⊲ Why LLMs hallucinate
⊲ How to make hallucinations work for you
⊲ How to mitigate hallucinations
Let’s get started.

Overview
This chapter is divided into three parts; they are
⊲ What are Hallucinations in Large Language Models
⊲ Using Hallucinations
⊲ Mitigating Hallucinations

5.1 What are Hallucinations in Large Language Models


A large language model is a trained machine learning model that generates text based on
the prompt you provided. The model’s training equipped it with some knowledge derived
from the training data we provided. It is difficult to tell what knowledge a model remembers
or what it does not. In fact, when a model generates text, it can’t tell if the generation is
accurate.
In the context of LLMs, hallucination refers to a phenomenon where the model generates
text that is incorrect, nonsensical, or not real. Since LLMs are not databases or search
engines, they would not cite where their response is based on. These models generate text as
an extrapolation from the prompt you provided. The result of extrapolation is not necessarily
supported by any training data, but is the most correlated from the prompt.
5.2 Using Hallucinations 23

To understand hallucination, you can build a two-letter bigrams Markov Chain from
some text: Extract a long piece of text, build a table of every pair of neighboring letters and
tally the count. For example, “hallucinations in large language models” would produce “HA”,
“AL”, “LL”, “LU”, etc. and there is one count of “LU” and two counts of “LA.” Now if you
started with a prompt of “L”, you are twice as likely to produce “LA” than “LL” or “LS”.
Then with a prompt of “LA”, you have an equal probability of producing “AL”, “AT”, “AR”,
or “AN”. Then you may try with a prompt of “LAT” and continue this process. Eventually,
this model invented a new word that didn’t exist. This is a result of the statistical patterns.
You may say your Markov Chain hallucinated a spelling.
Hallucination in LLMs is not much more complex than this, even if the model is much more
sophisticated. From a high level, hallucination is caused by limited contextual understanding
since the model is obligated to transform the prompt and the training data into an abstraction,
in which some information may be lost. Moreover, noise in the training data may also provide
a skewed statistical pattern that leads the model to respond in a way you do not expect.

5.2 Using Hallucinations


You may consider hallucinations a feature in large language models. You want to see the
models hallucinate if you want them to be creative. For example, if you ask ChatGPT or
other Large Language Models to give you a plot of a fantasy story, you want it not to copy
from any existing one but to generate a new character, scene, and storyline. This is possible
only if the models are not looking up data that they were trained on.
Another reason you may want hallucinations is when looking for diversity, for example,
asking for ideas. It is like asking the models to brainstorm for you. You want to have
derivations from the existing ideas that you may find in the training data, but not the same.
Hallucinations can help you explore different possibilities.
Many language models have a temperature parameter. You can control the temperature
in ChatGPT using the API instead of the web interface. This is a parameter of randomness.
The higher temperature can introduce more hallucinations.

5.3 Mitigating Hallucinations


Language models are not search engines or databases. Hallucinations are unavoidable. What
is annoying is that the models generate text with mistakes that is hard to spot.
If the contaminated training data caused the hallucination, you can clean up the data
and retrain the model. However, most models are too large to train on your own devices.
Even fine-tuning an existing model may be impossible on commodity hardware. The best
mitigation may be human intervention in the result and asking the model to regenerate if it
went gravely wrong.
The other solution to avoid hallucinations is controlled generation. It means providing
enough details and constraints in the prompt to the model. Hence the model has limited
freedom to hallucinate. The reason for prompt engineering is to specify the role and scenario
of the model to guide the generation so that it does not hallucinate unbounded.
5.4 Summary 24

5.4 Summary
In this chapter, you learned how an LLM hallucinates. In particular,
⊲ Why hallucination would be useful
⊲ How to limit the hallucination
It’s worth noting that while hallucination can be mitigated, but probably not completely
eliminated. There is a trade-off between creativity and accuracy.
Starting with the next chapter, you will see more examples of how to use LLMs and
ChatGPT in particular, for your benefit.
II
Work Productively with ChatGPT
Prompt Engineering for Effective
Interaction with ChatGPT
6
With the explosion in popularity of generative AI in general and ChatGPT in particular,
prompting has become an increasingly important skill for those in the world of AI. Crafting a
prompt, the mechanism of interacting with a large language model (LLM) such as ChatGPT,
is not the simple syntactic undertaking it would first appear to be. After the novelty of
the first interchanges with ChatGPT, it became clear that practice and consideration would
be needed for prompt mastery. As a result, developing processes to create the most useful
prompts possible — known as prompt engineering — has become a coveted expertise in LLM
circles and beyond.
In this chapter, you will learn about prompt engineering. In particular,
⊲ How to provide information in the prompt for the greatest impact on the responses
⊲ What are personas, positive and negative prompts, zero-shot prompts, and so on
⊲ How to use prompts iteratively to leverage the conversational nature of ChatGPT
Let’s get started.

Overview
This chapter is divided into three parts; they are
⊲ Principles of Prompting
⊲ Basic Prompt Engineering
⊲ Advanced Prompt Engineering Strategies
⊲ Collaborative Power Tips

6.1 Principles of Prompting


Prompt engineering is the most crucial aspect of utilizing LLMs effectively and is a powerful
tool for customizing the interactions with ChatGPT. It involves crafting clear and specific
instructions or queries to elicit the desired responses from the language model. By carefully
6.2 Basic Prompt Engineering 27

constructing prompts, users can guide ChatGPT’s output toward their intended goals and
ensure more accurate and useful responses.
There are several foundational techniques to remember in the process of prompt
optimization for ChatGPT.
First, providing explicit instructions at the beginning of the prompt helps set the context
and define the task for the model. Specifying the format or type of the expected answer is also
beneficial. Additionally, you can enhance the interaction by incorporating system messages
or role-playing techniques in the prompt.
Below is an example prompt with the above techniques:


I would like you to generate 10 quick-prep dinner meal ideas for recipe blogs, with
each idea including a title and a one-sentence description of the meal. These blogs
will be written for an audience of parents looking for easy-to-prepare family meals.


Output the results as a bulleted list.
Compare that prompt with the following:

“ ”
Write 10 recipe blogs.
Intuitively, the former will garner more useful results.
Remember that you can improve the quality and relevance of the model’s responses by
iteratively refining and experimenting with prompts, creating more productive conversations.
Don’t be afraid to test out potential prompts on ChatGPT directly.

6.2 Basic Prompt Engineering


Now that you know what a basic prompt should look like, let’s dive into some basic prompt
engineering considerations in more detail.

6.2.1 Prompt Wording


A prompt’s wording is paramount, as it guides the LLM in generating the desired output.
It’s important to phrase the question or statement in a way that ChatGPT understands and
can respond accurately.
For example, if a user is not an expert in an area and does not know the right term to
phrase a question, ChatGPT may experience limitations on the answers they provide. It is
similar to searching on the web without knowing the correct keyword.
While it may be evident that additional information could be used to create better
prompts, it may be less obvious that being overly verbose in general is not necessarily an
optimal strategy. It’s best to think of prompt wording not as a separate technique but as a
connecting thread through all other techniques.

6.2.2 Succinctness
Succinctness in a prompt is important for clarity and precision. A well-crafted prompt should
be concise and to the point, providing enough information for ChatGPT to understand the
6.2 Basic Prompt Engineering 28

user’s intent without being overly verbose. However, ensuring the prompt is not too brief is
vital, which may lead to ambiguity or misunderstanding. This balance between not enough
and too much can be tricky to strike. Practice is probably the best way to master this skill.
Wording and succinctness in the prompt are important because it is for specificity.

6.2.3 Roles and Goals


In prompt engineering, roles are personas assigned for the LLM and the intended audience. For
example, if one is interested in having ChatGPT write an outline for a blog post on machine
learning classification metrics, explicitly stating that the LLM is to act as an expert machine
learning practitioner and that its intended audience is data science newcomers would certainly
help provide a fruitful response. Whether this should be stated in conversational language
(“You are to act as a real estate agent with 10 years experience in the Phoenix area”) or in
a more formal manner (“Author: expert Phoenix real estate agent; Audience: inexperienced
home buyers”) can be experimented within a given scenario.
Goals are intimately connected to roles. Explicitly stating the goal of a prompt-guided
interaction is not only a good idea but also necessary. Without it, how would ChatGPT have
any inkling of what output to generate?
Below is a competent prompt that has considered both roles and goals:


You are to act as a real estate agent with 10 years of experience in the Phoenix
area. Your goal is to produce a one-paragraph summary of each of the top 5
family neighborhoods in the Phoenix metropolitan area. The intended audience
is inexperienced home buyers.
Along with the explicitly stated roles and goals, note the relative specificity of the


example prompt above.

6.2.4 Positive and Negative Prompting


Positive and negative prompting is another set of framing methods to guide the model’s
output. Positive prompts (“do this”) encourage the model to include specific types of output
and generate certain types of responses. Negative prompts (“don’t do this”), on the other
hand, discourage the model from including specific types of output and generating certain
types of responses. Using positive and negative prompts can greatly influence the direction
and quality of the model’s output.
Consider the following example prompt:


You are to act as a real estate agent with 10 years of experience in the Phoenix
area. Your goal is to produce a one-paragraph summary of each of the top 5
family neighborhoods in the Phoenix metropolitan area. The intended audience


is inexperienced home buyers.
The above prompt’s framing is positive, guiding what ChatGPT should generate. Let’s add
some wording to discourage certain output, be it in content or format. An example of negative
prompting geared toward content guidance could be the addition of the following to our above
example:
6.3 Advanced Prompt Engineering Strategies 29


Do not include any neighborhoods within 5 miles of downtown or adjacent to the


airport.
This additional constraint should be helpful in ChatGPT’s understanding of what output it
should generate.

6.3 Advanced Prompt Engineering Strategies


Let’s look at a selection of more advanced prompt engineering strategies. While the previous
section provided some general guidelines for interactions with LLMs, you can turn to a variety
of contemporary strategies that are commonplace in the prompt engineer’s toolkit for the
ability to interact with ChatGPT in a more complex manner.

Input/Output Prompting
The input/output prompting strategy involves defining the input that the user provides to the
LLM and the output that the LLM is to generate in response. This strategy is fundamental
to prompt engineering as it directly influences the quality and relevance of the ChatGPT’s
response.
For instance, the user might provide an input prompt asking ChatGPT to generate a
Python script for a specific task, and the desired output would be the generated script.
Below is an example of the most basic strategy: provide a single input and desire a single
output.


Generate a Python script that takes a single mandatory command line argument
([project]) and performs the following tasks:
- creates a new folder named [project]
- creates a file within the new folder named [project].py


- writes a simple Python script file header to the [project].py file

Zero-Shot Prompting
The zero-shot strategy involves the LLM generating an answer without any examples or
context. This strategy can be useful when the user wants a quick answer without providing
additional detail or when the topic is so general that examples would artificially limit the
response. For example:

“ ”
Generate 10 possible names for my new dog.

One-Shot Prompting
The one-shot strategy involves the LLM generating an answer based on a single example or
piece of context provided by the user. This strategy can guide ChatGPT’s response and ensure
it aligns with the user’s intent. The idea here would be that one example would provide more
guidance to the model than none. For example:


Generate 10 possible names for my new dog.


A dog name that I like is Banana.
6.3 Advanced Prompt Engineering Strategies 30

Few-Shot Prompting
The few-shot strategy involves the LLM generating an answer based on a few examples or
pieces of context provided by the user. This strategy can guide ChatGPT’s response and
ensure it aligns with the user’s intent. The idea here would be that several examples would
provide more guidance to the model than one. For example:


Generate 10 possible names for my new dog.
Dog names that I like include:
- Banana
- Kiwi
- Pineapple


- Coconut
As you can guess, the more examples the prompt included, the closer the generated output
conforms to what is desired. With zero-shot, there may be no fruit names suggested; with
one-shot, there may be several; and with few-shot, the suggestions may consist entirely of
fruit-themed names.

Chain-of-Thought Prompting
The chain-of-thought strategy involves providing the LLM with a few examples that help to
refine the original question and ensure a more accurate and comprehensive answer. Chain-
of-thought prompts are so-called because they include a few chain-of-thought examples in
the prompting. It is differentiated from the X-shot prompting techniques as chain-of-thought
prompts are structured to encourage critical thinking and are designed to help uncover new
insights or approaches that ChatGPT may not have otherwise considered.
The technique also encourages the LLM to output its critical reasoning. The calling card
of chain-of-thought prompting is the phrase “Let’s think step by step” which is generally
appended to the end of a prompt, which research suggests is enough to improve generated
results.
Consider the following one-shot prompt example:


Q: Joe has 20 eggs. He buys 2 more cartons of eggs. Each carton contains 12 eggs.
How many eggs does Joe have now?
A: The answer is 44.
Q: Farmer John had 93 chickens. If he sold 20 to Farmer Bill and bought twice


that number more, how many chickens does Farmer John have now?
And consider ChatGPT’s incorrect output response:

“ ”
The answer is 73.
Now let’s look at the following chain of thought prompt, which is written to encourage critical
thinking by the LLM:


Q: Joe has 20 eggs. He buys 2 more cartons of eggs. Each carton contains 12 eggs.
How many eggs does Joe have now? Let’s think step by step.
A: Joe started with 20 eggs. 2 cartons of 12 eggs is 24 eggs. 20 + 24 = 44.
Therefore, Joe has 44 eggs, and the answer is 44.
6.3 Advanced Prompt Engineering Strategies 31

Q: Farmer John had 93 chickens. If he sold 20 to Farmer Bill and bought twice
that number more, how many chickens does Farmer John have now? Let’s think


step by step.
ChatGPT’s response is different this time:


A: Farmer John sold 20 chickens to Farmer Bill, so he was left with 93 - 20 = 73
chickens. He then bought twice the number of chickens he sold, so he bought 2
* 20 = 40 chickens. Adding these newly bought chickens to his remaining stick,


Farmer John now has 73 + 40 = 113 chickens.
By providing an example of the critical thinking process needed to solve this problem and
coaching it to think step by step, ChatGPT could apply the same reasoning to our question
and come up with the right answer this time.

6.3.1 Self-Criticism
The self-criticism strategy involves prompting the LLM to assess its output for potential
inaccuracies or improvement areas. This strategy can ensure the information provided by
ChatGPT is as accurate as possible. It can aid users in debugging their prompts and
determining why they are not getting results that meet expectations.
An example of such a prompt is as follows:


Please re-read your above response. Do you see any issues or mistakes with your
response? If so, please identify these issues or mistakes and make the necessary


edits.
This example pertains to coaching ChatGPT to use self-criticism for debugging its buggy
code:


Look at the code you have just generated. Currently it does not run. Are you
able to see any syntax errors or flow control mistakes that you can rectify? If so,


please identify the section of problematic code and re-generate it.
Harnessing ChatGPT’s self-healing abilities is a prompt engineering technique you must not
overlook.

6.3.2 Iterative
The iterative or expansive strategy involves prompting the LLM with follow-up prompts based
on the output of an initial prompt. This involves iterating on the results by asking further
questions or making additional requests from each successive response.
For example, consider having ChatGPT assist in creating an outline for a book you are
writing. The first prompt could like this:


I am writing a book on time travel theories. I have not settled on a specific topic.
Generate 5 specific topic suggestions for such a book. For each suggestion, provide
a title and one paragraph of description of what the book would cover. The book


will be aimed at casual readers.
Now, suppose one of the suggested topics is as follows:
6.4 Collaborative Power Tips 32


Title: “Temporal Paradoxes: Navigating the Complexities of Time Travel”
Description: “Temporal Paradoxes” delves into the mind-bending intricacies of
time travel paradoxes, exploring the fascinating conundrums they present. This
book explores various paradoxes such as the Bootstrap Paradox, the Predestination
Paradox, and the Information Paradox, among others.


...
You could then iterate on this using a follow-up prompt:


I will write the book you suggested, “Temporal Paradoxes: Navigating the
Complexities of Time Travel”. Generate a chapter outline for this book, including


sections and subsections.
A possible output excerpt is below:


Introduction
- Defining temporal paradoxes
- Significance of temporal paradoxes in time travel narratives
- Overview of the chapter structure
Chapter 1: The Bootstrap Paradox
1.1 The essence of the Bootstrap Paradox
- Explaining the concept and its origin
- Key examples from literature, film, and real-life anecdotes


...
This iteration can then continue. Further prompting could be:


Let’s flesh out the introduction. Generate a two paragraph summary of what each
of the chapter’s sections will cover. The chapter outline for the introduction is
below.
---
Introduction
- Defining temporal paradoxes
- Significance of temporal paradoxes in time travel narratives


- Overview of the chapter structure
You could see how further iteration could continue in this example. A similar iteration could
be used to have ChatGPT generate code: starting with an overview, iterating on the overview
to generate modules, generating on the modules to generate functions, and finally generate the
code within functions. Just as breaking big problems into smaller, more manageable problems
is generally a prescription for success with humans, ChatGPT excels at completing larger
tasks in more approachable chunks.

6.4 Collaborative Power Tips


The best way to look at ChatGPT is as a junior assistant, be that a research assistant,
coding assistant, problem-solving assistant, or whatever assistant you require. Recognizing
and fostering this collaborative atmosphere can lead to further success. Here are a few quick
tips for promoting this collaboration.
6.5 Summary 33

6.4.1 Prompting for Prompts


One way to improve your prompt crafting is to get ChatGPT involved. A prompt like this
could lead to beneficial results:

“ ”
What prompt could I use right now to further help you in this task?
ChatGPT should then generate suggestions for useful prompts that you could use on it to
strengthen its further responses.

6.4.2 Model-Guided Prompting


Model-guided prompting involves instructing the LLM to prompt you for the information
needed to complete a requested task. This is similar to telling someone, “ask me what you
need to know.”


I would like you to write a Python program to manage my client information,
which is stored in a Google Sheet. Please ask me whatever questions you need


answers to in order to undertake this assignment.
Leaving it to ChatGPT to decide what information it needs to perform a task can benefit,
as it takes out some guesswork and discourages hallucination. Of course, a poorly crafted
prompt for model-guided prompting could leave you fielding several unrelated questions from
ChatGPT, so the initial prompt still needs to be thoughtfully written.

6.5 Summary
Once you become comfortable with the prompt engineering strategies, you can search out
other more complex, high-performance approaches. These strategies include tree of thoughts,
reflexion, and self-consistency, among others. Additional strategies are being developed
regularly; no doubt that between the time this was written and when you are reading it,
there have been some interesting developments on this front.
Remember, the point of prompt engineering is to convey your intentions and desires to
ChatGPT in a way that can be clearly and unambiguously understood by the LLM, so that it
can act upon the request in such a way that produces the desired output as closely as possible.
If you keep this in mind, move forward with the presented strategies, and hone your prompt
engineering skills through regular practice, you will find ChatGPT a genuinely helpful junior
assistant, willing and able to help whenever needed.
Just so long as you ask it properly.
In the next chapter, you will see examples of using ChatGPT for brainstorming.
Strategies for Effective
Brainstorming with ChatGPT
7
ChatGPT demonstrated its capability for a broad knowledge base, but it is also a fantastic
brainstorming and ideation tool. You can ask it to devise a complete project plan by framing
requests or providing wide-ranging responses to open-ended questions, supplementing and
extending human creativity.
In this chapter, you will learn to write detailed ChatGPT prompts for exploring
brainstorming capabilities. Specifically, you will learn:
⊲ How to plan a detailed Euro trip from Pakistan
⊲ How to plan a dinner for a family of five
⊲ Learn tips on improving the brainstorming and planning prompts.
Let’s get started.

Overview
This chapter is divided into three parts; they are:
⊲ Plan a Detail EuroTrip
⊲ Plan a Dinner for a Family
⊲ Tips on Maximizing ChatGPT’s Brainstorming Capabilities

7.1 Plan a Detail EuroTrip


Let’s plan a 2-week long Europe Trip from Pakistan. As usual, you need to give details to the
prompt to drive a more useful response. For example, let’s ask ChatGPT to provide various
trip options based on duration and budget. You specified in the prompt:
⊲ Actor: A professional travel agent.
⊲ Request: How to plan for a two-week trip to Europe from Pakistan.
⊲ Interest: Outdoor adventure.
⊲ Budget: USD 3000.
7.1 Plan a Detail EuroTrip 35

So the prompt would be:


Act as a professional travel agent and provide at least three detailed itinerary
options spanning the entire two-week trip to Europe from Pakistan. Each
option should include 3–5 destinations in a logical geographic sequence. Assume
the traveler is interested in blending city sightseeing with outdoor or cultural


experiences and a USD 3000 budget.
The following is the output you may find from ChatGPT:


Option 1: Eastern Europe Discovery
Duration: 14 days
Budget: USD 3000
Day 1-3: Prague, Czech Republic

⊲ Explore the historic Old Town, visit Prague Castle, and stroll across the
Charles Bridge.
⊲ Enjoy panoramic views from the Petřín Tower and visit the Astronomical
Clock.
⊲ Experience the vibrant nightlife and try traditional Czech cuisine.
Day 4-6: Budapest, Hungary
⊲ Take a relaxing cruise along the Danube River, passing by iconic landmarks.
⊲ Visit Buda Castle and admire the stunning views from Fisherman’s Bastion.
⊲ Relax in the thermal baths, such as Széchenyi or Gellért Baths.
⊲ Explore the ruin bars and enjoy Hungarian delicacies.
Day 7-9: Krakow, Poland
⊲ Discover the historic center and visit the Royal Wawel Castle.
⊲ Explore the somber history of Auschwitz-Birkenau Memorial and Museum.
⊲ Take a day trip to the beautiful Wieliczka Salt Mine.
⊲ Sample traditional Polish dishes like pierogi and bigos.
Day 10-12: Vienna, Austria
⊲ Visit the majestic Schönbrunn Palace and explore its gardens.
⊲ Marvel at St. Stephen’s Cathedral and the Belvedere Palace.
⊲ Attend a classical music concert or opera performance.
⊲ Try Viennese coffee and Sachertorte cake in a traditional café.
Day 13-14: Salzburg, Austria
⊲ Take a Sound of Music tour and visit filming locations.
⊲ Explore the baroque architecture of the historic Old Town.
⊲ Visit Mozart’s birthplace and enjoy a concert at the Mozarteum.
7.1 Plan a Detail EuroTrip 36

⊲ Hike or take a cable car up to the Fortress Hohensalzburg for panoramic


views.
Option 2: Mediterranean Delights
Duration: 14 days
Budget: USD 3000


...
ChatGPT provided three options in detail. Let’s say to select the third option called “Central
Europe Highlights”. You can ask for the itinerary in the follow-up question:


I like option 3: Central Europe Highlights. Please list the itinerary that I have to


do before traveling to Europe.
The response would begin with the following:


Certainly! Here’s a detailed itinerary for your Central Europe Highlights trip.
Before traveling to Europe, it’s essential to take care of the following preparations:
1. Research and Planning:
⊲ Familiarize yourself with the visa requirements for European
countries and apply if necessary.
⊲ Check the validity of your passport and ensure it has at least six
months of validity beyond your planned departure date.
⊲ Research the local customs, currency, and transportation options in
each destination.
⊲ Create a budget for accommodations, transportation, meals, and
activities.
2. Flights:
⊲ Search for flights from Pakistan to Berlin, Germany, as your starting
point.


...
The travel preparation involves research and planning, booking flights, accommodations,
intercity transport, travel insurance, sightseeing and activities, currency exchange and finances,
and vaccination. However, as a language model, the response from ChatGPT is not always
accurate and complete. ChatGPT has ignored that citizens of Pakistan need a visa to enter
Europe. Therefore, you need another follow-up question:


As a Pakistani, we need a Schengen visa to enter Europe. Can you tell me the


process of getting a visit visa for Germany?
This is what ChatGPT responded:


Certainly! To travel to Germany as a Pakistani citizen, you will need to apply for
a Schengen visa. Here’s an overview of the process for obtaining a visit visa for
Germany:
1. Determine the type of visa:
7.2 Plan a Dinner for a Family 37

⊲ If you are planning a tourist trip, you will need to apply for a Schengen
Tourist Visa (Type C).
⊲ If you plan to visit friends or relatives, you may need to apply for a
Schengen Visitor Visa (Type C) or a specific visa for that purpose.
2. Gather the required documents:


...
Securing a visitor visa involves several key steps. Determining the appropriate visa category
based on trip purpose and duration of stay establishes the foundation, while assembling the
required application documents like passport, proof of funds, travel itinerary, and occupation
documentation lays the groundwork.
While we can continue refining the itineraries by asking additional clarifying questions,
the initial brainstorming phase is now completed.

7.2 Plan a Dinner for a Family


Planning a dinner every day can be difficult, and if you are not a regular cook, it can be
challenging even to get proper groceries to make a dish. In these examples, you will ask
ChatGPT a direct question and use follow-up prompts to finalize the dinner preparation. In
your prompt, you should cover:
⊲ Actor: A super mom.
⊲ Request: Plan a dinner for five.
⊲ Time: 2 hours.
⊲ Type: Italian.
Then, the prompt would be as follows:


Suppose you are a super mom with 10 years of experience in cooking dinner for


the family. How would you plan an Italian-style dinner for 5 in 2 hours at home?
The response from ChatGPT is as follows:


As a super mom with 10 years of cooking experience, I’m here to help you plan
a delicious Italian-style dinner for your family of five in just two hours. Here’s a
step-by-step guide to make the most of your time:
1. Plan the menu: Choose a variety of dishes that encompass different
components like appetizers, main course, sides, and dessert. Here’s a sample
menu to get you started:
⊲ Appetizer: Bruschetta with tomato and basil.
⊲ Main Course: Spaghetti Carbonara.
⊲ Side Dish: Caprese Salad.
⊲ Dessert: Tiramisu.
2. Make a shopping list: Go through the recipes for each dish and list down
the ingredients you’ll need. Check your pantry to see if you already
7.3 Tips on Maximizing ChatGPT’s Brainstorming Capabilities 38


...
From the above, you got a list of dishes, a shopping list, prep work, how to manage the time,
and serving. There are 4 courses: Appetizer(Bruschetta with tomato and basil) main course
(Spaghetti Carbonara), side dish (Caprese Salad), and dessert (Tiramisu).
Of course, you can ask a follow-up question to find the recipe. You can simply refer to
“the dishes” without repeating the name since ChatGPT can remember what it answered:

“ ”
Now, write down a detailed plan for making all of the dishes on the menu.
The recipes as provided by ChatGPT are as follows:


Bruschetta with Tomato and Basil:
⊲ Preheat the oven to 375°F (190°C).
⊲ Slice a baguette into ½-inch thick slices.
⊲ Arrange the baguette slices on a baking sheet and brush them with olive
oil.
⊲ Toast the slices in the preheated oven for about 8-10 minutes or until golden
and crisp.
⊲ In the meantime, dice ripe tomatoes and finely chop fresh basil leaves.
⊲ In a bowl, combine the tomatoes,


...
After that, you can continue refining the recipe by providing follow-up prompts to modify
elements like ingredients, cooking methods, and flavor profiles based on your preferences and
available items.

7.3 Tips on Maximizing ChatGPT’s Brainstorming Capabili-


ties
In the previous examples, we have employed a direct and detailed plan for brainstorming, but
also be open and vague in your initial prompt. For example, say, “I need ideas for ...” rather
than stating a specific problem.
Moreover, you can:
1. Ask for multiple options or suggestions. For example: “Provide me with 3–5 ideas for
an Italian dish”
2. Provide examples of existing ideas as a starting point.
3. Consider adding more details to the idea after ChatGPT’s initial responses.
4. Read the responses and ask follow-up questions to refine, expand, or modify the most
promising ideas.
5. Ask ChatGPT to explain or justify its ideas to evaluate their merits.
6. Keep asking ChatGPT to modify the idea based on available resources and constraints.
7.4 Summary 39

Brainstorming, in general, can be a challenging task that involves exploring different options
and formulating a plan based on personal preferences. However, ChatGPT can simplify
brainstorming by offering various options and explanations. Although ChatGPT can assist,
it’s important to communicate your interests and adjust to your specific goals effectively. By
actively engaging with ChatGPT and refining the suggestions provided, you can optimize the
brainstorming experience and achieve better outcomes.

7.4 Summary
In this chapter, we delved into the powerful brainstorming capabilities of ChatGPT through
a series of practical examples. Specifically, we covered:
⊲ How to write a brainstorming prompt for planning a two-week trip to Europe, including
tips on narrowing down your options and prioritizing your itinerary.
⊲ How to use direct and detailed methods to plan a dinner party for five, and leverage
ChatGPT’s capabilities to explore recipes and cooking methods.
⊲ Tips on crafting open-ended and flexible prompts for brainstorming, adding more
details as you go along, and adapting your ideas based on available resources.
In the next chapter, you will learn about how to treat ChatGPT as an expert to give you
advises.
ChatGPT as Your Expert Helper
8
ChatGPT can help us learn new programming languages, courses, techniques, and skills. It
has become a go-to tool for many professionals seeking to improve their workflows or learn
something new. ChatGPT expert helper prompts can reduce our dependence on Google and
provide detailed plans for achieving goals.
In this chapter, you will learn to leverage simple ChatGPT prompts for learning a technique
or performing specialized tasks. Specifically, you will learn how to:
⊲ Generate instructions for training a model on a TPU (Tensor Processing Unit).
⊲ Generate detailed instructions for safely cutting down a tree.
⊲ Craft expert helper prompts.
Let’s get started.

Overview
This chapter is divided into three parts; they are
⊲ Accelerating Machine Learning Models with TPUs
⊲ A Guide to Safely Cutting Down a Tree
⊲ Tips on Writing Expert Helper Prompts

8.1 Accelerating Machine Learning Models with TPUs


In the first example, you will address a specialized issue many data scientists may be unaware
of. Most engineers currently utilize GPUs (Graphics Processing Units) or multiple GPUs to
accelerate machine learning model training. However, TPUs (Tensor Processing Units) can
provide even faster training times. You may not be able to find many instructions to use
TPUs, but you can ask ChatGPT for help by writing a correct prompt.
In your prompt, you should define:
⊲ Actor: ChatGPT should behave as a professional Machine Learning Engineer.
⊲ Request: write code for training image classifier on TPU.
8.1 Accelerating Machine Learning Models with TPUs 41

⊲ Environment: Google Colab.


For example, the prompt can be the following:


Act as a professional Machine Learning Engineer and write the Python code
for training the TensorFlow Image classification model on TPU. The computing


environment is Google Colab.
This is the output you may see from ChatGPT’s response:

import tensorflow as tf

# Check if TPU is available


try:
tpu = tf.distribute.cluster_resolver.TPUClusterResolver() # TPU detection
tf.config.experimental_connect_to_cluster(tpu)
tf.tpu.experimental.initialize_tpu_system(tpu)
strategy = tf.distribute.experimental.TPUStrategy(tpu)
print("Running on TPU:", tpu.master())
except ValueError:
strategy = tf.distribute.OneDeviceStrategy("GPU")
print("Running on GPU or CPU")

# Load and preprocess your dataset


# Replace `your_dataset` with your own dataset loading and preprocessing code

# Define the model architecture


# Replace `your_model` with your own model architecture

# Compile the model


# Replace `your_loss`, `your_metrics`, and `your_optimizer` with appropriate values
with strategy.scope():
model = your_model
model.compile(loss=your_loss, metrics=your_metrics, optimizer=your_optimizer)

# Define training parameters


# Replace `your_epochs` and `your_batch_size` with appropriate values
epochs = your_epochs
batch_size = your_batch_size

# Train the model


# Replace `your_training_data` with your own training data
model.fit(your_training_data, epochs=epochs, batch_size=batch_size)

# Evaluate the model


# Replace `your_test_data` with your own test data
loss, accuracy = model.evaluate(your_test_data)
print("Test loss:", loss)
print("Test accuracy:", accuracy)

Listing 8.1: Python code produced by ChatGPT

The ChatGPT example demonstrates how to train a model on TPU by generating Python
code with placeholders. To properly execute the code, you must replace the placeholders with
8.2 A Guide to Safely Cutting Down a Tree 42

your dataset loading and preprocessing code, model architecture, loss function, evaluation
metrics, optimizer, training parameters, training data, and test data.
After replacing the code, you can copy and paste it into a new Colab notebook and run
the code with TPU hardware acceleration. The code you obtained may not be fully executable
and may contain some bugs. However, you should be able to identify them and correct them
easily.

Output from ChatGPT is not always correct. You must verify the accuracy using
INFO-CIRCLE other means.

8.2 A Guide to Safely Cutting Down a Tree


In the second example, you will focus on the non-technical techniques required to cut down
the tree safely. To get appropriate instructions, you must provide sufficient circumstances in
the prompt, such as:
⊲ Actor: ChatGPT should behave as an experienced professional arborist.
⊲ Request: List down the steps required for cutting down a tree safely.
⊲ Environment: The tree is Box Elder, 50 feet tall, in between two houses.
⊲ Location: Suburbs, Mountain View, and California.
As an example, the prompt to ChatGPT can be:


Act as an experienced professional arborist and list the critical safety procedures
for removing a 50-foot-tall Box Elder tree located between two houses in a suburban


neighborhood in Mountain View, California.
This is what you may see in the output:


As an experienced professional arborist, I can provide you with a list of critical
safety procedures for removing a 50-foot-tall Box Elder tree located between two
houses in a suburban neighborhood in Mountain View, California. It’s important
to note that tree removal can be dangerous, and I highly recommend consulting
with a certified arborist or tree removal professional for such a task. Nevertheless,
here are some general safety procedures to consider:
1. Perform a thorough assessment: Before starting the tree removal process,
assess the tree’s condition, potential hazards, and the surrounding area.
Look for signs of decay, disease, or structural weaknesses that may affect
the tree’s stability.
2. Obtain necessary permits: Check with the local authorities and obtain
any required permits or permissions for tree removal in Mountain View,
California. Compliance with local regulations is crucial to ensure safety
and avoid legal issues.
3. Use proper personal protective equipment (PPE): Wear appropriate PPE,
including a hard hat, safety glasses, ear protection, gloves, and sturdy, non-
8.2 A Guide to Safely Cutting Down a Tree 43

slip boots. PPE helps protect against falling debris and other potential
hazards.
4. Establish a safety zone: Clearly mark and secure the area around the tree
to prevent unauthorized access. Use caution tape or barricades to keep
pedestrians and vehicles away from the work zone.
5. Plan for equipment and personnel: Determine the necessary equipment,
tools, and personnel required for safe tree removal. This may include
chainsaws, ropes, rigging equipment, and an experienced crew.
6. Engage in proper pruning techniques: If necessary, perform tree pruning to
remove dead branches or reduce the tree’s weight before the main removal
process. Proper pruning techniques help prevent accidents and control the
tree’s fall direction.
7. Conduct controlled tree felling: When felling the tree, employ proper cutting
techniques to ensure a controlled fall. Consider the tree’s lean, surrounding
obstacles, wind direction, and other factors that might influence its fall path.
8. Use rigging and lowering devices: If the tree’s location poses a risk to nearby
structures or obstacles, utilize rigging and lowering devices to safely control
the tree’s descent. This technique helps minimize the potential for property
damage and injury.
9. Perform tree removal in sections: When dealing with larger trees, it’s
often safer to remove them in sections. This involves carefully cutting and
lowering smaller portions of the tree to the ground rather than attempting
to fell the entire tree at once.
10. Use proper tree removal techniques: Follow industry best practices for
tree removal, including making precise cuts, avoiding excessive force, and
maintaining control throughout the process. Be aware of potential hazards
such as limb kickback and split wood.
11. Consider hiring professionals: Given the complexity and potential risks
involved in removing a 50-foot-tall tree between two houses, it’s strongly
recommended to engage the services of a certified arborist or experienced
tree removal company. Their expertise and specialized equipment will help
ensure a safe and efficient removal process.
Remember, tree removal can be extremely hazardous, especially when dealing with
large trees or those in close proximity to structures. Prioritizing safety at all times


is essential to protect yourself, your crew, and the surrounding property.
The list generated covered many important safety steps. However, removing a large tree
like the one described is a complex undertaking that likely requires specialized equipment,
trained personnel, required permits, proper techniques, access to key details, and contingency
planning. Even if you hire professionals, you need access to the tree’s location, area, and
spread before giving a green light.
8.3 Tips on Writing Expert Helper Prompts 44

In conclusion, it may not be a good idea to follow ChatGPT’s instructions to do such


work, even though it gives many details on how to do so. Hiring a certified arborist and
insured tree removal company to do this job may be a wiser decision.

8.3 Tips on Writing Expert Helper Prompts


Think of speaking with a real professional lawyer or doctor — you wouldn’t walk in and
vaguely say “I need help.” You would thoroughly explain the who, what, where, why, and
how behind your specific request. The same principle applies when using ChatGPT expert
helpers.
To generate effective expert helper prompts with ChatGPT, provide it with as much
relevant context as possible. Explain:
⊲ The role or profession of the expert you want assistance from. Be specific. For example:
“a certified arborist”
⊲ The nature of the task or request. Be clear, direct, and provide key details. For
example: “Safely remove this 50-foot tall tree between two houses.”
⊲ Any variables, constraints, or conditions that impact the situation. Give
measurements, locations, and specifications as needed.
⊲ Environmental factors, circumstances, or obstacles that introduce complexity.
⊲ The required outcome or goal you hope to achieve.
The more accurate, specific, and robust the description of your scenario, the more precise
and useful ChatGPT’s response will likely be. ChatGPT’s ability to simulate an “expert”
is constrained by the clarity and completeness of the information you provide to frame the
context.

8.4 Summary
In this chapter, we discussed how to craft ChatGPT expert helper prompts to generate helpful
responses. Specifically, we covered:
⊲ How to write a well-explained prompt for accelerating machine learning models training
with TPUs.
⊲ How to generate a list of the critical safety procedures for removing a tree. It is more
complex than you think.
⊲ Tips for crafting more targeted prompts that provide a clear description of the task
from the perspective of the relevant expert include necessary variables and a defined
objective.
In the next chapter, you will see how you can make ChatGPT to help you write paragraphs
of text.
Writing an Essay with ChatGPT
9
ChatGPT is a language model that you can use by talking to it. A language model in such
a scale can naturally produce fluent text that is difficult to tell apart from work by humans.
If you want to use it for a task, you will likely still need to provide detailed instructions.
Moreover, you should also not expect it to replace humans entirely. You would likely need to
do the final polishing.
In the following, you will use ChatGPT to produce an essay. Specifically, you will learn
⊲ How to guide break down your task into steps for ChatGPT
⊲ How to guide ChatGPT step by step to make an essay
Let’s get started.

Overview
This chapter is divided into four parts; they are:
⊲ Topic of the Essay
⊲ Straightforward Instruction
⊲ Guiding ChatGPT to Write Step-by-Step
⊲ How It Works

9.1 Topic of the Essay


For example, consider the sample task for GRE analytical writing1 . It is part of the Graduate
Record Examination for college students applying for admission to graduate schools. It aims to
demonstrate the ability to explain your reasoning in a statement. A high-score essay should
provide relevant reasons to support your point of view but avoid overly general examples
without expansion.
Consider the statement in the GRE sample:

1
https://www.ets.org/pdfs/gre/sample-issue-task.pdf
9.2 Straightforward Instruction 46


As people rely more and more on technology to solve problems, the ability of


humans to think for themselves will surely deteriorate.
Let’s see how ChatGPT responds if you ask it to write such an essay.

9.2 Straightforward Instruction


The simplest way of using ChatGPT is to ask it to give you an essay directly by the following
prompt:


Write an essay in support of the following statement:
As people rely more and more on technology to solve problems, the ability of


humans to think for themselves will surely deteriorate.

Figure 9.1: Instructing ChatGPT to write the entire essay

The result would differ each time you run it due to the system’s randomness. One result
would be the following:


The increased reliance on technology in modern times has undoubtedly made life
easier for people. From automated manufacturing processes to virtual personal
assistants, technology has become an integral part of our lives. However, as people
become increasingly dependent on technology to solve problems, the question
arises: will our ability to think for ourselves deteriorate?
It is a well-established fact that the human brain is like a muscle that needs
regular exercise to remain strong and healthy. When we solve problems using our
own mental faculties, we are essentially exercising our brain and enhancing our
cognitive abilities. However, when we rely solely on technology to solve problems,
we are not using our own brainpower and are essentially outsourcing our thinking
to machines.
9.3 Guiding ChatGPT to Write Step-by-Step 47

One of the most significant consequences of relying too much on technology is the
deterioration of critical thinking skills. Critical thinking involves analyzing and
evaluating information, identifying biases and assumptions, and making informed
judgments based on evidence. When we rely on technology to solve problems,
we tend to become passive consumers of information, accepting whatever the
technology presents to us without questioning its accuracy or reliability. This
lack of critical thinking can lead to poor decision-making and an inability to solve
complex problems on our own.
Moreover, technology can also contribute to a decline in creativity and innovation.
When we use technology to solve problems, we are limited by its capabilities and
functionalities. In contrast, when we think for ourselves, we are free to explore
new and unconventional ideas and come up with creative solutions to problems.
Overreliance on technology can stifle our creativity and prevent us from discovering
new and innovative solutions to the challenges we face.
Another negative consequence of relying too much on technology is the loss of
social skills. Social interaction is essential for the development of interpersonal
skills, such as communication, empathy, and conflict resolution. When we rely on
technology for communication, we miss out on the subtle nuances of face-to-face
interaction, which are critical for building meaningful relationships. This can lead
to a lack of social skills and difficulty in building and maintaining relationships
with others.
In conclusion, while technology has undoubtedly made our lives easier and more
convenient, it is important to recognize the potential negative consequences of
overreliance on technology. As we continue to integrate technology into our lives,
we must ensure that we do not become overly dependent on it to solve problems.
We must continue to exercise our critical thinking skills, nurture our creativity,
and maintain our social skills to ensure that we remain competent and independent


problem solvers.
This looks very natural and not bad as an essay. But indeed, it is not top-notch. You can get
a better essay if you know how to ask better.

9.3 Guiding ChatGPT to Write Step-by-Step


A language model can generate text based on the context. In the example of ChatGPT,
the context is the recent dialog between you and the system. Moreover, the response from
ChatGPT is not produced all at once but one token at a time. Therefore, it remembered what
it said in the previous sentence, for example.
Because of that, it is difficult to “fine-tune” the answer if it gives you a large piece of
text. It is easier to break down an enormous writing task into smaller parts.
For the same topic as above, you can do it as follows:


Give me 3 paragraphs in support of the following statement, one argument in each
paragraph:
9.3 Guiding ChatGPT to Write Step-by-Step 48

As people rely more and more on technology to solve problems, the ability of


humans to think for themselves will surely deteriorate.
And now it produces the following:


Paragraph 1: As technology becomes more advanced, it is easier for people to rely
on it to solve problems. This can lead to a lack of critical thinking skills because
people may not be challenged to solve problems on their own. For example, people
who use GPS to navigate may not develop spatial awareness or map-reading skills,
which are important for problem-solving in many areas of life. In addition, people
who rely on calculators or computer programs to do math may not develop strong
mental math skills or an understanding of mathematical concepts. As a result,
their ability to think independently and solve problems may deteriorate.
Paragraph 2: In addition to reducing critical thinking skills, technology can also
have a negative impact on creativity. When people rely on technology to solve
problems, they may become less likely to think outside the box and come up
with creative solutions. This is because they are used to following pre-determined
algorithms or solutions provided by technology. This can be seen in the world of
art, where digital tools can be used to create artwork quickly and easily. While
these tools can be useful, they may also limit creativity by making it easier to
create conventional or derivative works.
Paragraph 3: Finally, the over-reliance on technology can lead to a reduction
in social skills. As people spend more time communicating through screens and
devices, they may have less practice interacting with others face-to-face. This can
make it harder for them to understand social cues, empathize with others, and
develop strong relationships. In addition, people who rely on technology for social
interaction may be more likely to experience feelings of loneliness and isolation.
This can have a negative impact on mental health, which can, in turn, affect overall


cognitive functioning and problem-solving abilities.
It looks better. The first paragraph especially has a concrete example. But no examples are
given in the other two paragraphs. Let’s continue on the chat to ask for more examples:


Can you give some concrete examples of how technology negatively impacts


creativity?
It answers:


Certainly! Here are a few examples of how technology can negatively impact
creativity:
Template-driven design: Many digital tools, such as website builders, offer pre-
designed templates that users can customize with their own content. While these
templates can be helpful for beginners, they can also stifle creativity by limiting
design options and encouraging conformity.
Dependence on filters: Social media platforms like Instagram offer a variety of
filters that users can apply to their photos to enhance their appearance. While
these filters can be fun to use, they can also discourage creativity by making it
easy to create generic, highly stylized images that all look the same.
9.3 Guiding ChatGPT to Write Step-by-Step 49

Auto-correction and predictive text: While these features can be helpful for
avoiding typos and speeding up the writing process, they can also lead to a lack of
creativity in writing. For example, if someone relies too heavily on auto-correction,
they may not take the time to learn proper spelling or grammar, which can limit
their ability to express themselves creatively through writing.
Algorithmic recommendations: Streaming services like Netflix and Spotify use
algorithms to recommend content to users based on their viewing or listening
history. While this can be helpful for discovering new content, it can also limit
creativity by promoting similar content and discouraging users from exploring new
genres or artists.
Overall, while technology can be a powerful tool for enhancing creativity, it’s
important to be aware of its potential limitations and actively work to avoid


falling into creative ruts or becoming too dependent on digital tools.
It needs to be more concise since the GRE analytical writing is only roughly 500 to 600 words.
However, these examples are helpful. You can further ask for examples regarding the third
paragraph it originally produced:


Can you give some concrete examples of how technology can lead to a reduction


in social skills? Be brief.
Now it answered:


Sure, here are some examples of how technology can lead to a reduction in social
skills:
Overreliance on texting and social media can lead to a lack of face-to-face
communication skills and make it harder to pick up on social cues.
Spending excessive amounts of time on screens can lead to social isolation and
feelings of loneliness.
The anonymity of online communication can lead to a lack of empathy and an
increase in cyberbullying.
Online dating and social networking apps can reduce opportunities for in-person
social interaction and make it harder to form deep, meaningful relationships.
Constant access to technology can create a distraction from real-world social
situations and lead to a lack of engagement and attention in face-to-face


conversations.
That’s good. Note that these examples are not in paragraph form because you needed to
specify how ChatGPT should answer. But it is not difficult for you to incorporate these into
your essay paragraphs.

Getting insight and input from ChatGPT and polish further into the format you
INFO-CIRCLE desired should be the better way to use the tool, rather than asking ChatGPT
to generate the final result in one shot.
9.3 Guiding ChatGPT to Write Step-by-Step 50

Now we still need an introduction and a conclusion to complete the essay. Let’s ask
ChatGPT to do these.

“ ”
Please write an introduction paragraph for the above.
This is what it produced:


Technology has undoubtedly transformed the way we live our lives, from how we
work and communicate to how we access information and solve problems. While the
benefits of technology are numerous and undeniable, there are also some negative
consequences to our over-reliance on digital tools. One such consequence is a
reduction in social skills. As people spend more time communicating through
screens and devices, they may have fewer opportunities to practice face-to-face
communication skills, leading to a decline in social awareness and empathy. In
this context, it is worth exploring some concrete examples of how technology can


negatively impact our social skills and what we can do to mitigate these effects.
For the conclusion, you want to reference the main content of your essay. You shouldn’t worry
since ChatGPT remembers the conversation. You can ask:

“ ”
Please write a conclusion paragraph to summarize everything above.
and it answered:


In conclusion, while technology has many positive effects on our lives, it is essential
to recognize that there are also some negative consequences, such as a reduction
in critical thinking skills, creativity, and social skills. Technology can provide
shortcuts and instant gratification that can ultimately lead to the erosion of
essential skills. It is crucial to be aware of these potential drawbacks and take
steps to mitigate their effects, such as setting limits on screen time, engaging in
face-to-face communication, and finding ways to use technology in a balanced and
mindful way. By doing so, we can continue to benefit from the many advantages
of technology while also ensuring that we maintain the skills and connections that


make us human.
With a bit of reordering and polishing, you now have a complete essay.
9.4 How It Works 51

Figure 9.2: Instructing ChatGPT to write the essay in steps

9.4 How It Works


ChatGPT can do this task well because it is trained with a massive dataset. Hence, many
“facts” are remembered by the model that helps writing this essay. If you try this with a
smaller model, such as those you can run with GPT4All on your computer, you may find the
result less informative.
However, based on the principle behind its architecture, words are chosen based on the
highest correlation to both the prompt you provided and the content it generated previously.
Therefore, the more precise you set up your prompt, the model should be able to generate a
better response.
Nonetheless, you should not expect this to be perfect. Firstly, the prompt has a size
limit, so you can never outline all your intent. Secondly, even with no limit, it is difficult to
put all details in the prompt due to your cognitive bias. Lastly, due to the training provided
to it, such a model would prefer the most common words over the best words for the context.
This is also why we found that works produced by ChatGPT can earn a passing grade, but
never excellent.

9.5 Summary
In this chapter, you discovered how ChatGPT can help you write an essay. In particular, you
learned:
⊲ ChatGPT can write you an essay in one shot with a short guidance
⊲ You can break down the task into multiple steps to make ChatGPT produce a more
detailed response
9.5 Summary 52

⊲ ChatGPT can reference the dialog with you in creating new responses
In the next chapter, you will learn how to make ChatGPT to guide you to learn something.
Using ChatGPT as Your
Personalized Teacher
10
Machine Learning and Data Science are the two most essential technologies in Industry
4.0. Data Science refers to extracting meaningful insights from data, while Machine Learning
enables the computer to learn independently without being explicitly programmed. Mastering
these fields requires a solid understanding of fundamental concepts, hands-on experience, and
guidance from mentors. Traditional learning methods, like attending lectures, reading books,
making notes, etc., can be inflexible, expensive, and time-consuming. This is where ChatGPT
can be your personalized tutor.
In this chapter, you will uncover the benefits of ChatGPT as a personal tutor for machine
learning and data science enthusiasts. In particular, you will learn
⊲ How to let ChatGPT guide you to learn abstract algebra
⊲ How to let ChatGPT help you prepare for a data science interview
Let’s get started.

Overview
This chapter is divided into three parts; they are:
⊲ Mastering Linear Algebra in 12 Weeks
⊲ Self-Quizzing for a Machine Learning Interview
⊲ Prompting Tips to Enhance Learning Experience

10.1 Mastering Linear Algebra in 12 Weeks


Let’s say you heard about linear algebra, interested in it but have no idea what it is. You
know that linear algebra is an important skill for becoming a data scientist. You want to
learn linear algebra seriously.
This is a good chance to let ChatGPT guide you by generating a lesson plan. To generate
relevant and accurate responses, your prompt should be specific and clearly state your end
objectives. You should cover in your prompt:
10.1 Mastering Linear Algebra in 12 Weeks 54

⊲ What do you want to learn?


⊲ Is your goal time-bound?
⊲ Is there something that you want to focus more on?
Keeping in view the above scenario, here is the basic template that you can use:


I am interested in mastering [Subject] with a focus on [Topic]. I would like to
create a [Number of Weeks/Months] study plan that will help me achieve this goal.
Can you please help me by:
1. [Subgoal-1]
2. [Subgoal-2]


...
You can also specify your current level of expertise. The following is an example of what you
prompted to ChatGPT:


I am interested in mastering abstract linear algebra with a focus on topics relevant
to data science and machine learning. I would like to create a 12-week study plan
that will help me achieve this goal.
Can you please help me by:
1. Identifying the key concepts that I need to learn in abstract linear algebra
weekly


2. Recommending the best resources for learning these concepts.
The response from ChatGPT was as follows:


Certainly! Here’s a breakdown of key concepts to learn in abstract linear algebra
weekly, along with recommended resources:
Week 1: Introduction to Linear Algebra and Vectors
Learn about the basic concepts of linear algebra, such as vectors, vector spaces,
and linear combinations.
Familiarize yourself with vector operations, including addition, subtraction, and
scalar multiplication.
Recommended resources:
“Introduction to Linear Algebra” by Gilbert Strang
“Linear Algebra and Its Applications” by David C. Lay
Week 2: Matrices and Matrix Operations
Study matrices, their representation, and operations like addition, subtraction,
and scalar multiplication.
Explore matrix multiplication and properties such as associativity and
distributivity.
Recommended resources:
“Linear Algebra and Its Applications” by David C. Lay
“Linear Algebra Done Right” by Sheldon Axler
Week 3: Systems of Linear Equations
10.1 Mastering Linear Algebra in 12 Weeks 55

Understand systems of linear equations and their solutions.


Learn about Gaussian elimination, row echelon form, and reduced row echelon
form.
Explore concepts of rank, null space, and column space.
Recommended resources:
“Introduction to Linear Algebra” by Gilbert Strang
“Linear Algebra and Its Applications” by David C. Lay


...
As ChatGPT has a maximum token limit for each response so if you experience an incomplete
response, you can use this prompt:

“ ”
Can you please continue and complete your response?
Now you get a complete roadmap with topics relevant to your end goal and all the resources
you need per topic. Is that enough? You may also want ChatGPT to summarize the topic
and provide some practice questions to solidify your understanding. In this case, you can use
a follow-up prompt to create an interactive learning experience.


Thank you for sharing the 12-week schedule. I am excited to get started!
Can you please explain the first concept of Week 1
with examples? I would also appreciate it if you could provide the practice problems


to solidify my understanding of the concept.
The response from ChatGPT was:


Certainly! In Week 1, the first concept is “Introduction to Linear Algebra and
Vectors.” Let’s dive into it:
Concept Explanation:
Linear algebra is a branch of mathematics that deals with vector spaces and linear
transformations.
Vectors are mathematical objects that have both magnitude and direction, and
they are fundamental in linear algebra.
Vectors can be represented as column vectors or row vectors and can have various
dimensions.
Example:
Let’s consider a two-dimensional vector represented as v = [2, 5]. Here, the vector
has two components: 2 and 5. The first component (2) represents the magnitude
or value in the x-direction, and the second component (5) represents the magnitude
or value in the y-direction.
Practice Problems:
Given vectors u = [1, -3] and v = [4, 2], calculate the sum u + v.
Determine the magnitude (length) of the vector u = [3, -4].
Find the unit vector in the same direction as v = [2, 7].
Given the vectors u = [1, 2, 3] and v = [4, -1, 0], calculate the dot product u · v.
Verify whether the vectors u = [1, 2, -3] and v = [-2, 4, -6] are parallel (collinear)
by checking if one is a scalar multiple of the other.
10.2 Self-Quizzing for a Machine Learning Interview 56

Solving these practice problems will help solidify your understanding of vectors


and their properties. Good luck!
With the help of ChatGPT, you are now able to master the concepts of abstract linear algebra.
You can learn effectively and have a virtual tutor available 24/7 to clear your doubts and
suggest additional resources for better understanding.

10.2 Self-Quizzing for a Machine Learning Interview


Let’s consider another example.
Assume you are interviewing for the job of Junior Machine Learning Engineer. To perform
better in the interview, you should train yourself to think fluently for the interview questions.
Can you make ChatGPT help you practice for the interview?
A good prompt is important. It is better to divide the problem statement into sub-goals,
which you can use this basic template:


I want you to act as my [Subject/Position] Interviewer. Conduct my [Interview
Type] interview for the [Position/Role]. Please ask me a series of questions to
evaluate my knowledge and skills in [Areas], and provide feedback on my responses


unless I ask you to stop.
So this is the prompt you feed into ChatGPT:


I want you to act as my Machine Learning Interviewer. Conduct my technical
interview for the Junior Machine Learning Engineer position. Please ask me a
series of questions to evaluate my knowledge and skills in machine learning, and


provide feedback on my responses unless I ask you to stop.
Which you may see this response from ChatGPT:


Sure! I’d be happy to conduct your technical interview for the Junior Machine
Learning Engineer position. I’ll ask you a series of questions related to machine
learning, and I’ll provide feedback on your responses. Let’s begin! Question
1: What is the difference between supervised learning and unsupervised learning?
Provide examples of each. (Note: Feel free to take your time and provide a detailed


response. I’ll wait for your answer before proceeding to the next question.)

Scenario 01: Providing Correct and Detailed Response


If you have a solid understanding of the asked concept, you may provide a detailed and correct
response, such as the following:


In Supervised learning, we have a labeled dataset while in Unsupervised Learning
we have an unlabeled dataset. For example, sentiment analysis can be an example of
supervised learning where the text has been labeled with correct output for training
purposes. Clustering the unlabeled dataset into groups based on similarities is an


example of an unsupervised learning problem
Then ChatGPT will appraise you:
10.2 Self-Quizzing for a Machine Learning Interview 57


Great job on explaining the difference between supervised and unsupervised
learning! You correctly mentioned that supervised learning involves using labeled
data, where the algorithm learns from input-output pairs to make predictions or
classifications. Sentiment analysis is indeed a good example of supervised learning,
where sentiment labels (positive, negative, neutral) are provided for training.
You also mentioned unsupervised learning correctly. In unsupervised learning,
the algorithm works with unlabeled data to find patterns, structures, or groupings
in the data. Clustering is a commonly used technique in unsupervised learning,
where similar data points are grouped based on their features or attributes.
Overall, your response demonstrates a good understanding of the difference between
supervised and unsupervised learning, and you provided relevant examples. Well
done!
Let’s move on to the next question.
Question 2: What is the purpose of regularization in machine learning algorithms?


How does it help in preventing overfitting?

Scenario 02: Concise but Correct Response


However, if you know what is “regularization” but not aware of the ins and outs, you may be
able to provide only a short answer:

“ ”
Regularization adds a penalty to the loss function hence preventing overfitting
In this case, ChatGPT will tell you to enrich your answer:


That’s a good start! Regularization is indeed used to prevent overfitting in machine
learning algorithms. Let me provide you with a more detailed explanation.
Regularization is a technique that introduces a penalty term to the loss function
during training. The penalty term is based on the complexity or magnitude of the
model’s parameters. The purpose of this penalty term is to discourage the model
from fitting the training data too closely, which can lead to overfitting.
Overfitting occurs when a model becomes too specialized in capturing the noise
or idiosyncrasies of the training data, resulting in poor generalization to unseen
data. Regularization helps to address this issue by adding a regularization term to
the loss function, which controls the complexity of the model. The regularization
term encourages the model to find a balance between fitting the training data well
and keeping the model’s parameters small or constrained.
By including regularization, the model is penalized for having large or complex
parameter values, which helps prevent overfitting. It encourages the model to
generalize better to unseen data by finding a simpler and more robust representation
of the underlying patterns in the data.
In summary, regularization adds a penalty to the loss function to prevent overfitting
by discouraging complex or large parameter values in the model. This promotes
better generalization to new, unseen data.
10.2 Self-Quizzing for a Machine Learning Interview 58

Well done on your response! If you have any questions or would like to discuss


further, feel free to let me know before moving on to the next question.
You can observe how ChatGPT provided a detailed explanation of the concept. It also allows
you to clear any of your concerns before it can move over to the next question just like a real
tutor.
Isn’t it cool? Now, let us move over to our last scenario by first prompting ChatGPT to
continue with the next question. Then it may respond with:


Of course! Let’s proceed to the next question.
Question 3: Explain the bias-variance tradeoff in machine learning and its
relationship to model complexity.
(Take your time to provide a detailed response, and feel free to ask for clarification


if needed.)

Scenario 03: Incorrect Response


Let’s say you did not know what is bias-variance tradeoff and gave an incorrect response:


The bias-variance tradeoff is a trade-off between the model’s accuracy and its
complexity. As the complexity of a model increases, bias increase and variance


decreases
In this case, you will see ChatGPT trying to correct you:


I appreciate your attempt at explaining the bias-variance tradeoff. However,
the relationship between bias and variance is slightly different than what you
mentioned. Allow me to provide a more accurate explanation:
The bias-variance tradeoff is a fundamental concept in machine learning that deals
with the relationship between the bias and variance of a model. Bias refers to the
error introduced by approximating a real-world problem with a simplified model,
making assumptions that may not hold. Variance, on the other hand, refers to the
model’s sensitivity to fluctuations in the training data, meaning it captures noise
or random variations rather than the true underlying patterns.
The tradeoff arises when adjusting the complexity of a model. A model with high
bias tends to be overly simplistic, making strong assumptions that may not match
the underlying data distribution. Such a model may have low accuracy on both
the training and testing data and is said to underfit the data. On the other hand, a
model with high variance captures the noise or random fluctuations in the training
data too closely. It may perform well on the training data but fails to generalize
to unseen data, a phenomenon known as overfitting.
Here’s how the tradeoff works: When you have a simple model with low complexity,
such as linear regression with few features or low polynomial degree, it generally
exhibits high bias and low variance. As you increase the complexity, say by adding
more features or increasing the polynomial degree, the model becomes more flexible
and can better fit the training data. However, this comes at the cost of potentially
10.3 Prompting Tips to Enhance Learning Experience 59

higher variance and lower bias. The model becomes more prone to overfitting and
may fail to generalize well to unseen data.
The goal is to strike a balance between bias and variance by finding an optimal
level of model complexity that minimizes the total error. This is typically achieved
through techniques like cross-validation, regularization, or ensemble methods that
combine multiple models.
In summary, the bias-variance tradeoff refers to the tradeoff between a model’s
bias and variance. Increasing complexity reduces bias but increases variance while
decreasing complexity increases bias but reduces variance. The aim is to find
the right level of complexity that minimizes the overall error and ensures good
generalization to unseen data.
A great effort in attempting to explain the bias-variance tradeoff! If you have any
further questions or if there’s anything you’d like me to clarify, please let me know


before we move on to the next question
You can see how ChatGPT explained how bias-variance trade-off works under the hood and
generated an even more detailed response to your incorrect answer.

10.3 Prompting Tips to Enhance Learning Experience


Whether you are preparing for an interview or creating a study plan, Here is a list of prompting
tips that will allow you to make the most out of your learning experience with ChatGPT as
your personalized tutor:
⊲ Clearly state your learning objectives and be specific. For example, instead of asking,
“Explain Data Preprocessing?” you can narrow down the scope and ask, “Can you
please describe the feature selection process in data preprocessing?”
⊲ Ask follow-up questions to obtain further clarification. You can ask for additional
examples or step-by-step explanations to better understand the concepts.
⊲ Instead of a one-sided query conversation, create an interactive conversation with
ChatGPT, enabling it to tailor the responses to your specific needs.
⊲ To bridge the gap between theory and practice, prompt the ChatGPT and ask for
practical examples and use cases.
⊲ Ask for feedback and possible improvements as it facilitates continuous improvement.

10.4 Summary
ChatGPT is a valuable tool that you can use to create a personalized learning environment.
It can adapt beautifully according to the progress of the learner. Here are the key takeaways
from this chapter:
⊲ ChatGPT can tailor the journey to address the strengths and weaknesses of the
individual.
⊲ Define your end goals and subgoals before drafting the initial prompt
10.4 Summary 60

⊲ Follow the prompting tips for a more dynamic conversation and relevant responses
In the next chapter, you will see evidence that ChatGPT is good at many languages.
Using ChatGPT for Translation
Effectively
11
ChatGPT has demonstrated its ability to handle translation tasks with surprisingly high
accuracy. While Google Translate has been the go-to tool for multilingual translation for
years, recent studies show that ChatGPT performs competitively with commercial translation
products in high-resource European languages.
ChatGPT’s strength as a translator goes beyond just natural language text. You can also
translate the code between different programming languages. Simply providing an initializing
prompt describing the translation you want, ChatGPT can often generate the converted code
within seconds with high accuracy.
In this chapter, you will learn how to use ChatGPT prompts to understand ChatGPT’s
Translation Capabilities. Specifically, you will learn how to:
⊲ Translate a poem from English to Swedish.
⊲ Translate code from Julia to Python.
⊲ Enhance translation results.
Let’s get started.

11.1 Overview
This chapter is divided into three parts; they are
⊲ Language Translation
⊲ Code Translation
⊲ Tips on Effective Translation

11.2 Language Translation


Before crafting a translation prompt, you must establish an initialization prompt providing
the context for the translator and text style. For our current task, you are translating a poem
by Robert Frost and will incorporate this information into the initialization prompt:

“ ”
You are a translation helper that translates English poems into Swedish.
11.2 Language Translation 62

Without providing a poem, ChatGPT will simply acknowledge your intention:


Sure! I can help you with translating English poems into Swedish. Please provide
me with the English poem you would like to have translated, and I’ll do my best


to assist you.
Your translation bot is now fully prepared and comprehensively understands the context. You
can proceed by requesting to translate the poem into Swedish. You provide the poem in your
second prompt:


Please convert the following poem from English to Swedish:
Nature’s first green is gold,
Her hardest hue to hold.
Her early leaf’s a flower;
But only so an hour.
Then leaf subsides to leaf.
So Eden sank to grief,
So dawn goes down to day.


Nothing gold can stay.
The following is what ChatGPT responded:


Sure! Here’s the translation of the poem “Nothing Gold Can Stay” by Robert
Frost into Swedish:
Naturens första gröna är guld,
Hennes hårdaste nyans att behålla.
Hennes tidiga löv är en blomma;
Men endast så en timme.
Sedan försvinner bladet till blad.
Så sjönk Eden i sorg,
Så gryningen går ner till dagen.
Ingenting guld kan bestå. I hope this translation captures the essence of the
original poem in Swedish. Let me know if there’s anything else I can assist you


with!

Validation
To confirm the accuracy of the translation, you can paste the translated poem into Google
Translate to get the English version. In this case, the translation is nearly flawless, which is
impressive given the difficulty of translating poetry. It successfully captures both the essence
and the meaning of the original poem.
11.3 Code Translation 63

Figure 11.1: Verifying the translation with Google Translate

11.3 Code Translation


In this section, you will ask ChatGPT to translate a simple number-guessing game from Julia
into Python.
Many programming languages look similar to each other. To ensure a successful code
translation, you must provide context through an initialization prompt. This prompt will
introduce the code translator and specify the type of code being translated:


You are a professional software engineer that has mastered both Julia and Python
programming languages. In this case, you will help me translate a simple Julia


game into Python.
Similar to the previous example, ChatGPT will acknowledge your instructions and wait for
the code from you:


Of course! I’d be happy to help you translate your Julia game into Python. Please
provide me with the code for the game in Julia, and I’ll assist you in converting


it to Python.
Now, ask ChatGPT to convert the following code into Python, using the following prompt:


Please convert the following Julia Code into Python:

```
function number_game()
secret_number = rand (1:100) # Generate a random secret number between 1 and 100
attempts = 0
println("Welcome to the Number Game!")
println ("I'm thinking of a number between 1 and 100. Can you guess it?")
while true
attempts += 1
guess = parse(Int, readline()) # Read the player's guess from input
if guess < secret_number
println("Too low! Try again.")
elseif guess > secret_number
println("Too high! Try again.")
11.3 Code Translation 64

else
println("Congratulations! You guessed the number in $attempts attempts!")
break
end
end
end

# Call the number_game function to start the game


number_game()
```

The code above is deliberately quoted using three backticks (```) following the convention of
quoting codes in Markdown format. You shall see ChatGPT translated the code in response:


Sure! Here’s the equivalent Python code for the given Julia code:

import random
def number_game():
secret_number = random.randint(1, 100) # Generate a random secret number between 1 and 100
attempts = 0
print("Welcome to the Number Game!")
print("I'm thinking of a number between 1 and 100. Can you guess it?")
while True:
attempts += 1
guess = int(input()) # Read the player's guess from input
if guess < secret_number:
print("Too low! Try again.")
elif guess > secret_number:
print("Too high! Try again.")
else:
print(f"Congratulations! You guessed the number in {attempts} attempts!")
break

# Call the number_game function to start the game


number_game()

Validation

As a language model, ChatGPT may produce some errors in the code. To verify the accuracy
of the translation, you should create a Python file named number_game.py, paste the converted
code, and execute the file in the terminal, so that you let a real Python interpreter to tell you
whether the code is working as expected.
In this case, ChatGPT has flawlessly translated the Julia code into Python with just a
simple prompt.
11.4 Tips on Effective Translation 65

Figure 11.2: Running the translated code

11.4 Tips on Effective Translation


While it’s possible to write a simple translation prompt and obtain a result, there are several
tips you can follow to enhance the quality of the translation output:
⊲ Begin with an initialization prompt before crafting a translation request.
⊲ Provide additional context to help the model understand the meaning behind the
text. For instance, specify if the text is a poem or a technical document.
⊲ Clearly state both the source language and target language in your prompt.
⊲ Use simple and concise sentences in any follow-up prompts.
⊲ Always proofread and verify the translations for accuracy.
⊲ Ensure that your input text has correct punctuation and follows the appropriate
formatting guidelines for better translation results.

11.5 Further Readings


This section provides more resources on the topic if you are looking to go deeper.

Articles
Wenxiang Jiao, Wenxuan Wang, Jen-tse Huang, Xing Wang, and Zhaopeng Tu. “Is ChatGPT
A Good Translator? Yes With GPT-4 As The Engine”, 2023.
https://arxiv.org/pdf/2301.08745.pdf
11.6 Summary 66

11.6 Summary
In this chapter, we have explored different use cases of machine translation with ChatGPT,
highlighting effective strategies for achieving accurate translations. Specifically, we have
discussed the following topics:
⊲ Writing an effective initialization and translation prompt for language translation.
⊲ Writing translation prompts for technical tasks, such as converting Julia code into
Python.
⊲ Enhancing translation results through context awareness, attention to punctuation,
validation techniques, and optimizing ChatGPT
⊲ prompts.
By implementing these techniques, you can leverage ChatGPT’s translation capabilities to
their fullest potential and obtain high-quality translations for various use cases.
Translation needs to understand the context of the text. In the next chapter, you will
see another example in which ChatGPT can understand your input well to paraphrase what
you said.
Mastering Summarization with
ChatGPT
12
In this era of information overload, summarizing plays a crucial role in extracting meaningful
information from large amounts of data. It is not only time-saving but also facilitates quick
decision-making. However, manual summarization techniques of hiring human experts to
read, analyze and summarize the data have become obsolete due to the exponential growth
of data. This is where the world felt the need to use Natural Language Processing techniques
to develop an automated system that presents condensed information. ChatGPT is one of
them and is widely used in various fields for summarization purposes.
In this chapter, you will have a detailed look into how ChatGPT can assist in generating
summaries. In particular,
⊲ Summarizing market research reports and developing an effective marketing strategy
⊲ Analyzing user feedback surveys to improve product design
Let’s get started.

Overview
This chapter is divided into three parts; they are:
⊲ Summarizing Market Research Reports
⊲ Analyzing User Feedback Surveys
⊲ Tips for Effective Summarization with ChatGPT

12.1 Summarizing Market Research Reports


Take an example of a marketing team that has already conducted market research. They plan
to use this data to develop their marketing strategy for the new product. Although they have
detailed reports due to a shortage of time and abundant data, they struggle to make sense of
them.
You can use ChatGPT to help them summarize the reports and develop an understanding
of their target audience and competitive landscape to devise an effective marketing strategy.
Before creating the initial prompt, you should ask these questions:
12.1 Summarizing Market Research Reports 68

⊲ Do you have any word limit restrictions?


⊲ What information do you want in your final summary? (Include keywords to be more
specific)
In this case, the marketing team was not concerned about the word limit, so they devised this
prompt considering their end goal:


Summarize the key findings and insights from the market research reports on
the target audience and competitors. Highlight the key demographics, behaviors,
needs, and preferences of potential customers. Identify the main competitors,
their product profiles, marketing strategies, and key strengths. Synthesize this
information to determine how to effectively position and differentiate our new
product to capture interest from the target audience in a crowded market.
Market Research Report 1: [ ]
Market Research Report 2: [ ]


...
The market research reports considered in this case are quite lengthy to cite here, but an
overview of both is as follows:
⊲ Market Research Report 1 — Target Audience Analysis: This market research report
aims to comprehensively understand the target audience for the upcoming product
launch. The research was conducted through surveys, interviews, and data analysis,
enabling the marketing team to gain valuable insights into potential consumers’
demographic profiles, preferences, and behaviors.
⊲ Market Research Report 2 — Competitive Landscape Analysis: This market research
report analyzes the competitive landscape for the new product launch. By summarizing
the findings, the marketing team gains valuable insights into the key competitors, their
market positioning, product offerings, and marketing strategies.
The following is the response from ChatGPT:


Synthesis and Recommendations: Based on the findings from the market research
reports on the target audience and competitors, we can derive key insights to
effectively position and differentiate our new product in the crowded market.
Target Audience Insights:
⊲ Our target audience consists of tech-savvy individuals aged 25-40, with
a balanced gender distribution and higher income levels. They value
convenience, quality, and personalized experiences.
⊲ To capture their interest, our marketing strategy should emphasize
the product’s ability to enhance productivity, save time, and provide
entertainment value.
⊲ Leveraging social media platforms like Instagram and YouTube, along with
targeted email marketing campaigns, can effectively reach and engage our
target audience.
Competitor Analysis:
12.2 Analyzing User Feedback Surveys 69

⊲ Key competitors in the market have established brand recognition and a


significant market share.
⊲ We should conduct a thorough analysis of their products to identify unique
selling propositions, pricing strategies, and potential gaps in the market.
⊲ Differentiating our product through messaging, branding, and customer
engagement strategies will be crucial.
Positioning and Differentiation:
⊲ Highlight the specific features and benefits that set our product apart from
competitors, addressing pain points and providing solutions that resonate
with the target audience.
⊲ Develop a compelling value proposition that communicates our product’s
superiority and distinct advantages.
⊲ Emphasize the brand’s uniqueness, customer-centric approach, and
commitment to delivering personalized experiences.
Marketing Strategy Recommendations:
⊲ Implement a multi-channel marketing approach, focusing on social media
platforms, email marketing, and content marketing to reach and engage
the target audience effectively.
⊲ Craft consistent and cohesive messaging across all touchpoints to reinforce
the brand identity and resonate with the target audience’s preferences and
values.
⊲ Collaborate with influencers or industry experts to generate buzz, gain
credibility, and expand the product’s reach.
⊲ Continuously monitor and adapt marketing strategies based on performance
metrics, customer feedback, and evolving market trends.
By leveraging these insights and recommendations, our marketing team can develop
a strong positioning strategy that effectively captures the interest of the target


audience and differentiates our product in the competitive market landscape.
The results were quite impressive. ChatGPT enabled the team to develop a good marketing
strategy in no time. They were able to increase their brand awareness and generate more
leads. This new tool allows the marketing team to work smarter and more cost-effectively.

12.2 Analyzing User Feedback Surveys


Let’s consider another use case of summarizing the documents using ChatGPT. Here, Jamil
and Sarwar, the owners of FEMCodes is a software company going to develop a new feature
for their product. They wanted to ensure that the design met the needs of the end users, so
they conducted extensive user surveys and received many responses. Most of them shared
common concerns, but they worried about missing something important.
12.2 Analyzing User Feedback Surveys 70

You can use ChatGPT to help them summarize the survey result. The summary would
be shared on their social media page. Hence it should be clear and concise.
Here is the format of the user surveys used in this case:
1. Respondent 1:
⊲ Biggest Pain Points: Slow loading times, frequent crashes, and lack of
integration with other software.
⊲ Desired Features: Improved performance and stability, seamless integration
with popular tools, and a more intuitive user interface.
⊲ Satisfaction with Current Product: Somewhat dissatisfied.
⊲ Likelihood to Recommend: Unlikely to recommend.
2. Respondent 2:
⊲ Biggest Pain Points: Limited customization options, lack of advanced reporting
features, and difficulty in accessing certain functionalities.
⊲ Desired Features: More flexibility for customization, robust reporting and
analytics capabilities, and easier access to key features.
⊲ Satisfaction with Current Product: Moderately satisfied.
⊲ Likelihood to Recommend: Neutral.
and so on. These survey data should be incorporated into the prompt, such as the following:


Summarize the key findings and insights from the user feedback surveys. Identify
the most common pain points, frustrations, and feature requests from users.
Highlight any areas of concern or potential issues raised. Provide a synthesis of this
feedback to determine how we can best address the key needs and concerns of our
users with the new product feature. Extract any suggestions or recommendations
provided by users on how we can improve the product or better meet their needs


User Survey Data
The response from ChatGPT might be:


Key Findings and Insights: Common Pain Points and Frustrations:
⊲ Slow loading times, frequent crashes, and lack of integration with other
software.
⊲ Limited customization options, lack of advanced reporting features, and
difficulty in accessing certain functionalities.
⊲ Inconsistent user experience across devices, inadequate customer support,
and a steep learning curve for new users.
⊲ Limited collaboration features, inefficient workflow management, and lack
of integration with project management tools.
⊲ Lack of regular updates and bug fixes, poor documentation and user guides,
and difficulties in onboarding new team members.
Desired Features and Recommendations:
12.2 Analyzing User Feedback Surveys 71

⊲ Improved performance and stability, seamless integration with popular


tools, and a more intuitive user interface.
⊲ More flexibility for customization, robust reporting and analytics
capabilities, and easier access to key features.
⊲ Responsive design for seamless use across different devices, improved
customer support options, and enhanced onboarding process.
⊲ Robust collaboration tools, streamlined workflow management capabilities,
and seamless integration with popular project management software.
⊲ Regular updates with bug fixes and new features, comprehensive
documentation and user guides, and improved onboarding resources.
Areas of Concern and Potential Issues:
⊲ Users express dissatisfaction with the current product, which could impact
user retention and customer loyalty.
⊲ Some users are unlikely to recommend the product to others, indicating a
need for improvement in meeting user expectations.

The response is well-summarized but not concise. The company can learn what to improve,
but it is not the right amount of information to share on social media. You need a shorter

version for that. This can be obtained using a follow-up prompt:


Using condensation and paraphrasing techniques, summarize a given text into a


shortened version.
The response from ChatGPT might be:


User feedback surveys highlight common pain points and frustrations, including
slow loading times, crashes, lack of integration, limited customization options,
and difficulty in accessing functionalities. Users also express concerns about
inconsistent user experience, inadequate customer support, and steep learning
curves. They desire improved performance, stability, intuitive interfaces,
customization options, advanced reporting features, and easier access to key
functionalities. Additionally, users recommend responsive design, enhanced
customer support, better onboarding processes, robust collaboration tools,
streamlined workflow management, and seamless integration with project
management software. Suggestions for improvement include regular updates,
bug fixes, comprehensive documentation, and improved onboarding resources.
Dissatisfaction with the current product and the likelihood of users not
recommending it emphasize the importance of addressing these concerns to enhance


user satisfaction and retention.
Although the generated response summarized the above content quite well, it can be
refined further to make its tone easier for the general public to understand. We can also define
the word limit or directly generate social media posts with appropriate hashtags.
12.3 Tips for Effective Summarization with ChatGPT 72

12.3 Tips for Effective Summarization with ChatGPT


Summarization is to distill important ideas. To prompt an effective summarization from
ChatGPT, you should:
⊲ Provide ChatGPT with enough context. The level of complexity and details in your
summary may vary depending on your use case. Hence, the more context ChatGPT
has, the better will be the summarization results.
⊲ Use follow-up prompts to refine responses. ChatGPT is an AI model that may not
generate 100% accurate responses. Follow-up prompts help clarify anything in the
generated summary if it is ambiguous.
⊲ Generate multiple summaries and iteratively improve the summary content as per the
user’s requirement.
⊲ Request to extract key points from the original text, then use follow-up prompts to
write a more detailed summary. This way, you can ensure all the important information
is retained.
⊲ Review, validate, and modify the output to align correctly with your goals

12.4 Summary
In this chapter, you explored the use of ChatGPT for effective summarization. Summarizing
large amounts of data is crucial in today’s information overload era. Manual techniques have
become obsolete, leading to the adoption of automated systems like ChatGPT. You examined
two case studies: summarizing market research reports to develop a marketing strategy and
analyzing user feedback surveys to improve product design. ChatGPT provided concise and
insightful summaries in both cases, enabling the teams to make informed decisions. The
impressive results demonstrated the effectiveness and cost-efficiency of leveraging ChatGPT
for summarization purposes. This chapter also provided tips for effective summarization
with ChatGPT, emphasizing the importance of context, iterative improvement, and human
validation.
The above summary was generated by ChatGPT and then refined. Feel free to evaluate
its effectiveness in capturing the key information of this chapter.
In the next chapter, you will see how ChatGPT’s fantastic capability of understanding
what you provide can help you do research.
Advanced Techniques for
Research with ChatGPT
13
Research has always been essential to human progress and has evolved tremendously over the
past few years. With the advent of advanced technologies, new tools and techniques have
emerged to conduct more efficient research and to stay at the forefront of knowledge. One
such technology is ChatGPT, a large language model that uses deep learning approaches
to generate human-like responses. The remarkable ability of ChatGPT to understand and
develop text has made it an invaluable tool that can enhance your research. Your productivity
as a researcher is improved as it saves time and resources by providing comprehensive insights.
However, researchers must be careful about the ethical considerations of using ChatGPT and
ensure that their research is accurate and unbiased.
In this chapter, you will explore the advanced techniques to improve your research. In
particular,
⊲ Analyzing and Interpreting Research Data
⊲ Performing Literature Review & Identifying Research Gaps
Let’s get started.

Overview
This chapter is divided into three parts; they are:
⊲ Analyzing and Interpreting Research Data
⊲ Performing Literature Review & Identifying Research Gaps
⊲ Bonus Prompts for Researchers

13.1 Analyzing and Interpreting Research Data


A small business owner wants to analyze customer satisfaction data to improve customer
service. They collected this data from 50 customers using the Likert Scale Questionnaire with
10 questions. The data is numerical ratings from 1 to 5, where 1 indicates “Very Dissatisfied”
while 5 indicates “Very Satisfied”. Interpreting this raw data using conventional methods
13.1 Analyzing and Interpreting Research Data 74

will be time-consuming and requires dedicated software expertise. This is where you can use
ChatGPT to help you make sense of the data.
You will see how we will ask questions to assist this business owner. Before proceeding
toward the prompts, here is the snapshot of the data that we will be working on:
Customer ID Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10
1 4 5 3 5 4 3 4 4 5 3
2 3 4 2 4 3 2 3 3 4 2
3 5 5 4 5 5 5 4 5 5 4
4 2 3 2 4 2 2 3 3 2 2
5 4 4 3 4 4 4 4 4 4 3
6 3 4 2 4 3 3 3 3 4 2
7 1 2 1 2 1 1 2 2 1 1
. . . . . . . . . . .
. . . . . . . . . . .
49 2 2 1 2 1 1 2 2 1 1
50 3 4 2 4 3 3 3 3 4 2

Step 1: Data Analysis & Exploration


Data exploration is an essential step in data analysis that helps you understand the data and
identify the key insights. Before prompting the ChatGPT, enlist the specific questions you
want to be answered. Incorporating these questions will guide the data exploration part. Here
is the final prompt that the business owner provides to the ChatGPT:


I would like you to help me with the initial data exploration of the customer
satisfaction ratings dataset that I collected. Please provide insights on the
following:
1) Can you provide summary statistics of the customer satisfaction rating dataset,
including the range, mean, median, and mode of the ratings?
2) How many customers gave the highest rating (5) for each question, and how
many gave the lowest rating (1)?


Dataset: [ ]
The following is the response from ChatGPT:


To perform the initial data exploration of the customer satisfaction rating dataset,
let’s start by calculating the summary statistics, including the range, mean, median,
and mode of the ratings. Here are the summary statistics for each question in the
dataset: Question 1 (Q1):
Range: 4 (5 - 1)
Mean: 3.08
Median: 3
Mode: 4 (appears most frequently)
...
13.1 Analyzing and Interpreting Research Data 75

Here are the summary statistics for the customer satisfaction rating dataset you
provided:
Range: The range of ratings is from 1 to 5.
Mean: The mean rating across all customers and questions is 3.36.
Median: The median rating is 4.0, which means that half of the ratings are below
4 and a half are above.
Mode: The mode represents the most common rating in the dataset. In this case,
there are multiple modes, with a rating of 4 being the most frequent rating.
Now, let’s find out how many customers gave the highest rating (5) and the lowest
rating (1) for each question:
For Question 1 (Q1):
Number of customers who gave a rating of 5: 5
Number of customers who gave a rating of 1: 3
...
Please note that the above counts are based on the dataset you provided. If you


have more data, the counts may differ.

Step 2: Interpreting Key Insights


Now, that you have a general overview of the data, let us draw the key insights the company can
leverage and the common reasons for customer complaints. Considering the abovementioned
things, the business owner crafts a new prompt and feeds it to ChatGPT. The follow-up
prompt after step 1 is as follows:


Based on the above statistics, what are the key insights I can draw from the data?
Can you also provide information about the following:
1. Key drivers of customer loyalty based on available data?


2. Common reasons for customer complaints or negative feedback?
Since we have considered dummy data where the questions are just like the black box, ChatGPT
cannot provide us recommendations about how to improve our strategy but will pinpoint the
areas of improvement.
Here is the response from ChatGPT:


Based on the provided statistics, we can draw the following key insights from the
data:
Average Rating: The average rating across all customers and questions is 3.36,
which is slightly below the midpoint of 5. This suggests that overall customer
satisfaction is moderate.
Positive Ratings: The most frequent rating is 4, which indicates that many
customers are generally satisfied with the service or product.
13.2 Performing Literature Review & Identifying Research Gaps 76

Negative Ratings: There are a few customers who have given the lowest rating of
1 for some questions. This indicates that there are areas where improvement is
needed to address customer concerns.
Question 10 (Q10): This question received the highest number of lowest ratings
(5 customers gave a rating of 1). It may be worth investigating the specific issues
raised in this question to identify potential areas for improvement.
Now, let’s analyze the data to identify the key drivers of customer loyalty based
on the available information. To determine this, we can look at the questions that
received the highest number of 5 ratings:
Question 2 (Q2): This question received a rating of 5 from all customers. It suggests
that the aspect addressed in this question is a key driver of customer loyalty.
Unfortunately, without the actual question content, it’s difficult to determine the
specific driver.
Questions 1, 4, 5, 6, 7, 8, and 9: These questions also received a rating of 5 from
all customers. Similar to Q2, the specific drivers of loyalty cannot be identified
without knowing the content of these questions.
Regarding common reasons for customer complaints or negative feedback, the data
indicates that Question 10 (Q10) received the highest number of lowest ratings (5
customers gave a rating of 1). It suggests that there are specific issues addressed
in Q10 that lead to customer dissatisfaction. To identify the common reasons for
negative feedback, it’s essential to review the content of Question 10 and analyze
the responses provided by the customers. Without that information, we cannot
provide specific insights into the common complaints.
To gain deeper insights and a more comprehensive understanding of the data, it is
recommended to review the actual questions and analyze the qualitative feedback
provided by customers, if available. This will provide more context and enable
more accurate identification of key drivers of loyalty and common reasons for


complaints.
You have seen how helpful ChatGPT can be to business owners so they can make data-driven
decisions. However, one crucial thing that the researchers should be mindful of is to avoid
biased language while framing the prompts or input data. This can lead to biased results.
Using high-quality training data representing the whole population is also helpful in ensuring
the research is accurate and unbiased.

13.2 Performing Literature Review & Identifying Research


Gaps
Zeenat is a post-graduate researcher. She aims to perform a literature review on renewable
energy resources and their integration into the power grid. She wants to identify the potential
gaps in this area that can help her formulate the research questions and help her in the
literature review process. You will now witness the one-on-one conversation between Zeenat
and ChatGPT:
13.2 Performing Literature Review & Identifying Research Gaps 77


[Zeenat]: I need help with a literature review on renewable energy sources and
their integration into the power grid. Can you provide me with an overview of the


current state of research in this area?


[ChatGPT]: Certainly! The integration of renewable energy sources into the power
grid has been a topic of extensive research in recent years. Here’s an overview of
the current state of research in this area:
1. Renewable Energy Technologies: Numerous renewable energy technologies
are being studied and deployed, including solar photovoltaic (PV) systems,
wind turbines, hydroelectric power, biomass, geothermal, and tidal energy.
Researchers are investigating the technical aspects, efficiency, and scalability of
these technologies.
2. Grid Integration Challenges: One major focus of research is understanding and
addressing the challenges associated with integrating renewable energy into the
power grid. These challenges include intermittency and variability of renewable
generation, grid stability, voltage control, frequency regulation, and power quality
issues.


...
ChatGPT has a knowledge cutoff of September 2021, so ChatGPT might not be aware of the
recent events. It provides a comprehensive overview of the current challenges and work done
so far, but the response should also be verified from other sources. Let’s get back to Zeenat’s
conversation with ChatGPT:


[Zeenat]: Can you provide a list of the top 10 most-cited papers on renewable


energy integration into the power grid?


[ChatGPT]: I can give you a general idea of some influential papers in the field that
were highly cited as of my knowledge cutoff date. These papers have contributed
significantly to the understanding and development of renewable energy integration
into the power grid:
1. “Power System Stability and Control” by Prabha Kundur
2. “Large-scale Renewable Power Generation: Integration and Sustainability” by
Peter Droege
3. “Power System Analysis” by Hadi Saadat
4. “Renewable Energy Sources and Climate Change Mitigation” by Ottmar
Edenhofer et al.
5. “Renewable Energy Integration: Practical Management of Variability,
Uncertainty, and Flexibility in Power Grids” by Lawrence E. Jones
6. “The Smart Grid: Enabling Energy Efficiency and Demand Response” by Clark
W. Gellings
7. “Renewable Energy Grid Integration: Technical and Regulatory Issues” by
Lawrence E. Jones
8. “Renewable and Efficient Electric Power Systems” by Gilbert M. Masters
13.2 Performing Literature Review & Identifying Research Gaps 78

9. “Renewable Energy: Power for a Sustainable Future” by Godfrey Boyle


10. “Renewable Energy Integration: Challenges and Solutions” by Fereidoon P.
Sioshansi
Please note that this list is not exhaustive and there may be other highly cited
papers in the field that are not included here. I recommend consulting academic
databases, such as Google Scholar or Scopus, to find the most up-to-date and
comprehensive list of highly cited papers on renewable energy integration into the


power grid.
Collecting the most cited and influential papers is time-consuming, mainly when the
information is scattered across various resources. However, you can save much time by using
ChatGPT as your research assistant. Now that you have the list of the top 10 cited papers,
Zeenat needs to identify the potential research gaps that can form the basis for her thesis.


[Zeenat]: Based on the current research, what are the main challenges and research
gaps that need to be addressed in the integration of renewable energy sources into


the power grid?


[ChatGPT]: The integration of renewable energy sources into the power grid poses
several challenges and research gaps that are being actively addressed by researchers
and industry experts. Here are some of the main challenges and research areas:
1. Grid Stability: The intermittent nature of renewable energy sources, such
as solar and wind, can impact grid stability. Developing advanced control and
forecasting techniques can help address this issue.
2. Energy Storage: Efficient and cost-effective energy storage solutions are needed
to store excess renewable energy for use during periods of low generation.
3. Grid Management: As renewable energy sources become more prevalent, there
is a need for better grid management techniques, such as demand response and
distributed energy resource management.
4. Regulatory Frameworks: Addressing the regulatory challenges related to
renewable energy integration, such as grid access, pricing, and incentives, remains
an important research area.
5. Technological Innovations: Continued research on new technologies and
materials that can improve the efficiency and cost-effectiveness of renewable energy
generation and storage is crucial.
6. System Integration: Research on the integration of renewable energy sources
with existing power infrastructure, including the interplay between different energy
sources and grid components, is needed.
These are some of the key challenges and research gaps in the integration of
renewable energy sources into the power grid. Researchers, policymakers, and
industry stakeholders are actively working to address these challenges and develop
innovative solutions to accelerate the transition to a sustainable and renewable


energy-based grid
13.3 Bonus Prompts for Researchers 79

With ChatGPT’s help, Zeenat could understand the current state of the research and identify
the potential gaps that helped her develop the research questions for her thesis. But you need
to be aware of important considerations other than the knowledge limitations; these are as
follows:
⊲ Accuracy and Reliability: ChatGPT is a language model, so the responses cannot be
declared 100
⊲ Ethics and Bias: Researchers should strive to maintain ethical research standards and
be aware of potential biases in ChatGPT’s responses.

13.3 Bonus Prompts for Researchers


This bonus section contains the prompts that researchers can use to make their research
process more manageable. From literature reviews to data collection to writing up the results,
you can streamline your research workflow using these prompts:

Generating Topic Ideas


Can you suggest 5 important unanswered questions related to [your area of interest]


that would advance the current state of knowledge in [specific subfield or topic]?

Research Methodology & Data Collection Techniques


Can you suggest the best research methodology and data collection techniques for
studying [research topic] in [specific subfield or context], including their strengths,


weaknesses, and when each would be most appropriate?

Develop a Strong Introduction, Thesis Statement & Conclusion


What are some effective strategies for developing a strong introduction, clear thesis
statement, and convincing conclusion for my [research paper] on [research topic]?
Please provide guiding questions and ideas on how to structure these elements to


ensure they are effective and aligned with the research goals.

Proofreading your Research Paper


Proofread and edit my Research Paper for any grammatical, punctuation, repetitive
words, and spelling errors. Please provide suggestions to improve the readability


and flow of my research paper.

Generating Synthetic Data


I would like you to generate a dataset of [About?] with [Number of Records]
synthetic records with the following characteristics.
[Name of Field] ([Data Type / Range]) ...
13.4 Summary 80

[Special Instructions about Dataset]


The data should be realistic and plausible, not obviously fake or randomly
generated. Format the output as a comma-separated values (CSV) file with a


header row listing the field names and [Number] data rows.

13.4 Summary
While ChatGPT can be a helpful resource, the actual human research and the researcher’s
understanding and expertise in a particular subject remain essential for high-quality research.
Here are the key takeaways from this chapter:
⊲ ChatGPT can help assist research tasks allowing you to focus more on the actual
research and less on the other things. Sample prompts and examples are provided to
demonstrate how it can assist at different stages of the research process.
⊲ Researchers should carefully frame prompts and provide enough detail and context
to guide ChatGPT in generating relevant and valuable responses.
⊲ Researchers must take responsibility for the accuracy and reliability of their work.
They should abide by the ethical considerations of using AI-based assistance in their
research.
In the next chapter, you will see why ChatGPT can save you time because it can understand
text.
14
Using the Natural Language
Understanding Capability of
ChatGPT

ChatGPT as a Large Language Model, is well-known for understanding human languages.


Instead of asking ChatGPT for an answer you don’t know, you can make it work on existing
information while leveraging the natural language understanding (NLU) capability. In this
chapter, you will learn
⊲ How to make ChatGPT produce a summary from a long text
⊲ How to make ChatGPT extract key information from a passage
Let’s get started.

Overview
This chapter is divided into three sections; they are:
⊲ You AI Secretary
⊲ Extracting Unstructured Information
⊲ How to Use ChatGPT for NLU

14.1 Your AI Secretary


Imagine you have a meeting transcript with conversations between different people. The
transcript would be a great way to check how a conclusion is reached by tracking the discussion,
but meeting minutes should be easier to read the decision. You can ask ChatGPT to produce
the meeting minute from a transcript.
Let’s consider the transcript here:
⊲ https://www.nyc.gov/assets/transitionalfinance/pdf/transcript/tfa-board-fin-t
ranscript-10-21-22.pdf

An excerpt is as follows:


» GOOD MORNING, EVERYBODY. I’M MICHAEL STERN, DELEGATE
FOR COMPTROLLER BRAD LANDER AND CHAIR OF THE FINANCE
COMMITTEE OF THE NEW YORK CITY TRANSITIONAL FINANCE
14.1 Your AI Secretary 82

AUTHORITY. AS A REMINDER, PLEASE KEEP YOUR FILMS MUTED


UNLESS SPEAKING. I’LL NOW CALL TO ORDER A MEETING OF THE
FINANCE COMMITTEE. RITA, COULD YOU PLEASE CALL THE ROLL?
...
» THANK YOU, EVERYBODY. HAVE A GREAT WEEKEND.
» HAVE A GREAT WEEKEND.


» THANK YOU.
This is not a long meeting, but the transcript spans several pages. You can summarize the
transcript into 1-page minutes using the following prompt:


As an experienced secretary, please summarize the meeting transcript below to
meeting minutes, list out the participants, agenda, key decisions, and action items.
» GOOD MORNING, EVERYBODY. I’M MICHAEL STERN, DELEGATE FOR
COMPTROLLER
BRAD LANDER AND CHAIR OF THE FINANCE COMMITTEE OF THE
NEW YORK CITY
TRANSITIONAL FINANCE AUTHORITY. AS A REMINDER, PLEASE KEEP
YOUR FILMS
MUTED UNLESS SPEAKING. I’LL NOW CALL TO ORDER A MEETING OF
THE FINANCE
COMMITTEE. RITA, COULD YOU PLEASE CALL THE ROLL?
...
» THANK YOU, EVERYBODY. HAVE A GREAT WEEKEND.
» HAVE A GREAT WEEKEND.


» THANK YOU.
In the prompt, you provided the transcript and told ChatGPT what to include in the output
to ensure all key details are included. The following is what ChatGPT produced:


Meeting Minutes
Meeting: Finance Committee Meeting
Date: [Insert Date]
Time: [Insert Time]
Location: [Insert Location]
Participants:
- Michael Stern (Delegate for Comptroller Brad Lander and Chair of the Finance
Committee)
- David Womack (Representing Director Jacques Jiha)
- Diana Beinart (Representing Commissioner Preston Niblack)
- Louann Koziol (Representing Commissioner Thomas Foley)
- Hector German (Representing Speaker Adrienne Adams)
Agenda:
1. Approval of the minutes of the committee’s last meeting.
2. Resolution recommending the Board of Directors approve the 125th series
resolution authorizing the issuance of up to 1.6 billion of fiscal 23 series D future
tax-secured bonds. Key Decisions:
1. Approval of the minutes of the committee’s last meeting.
- The minutes were reviewed and approved unanimously.
14.1 Your AI Secretary 83

2. Resolution recommending the Board of Directors approve the 125th series


resolution authorizing the issuance of up to 1.6 billion of fiscal 23 series D future
tax-secured bonds.
- The resolution was presented, and the expected breakout of the subseries was
provided.
- The committee members voted in favor of the resolution unanimously, and it
was approved. Action Items:
1. None mentioned in the transcript.
Adjournment:
- The Finance Committee meeting was adjourned.

Meeting: Board of Directors Meeting
Date: [Insert Date]
Time: [Insert Time]
Location: [Insert Location]
Participants:
- David Womack (Delegate for Budget Director Jacques Jiha and Chair of the
Board of Directors)
- Diana Beinart (Representing Commissioner Preston Niblack)
- Michael Stern (Representing Comptroller Brad Lander)
- Louann Koziol (Representing Commissioner Thomas Foley)
- Hector German (Representing Speaker Adrienne Adams)
Agenda:
1. Resolution to allow remote meetings during a state of emergency related to
COVID-19.
2. Approval of the minutes of the last board meeting.
3. Approval of the 125th series resolution authorizing the issuance of up to 1.6
billion of fiscal 2023 series D future tax-secured bonds.
Key Decisions:
1. Resolution to allow remote meetings during a state of emergency related to
COVID-19.
- The resolution was proposed to allow remote meetings while a state of emergency
related to COVID-19 is in effect in the city.
- The board members voted in favor of the resolution, and it was approved.
2. Approval of the minutes of the last board meeting.
- The minutes were reviewed and approved unanimously.
3. Approval of the 125th series resolution authorizing the issuance of up to 1.6
billion of fiscal 2023 series D future tax-secured bonds.
- The resolution was presented, and the committee’s recommendation was
mentioned.
- The board members voted in favor of the resolution unanimously, and it was
approved.
Action Items:
1. None mentioned in the transcript.
Adjournment:
- The Board of Directors meeting was adjourned.
14.2 Extracting unstructured information 84

Note: The transcript provided does not include specific details about the meeting
such as dates, times, and locations. Please fill in the missing information based


on the context and requirements of the organization.
The minutes are much tidier than the transcript and easier to read. One particular fact is
that this transcript is two meetings scheduled as one and you can be aware of that from
the minutes. However, you may still need to polish it if you wish it in a particular format.
Some information that should appear in the minute but not available from the transcript is
replaced with a placeholder that you need to fill in. This shouldn’t be very difficult compared
to summarizing the transcript.
ChatGPT can do this job easily because it is trained to understand language, and it can
extract key information. You can make it a helpful secretary with an appropriate prompt to
instruct ChatGPT to reproduce the key information in a particular format.
Nevertheless, some meetings are lengthy. The transcript may be very long and would
hit the context length limit in ChatGPT. In that case, ChatGPT will refuse to proceed. You
may want to break down the transcript into multiple chunks and let ChatGPT summarize
each first. Then combine the summarized result to generate the minutes.

14.2 Extracting unstructured information


Because ChatGPT can understand text, you can use it to extract unstructured information.
Unstructured information is those immersed in paragraphs of texts, contrary to lists and
tables. Since it has no trivial pattern, it isn’t easy to search.
You can leverage the language understanding capability of ChatGPT to help you extract
unstructured information and produce a list. Let’s consider the following example:


Read the following text, and answer the following:
1. What is the latest passenger count?
2. What is the date referenced for this volume?
3. How many passengers it has before?
4. What was the date referenced for the previous volume?
Text:
The Port Authority of New York and New Jersey today announced that for the
first time since the start of the COVID-19 pandemic, monthly air passenger levels
across the agency’s regional airports surpassed pre-pandemic volumes.
In November, the Port Authority’s airports handled a total of 11 million passengers,
which was 102 percent of pre-COVID November 2019 volumes. Strong demand
for air travel in November was driven primarily by domestic travelers during
Thanksgiving, when 8 percent more holiday passengers flew to U.S. destinations
compared to Thanksgiving 2019.
The Port Authority also forecasts demand for air travel will remain high through
the remainder of 2022, particularly during the 11-day period beginning Friday,
Dec. 23, 2022, to Monday, Jan. 2, 2023.
The evident return to air travel in the bistate region caps a year of accomplishments
and openings for the Port Authority’s redevelopment projects at its three major
14.2 Extracting unstructured information 85

regional airports. It is a stark contrast to the nadir of the pandemic in 2020,


when volumes at the three major airports declined steeply to just a quarter of its
pre-pandemic volumes.
“We are extremely gratified to see our airports at pre-pandemic levels after more
than two years of a global pandemic that left us homebound and filled with
wanderlust,” said Port Authority Chairman Kevin O’Toole. “Throughout this
year, we have seen the steady return of airport passengers and also the pleasant
surprise on their faces when they see the brand-new, world-class air facilities that
await them. We look forward to welcoming millions more passengers in the coming
weeks as people celebrate the holidays with loved ones.”
“The fact that November 2022 aviation volumes surpassed pre-pandemic November
2019 numbers demonstrates that our historic investments in the region’s airports are
critically important,” said Port Authority Executive Director Rick Cotton. “Our
goal is to provide air passengers who travel through our airports with a world-class
21st century travel experience, and to contribute to the growing resurgence in the
region’s economy post-COVID.”
LaGuardia Airport reached substantial completion earlier this year of its $8 billion
public-private transformation, making it the first new major airport built in the
United States in the last 25 years. The new airport was built in phases to ensure
that it remained fully operational and never lost capacity throughout construction.
This year all passenger facilities at the new Terminal B opened, as well as Delta’s
new Terminal C and the newly rebuilt roadway network. The new airport has
won praise from passengers for its 21st century design, amenities and customer
experience, and awards and accolades from respected industry groups worldwide.
Newark Liberty International Airport also celebrated a key milestone in November
2022 with the ribbon-cutting of its new Terminal A, which features approximately
1 million square feet of space and 33 gates to handle larger aircraft, as well
as a modernized common-use check-in area, security and baggage claim areas
expected to efficiently handle an estimated 13.6 million passengers a year. The Port
Authority also announced a world-class master planner to lead the transformation
of the entire airport. The new Terminal A is expected to open for service in early
2023.
At John F. Kennedy International Airport, the Port Authority reached financial
close on two new terminals - Terminal One and Terminal 6 - and completed the
expansion of Terminal 8 with approximately 130,000 square feet of additional and
refurbished space. The expansion marked the first step in the transformation of
JFK Airport and allowed British Airways to move from its long-time home in
the 50-year-old Terminal 7 to co-locate with American Airlines in Terminal 8.
Terminal 7 will be demolished to clear space for a new Terminal 6 that will begin
construction early next year. The $1.5 billion expansion of Terminal 4 is also


underway, having broken ground in December 2021.
The text is from a press release obtained here:
14.3 How to Use ChatGPT for NLU 86

⊲ https://www.panynj.gov/port-authority/en/press-room/press-release-archives/20
22-press-releases/port-authority-reports-monthly-airport-passenger-volume-s
urpasse.html

The result from ChatGPT is as follows:


1. The latest passenger count mentioned in the text is 11 million passengers.
2. The date referenced for this volume is November.
3. The text does not provide information on the number of passengers before the
COVID-19 pandemic.


4. The date referenced for the previous volume is not mentioned in the text.
The distilled result is easier to extract, and you may transfer it to another use. Also note that
when the provided text does not contain the information you were looking for, it will tell you
so. This is because, in your prompt, you asked it to answer based on the text only.

14.3 How to Use ChatGPT for NLU


ChatGPT as a language model should understand text fairly easily. However, to leverage its
natural language understanding capabilities, you should be careful not to allow it to hallucinate.
Hallucination happens when you allow it to generate text out of context. This can be avoided
when you explicitly mention using only the provided information for the task in the prompt,
but nothing else.
Even so, bear in mind that ChatGPT may not understand everything well. Should there
be some information out of context, ChatGPT would not know. One particular example is
domain-specific abbreviations and jargon. If there is information not very straightforward,
ChatGPT may also fail to extract it. You may try to regenerate the second example above
for a few times. ChatGPT sometimes cannot find the exact passenger volume since the text
expressed it as a percentage of another volume.

14.4 Summary
In this chapter, you have seen how to use ChatGPT as a natural language understanding tool.
You have seen examples of:
⊲ Transforming a meeting transcript into minutes
⊲ Extracting specific information from text
Using this capability of ChatGPT, you can easily build a helper, such as extracting action
items from an email you received and create a to-do list.
In the next chapter, you will see ChatGPT can generate not only human language, but
also programming language.
Using ChatGPT as Your
Programming Assistant
15
A large language model is a machine that can understand and generate text. Depending on
how it is trained, sometimes the model can generate something other than text. ChatGPT is
such a large language model. It can generate programming code if you prompt it correctly. In
this chapter, you will learn how to make ChatGPT to generate a program for you. Specifically,
you will learn
⊲ How to make ChatGPT to bootstrap your programming project
⊲ How to use ChatGPT as your programming helper
Let’s get started.

Overview
This chapter is divided into two parts; they are:
⊲ Start a Programming Project
⊲ Understanding Code and Generating Function Snippets

15.1 Start a Programming Project


Let’s consider a simple project: You want to set up a REST API server that can help you take
a “screen capture” of an entire web page of a provided URL. Optionally, the REST API can
accept an additional optional parameter of an email address. In that case, the screen capture
is not returned but emailed out.
This is a project that involves multiple components. It would help if you had something
like a REST API server that listens to HTTP requests and responds accordingly. You also
need something to fetch a URL and take a screenshot like a regular web browser. There is
also a logic that depends on whether an email address is provided; the output can be an image
file returned or an email with an attachment sent out.
If you are unfamiliar with creating a REST API server or don’t know the tools available,
you can ask ChatGPT for help. Simply put down all the detail in your prompt and ask:
15.1 Start a Programming Project 88


I need to create a REST API server that accepts a URL as input, captures the web
page screenshot into JPEG format, and returns it as output. Optionally, the user
may provide an email address as an additional input. In that case, the screenshot


should be emailed out instead of returned. Can you help me with this program?
With this, ChatGPT produces the following suggestion:


Certainly! I can help you with that. To create a REST API server that captures
web page screenshots and handles optional email functionality, you can use Node.js
along with a few additional packages. Here’s an outline of the steps you can follow:
1. Set up a new Node.js project and initialize it using npm:

mkdir screenshot-api
cd screenshot-api
npm init

2. Install the necessary packages. You’ll need express for the API server, puppeteer
for capturing screenshots, and nodemailer for sending emails:

npm install express puppeteer nodemailer

3. Create an index.js file and set up the basic server using Express:

const express = require('express');


const app = express();
const port = 3000;

app.get('/screenshot', async (req, res) => {


const url = req.query.url;
const email = req.query.email;

// Capture the screenshot using Puppeteer

// Handle the response based on whether an email is provided

});

app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});

4. Inside the /screenshot route, use Puppeteer to capture the web page screenshot
and handle the response accordingly:

const puppeteer = require('puppeteer');

app.get('/screenshot', async (req, res) => {


const url = req.query.url;
const email = req.query.email;
15.1 Start a Programming Project 89

// Launch Puppeteer
const browser = await puppeteer.launch();
const page = await browser.newPage();

// Navigate to the provided URL


await page.goto(url);

// Capture the screenshot


const screenshotBuffer = await page.screenshot({ fullPage: true });

// Close the browser


await browser.close();

// Handle the response based on whether an email is provided


if (email) {
// Send the email with the screenshot attachment using Nodemailer

} else {
// Send the screenshot as the response
res.type('image/jpeg');
res.send(screenshotBuffer);
}
});

5. To handle sending emails with the screenshot attachment, add the following
code inside the if (email) block:

const nodemailer = require('nodemailer');

// Create a transporter using your email service provider's details


const transporter = nodemailer.createTransport({
service: 'your-email-service-provider',
auth: {
user: '[email protected]',
pass: 'your-email-password',
},
});

// Define the email options


const mailOptions = {
from: '[email protected]',
to: email,
subject: 'Web Page Screenshot',
text: 'Please find the attached screenshot.',
attachments: [
{
filename: 'screenshot.jpg',
content: screenshotBuffer,
},
],
};

// Send the email


15.1 Start a Programming Project 90

transporter.sendMail(mailOptions, (error, info) => {


if (error) {
console.error(error);
res.status(500).send('Failed to send email.');
} else {
console.log(`Email sent: ${info.response}`);
res.send('Screenshot emailed successfully!');
}
});

Make sure to replace 'your-email-service-provider', '[email protected]',


and 'your-email-password' with your actual email service provider’s details.
6. Finally, start the server:

node index.js

Now, when you make a GET request to http://localhost:3000/screenshot?url={URL},


the server will capture a screenshot of the provided URL. If an email address is
also provided as email={EMAIL}, the server will send the screenshot as an email
attachment instead of returning it directly.
Remember to handle errors and add any necessary error checking or validation
based on your requirements.
That’s it! You now have a basic REST API server that captures web page screen-
shots and optionally sends them via email. Feel free to enhance it further according


to your needs.
This is a very detailed result that tells you how to finish this programming task. The response
covered all the requirements, but you should notice that when you didn’t specify explicitly in
the prompt, ChatGPT will make some design decisions for you, such as what programming
language to use.
It is not easy to think for all the details at the first run, but the nature of ChatGPT
allows you to provide follow-up prompt to revise the answer, such as:


For the above problem, I want to use Python and FastAPI as the web framework


and Selenium for the web browser. Can you rewrite this?
The response from ChatGPT now becomes:


Certainly! Here’s a revised version of the solution using Python, FastAPI as the
web framework, and Selenium for the web browser automation. 1. Install the
necessary packages. You’ll need fastapi, uvicorn for running the server, selenium,
and webdriver_manager for managing the web driver:

pip install fastapi uvicorn selenium webdriver_manager

2. Create a new file called main.py and import the required modules:
15.1 Start a Programming Project 91

from fastapi import FastAPI, HTTPException


from fastapi.responses import FileResponse
from pydantic import BaseModel
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.common.exceptions import WebDriverException
from io import BytesIO

app = FastAPI()

3. Define a request model to handle the input data:

class ScreenshotRequest(BaseModel):
url: str
email: str = None

4. Create a route to capture the web page screenshot:

@app.get("/screenshot")
async def capture_screenshot(request: ScreenshotRequest):
options = Options()
options.headless = True

try:
# Set up the Chrome webdriver


driver = webdriver.Chrome(ChromeDriverManager().install(), ❈
options=options)
driver.set_window_size(1280, 720)

# Navigate to the provided URL


driver.get(request.url)

# Capture the screenshot


screenshot = driver.get_screenshot_as_png()
screenshot_buffer = BytesIO(screenshot)

# Close the browser


driver.quit()

if request.email:
# Send the email with the screenshot attachment

return "Screenshot emailed successfully!"


else:
# Return the screenshot as a response
return FileResponse(screenshot_buffer, media_type="image/png")
except WebDriverException:


raise HTTPException(status_code=400, detail="Failed to capture ❈
screenshot.")

5. Start the server using Uvicorn:


15.2 Understanding Code and Generating Function Snippets 92

uvicorn main:app --reload

Now, when you make a GET request to http://localhost:8000/screenshot?url={URL},


the server will capture a screenshot of the provided URL. If an email address is also
provided as email={EMAIL}, you can handle sending the email with the screenshot
attachment using the email field in the request. Remember to handle errors and
add any necessary error checking or validation based on your requirements. Note:
This solution assumes you have Chrome installed on your machine. If you’re using
a different browser, you’ll need to adjust the webdriver accordingly. That’s it! You
now have a REST API server using Python, FastAPI, and Selenium to capture


web page screenshots and handle optional email functionality.
You can see that, you didn’t provide any unnecessary detail in your follow-up prompt except
referencing to “the above problem” but ChatGPT can accurately “translated” the Node.js
implementation into Python and use the libraries you specified.
It is a fantastic result, although you may still need to polish the code. One example is
that the browser screen size is certainly affecting how a web page is rendered, but the size was
hard-coded in the above since you didn’t specify that it should be adjustable in your prompt.
Another potential reason to polish the generated code is to catch other coding style issues or
add defensive measures against security concerns.
In summary, as in the other use case, the more detail you put in the prompt with sufficient
clarity is the key to a useful response. In the case of a programming task, it is crucial to lay
out the details of
⊲ What is the objective
⊲ What is the input and output format
⊲ What are the tools the program should use
⊲ What are the different situations that the program may encounter and how should
these situations be handled

15.2 Understanding Code and Generating Function Snippets


Sometimes, it is not a large program that you want to write but a smaller function. You can
ask ChatGPT to generate a function for you using a prompt similar to the above, except you
need to specify the output format, such as a function or a class.
Indeed you can also do the other way round, namely, provide a code to ChatGPT and
ask it to explain in English. It is sometimes useful, especially to decipher other people’s code.
Let’s consider the following example:


Please explain what the following code is doing:
```
float det(float** a, float k) {
float s = 1, ret = 0, **b;
int i, j, m, n, c;
15.2 Understanding Code and Generating Function Snippets 93

if (k == 1) {
return a[0][0];
} else {
b = (float**) malloc(sizeof(float*)*k);
for (i = 0; i < k; i++)
b[i] = (float*) malloc(sizeof(float)*k);
ret = 0;
for (c = 0; c < k; c++) {
m = 0;
n = 0;
for (i = 0; i < k; i++) {
for (j = 0; j < k; j++) {
b[i][j] = 0;
if (i != 0 && j != c) {
b[m][n] = a[i][j];
if (n < (k - 2))
n++;
else {
n = 0;
m++;
}
}
}
}
ret = ret + s * (a[0][c] * det(b, k - 1));
s = s * -1;
};
for (i = 0; i < k; i++)
free(b[i]);
};
free(b);
return ret;
}
```

This prompt is very simple: There is only one keyword, “explain”. But pay attention to how
you provide the code to ChatGPT: The use of backticks (```) follows the Markdown’s code

fence syntax to quote the program. This helps identify which is your instruction and which
is not.
While this program is not long, ChatGPT explained the code with great verbosity. It
also identifies the intent at a high level. Namely, it is to calculate the determinant of a matrix.
The following is the response:


The code you provided is a recursive implementation of calculating the determinant
of a square matrix using the Laplace expansion. Here’s a step-by-step breakdown
of what the code does:
15.2 Understanding Code and Generating Function Snippets 94

1. The function det takes two parameters: a pointer to a 2D array (float** a)


representing the matrix and the size of the matrix (float k).
2. It declares some variables: s for sign, ret for the determinant value, and
**b as a temporary matrix.

3. It checks if k is equal to 1. If so, it means we have reached the base case


of a 1×1 matrix, and the function returns the single value in the matrix,
which is the determinant.
4. If k is greater than 1, it proceeds with the calculation.
5. It dynamically allocates memory for the temporary matrix b with size k x
k.

6. It initializes ret to 0.
7. It enters a loop that iterates over each column of the first row of the matrix
a.

8. Inside the loop, it resets the indices m and n to 0.


9. It enters a nested loop that iterates over each element of the matrix a.
10. Inside the nested loop, it sets the element in the temporary matrix b at
position m, n to 0.
11. It checks if the current element is not in the first row (i != 0) and not in
the current column (j != c).
12. If the element is not in the first row or the current column, it copies the
value from matrix a to the temporary matrix b at position m, n.
13. It updates the indices m and n based on the position of the next element
in b.
14. After the nested loop, it calculates the determinant of the submatrix b by
recursively calling the det function with the temporary matrix b and size
k - 1.

15. It multiplies the determinant of the submatrix by the sign s (alternating


sign).
16. It multiplies the sign s by -1 to switch the sign for the next iteration.
17. It adds the product of the sign, the element in the first row (a[0][c]), and
the determinant of the submatrix to the running sum ret.
18. The loop continues to the next column.
19. After the loop, it frees the memory allocated for each row of the temporary
matrix b.
20. It frees the memory allocated for the temporary matrix b.
21. Finally, it returns the calculated determinant value ret.

In summary, the code recursively calculates the determinant of a square matrix by


performing a Laplace expansion along the first row. It uses a temporary matrix to
15.2 Understanding Code and Generating Function Snippets 95

store the submatrices obtained by excluding the first row and the selected column.


The recursion continues until it reaches the base case of a 1×1 matrix.

Follow-up to improve the code


This code is not easy to understand at first glance. There may be a way to make it easier to
read. Indeed, ChatGPT can do a good job in this case with just a straightforward follow-up
prompt:

“ ”
Can you rewrite this code for clarity and add comments?
The keywords here are “for clarity” and “add comments”. ChatGPT provides the following
in response:


Certainly! Here’s a revised version of the code with comments explaining each
step:

float determinant(float** matrix, int size) {


float sign = 1; // Sign of the determinant
float result = 0; // Determinant value
float** submatrix; // Temporary submatrix
int i, j, m, n, c; // Loop variables

// Base case: 1x1 matrix


if (size == 1) {
return matrix[0][0];
}
else {
// Allocate memory for the temporary submatrix
submatrix = (float**)malloc(sizeof(float*) * size);
for (i = 0; i &lt; size; i++) {
submatrix[i] = (float*)malloc(sizeof(float) * size);
}

// Calculate the determinant


for (c = 0; c &lt; size; c++) {
m = 0;
n = 0;

❈ // Create the submatrix by excluding the first row and the current ❈
column
for (i = 0; i &lt; size; i++) {
for (j = 0; j &lt; size; j++) {
submatrix[i][j] = 0;

// Copy values to the submatrix


if (i != 0 &amp;&amp; j != c) {
submatrix[m][n] = matrix[i][j];

// Update submatrix indices


if (n &lt; (size - 2)) {
n++;
}
15.2 Understanding Code and Generating Function Snippets 96

else {
n = 0;
m++;
}
}
}
}

// Calculate the determinant of the submatrix recursively


result += sign * matrix[0][c] * determinant(submatrix, size - 1);

// Flip the sign for the next iteration


sign *= -1;
}

// Free the memory allocated for the submatrix


for (i = 0; i &lt; size; i++) {
free(submatrix[i]);
}
free(submatrix);

return result;
}
}

I’ve added comments above each significant section of the code to explain what it


does. This should make the code more readable and easier to understand.
This version is undoubtedly easier to read.
Besides, you can ask for more. Such as ask to catch bugs or potential security issues in
the code. Let’s ask ChatGPT to produce some unit test code:

“ ”
Can you give me a few unit test cases to ensure this function works well?
Not require any further explanation, the following is the response:


Certainly! Here are a few unit test cases to verify the correctness of the determinant
function: Test Case 1: 2×2 Matrix

float matrix1[2][2] = {{2, 3},


{1, 4}};
float** ptrMatrix1 = (float**)matrix1;
float det1 = determinant(ptrMatrix1, 2);
// Expected output: 5

Test Case 2: 3×3 Matrix

float matrix2[3][3] = {{6, 1, 1},


{4, -2, 5},
{2, 8, 7}};
float** ptrMatrix2 = (float**)matrix2;
float det2 = determinant(ptrMatrix2, 3);
// Expected output: -306
15.3 Summary 97

Test Case 3: 4×4 Matrix

float matrix3[4][4] = {{1, 0, 2, -1},


{3, 0, 0, 5},
{2, 1, 4, -3},
{1, 0, 5, 0}};
float** ptrMatrix3 = (float**)matrix3;
float det3 = determinant(ptrMatrix3, 4);
// Expected output: -20

These test cases cover matrices of different sizes (2×2, 3×3, and 4×4) and include
positive, negative, and zero determinant values. By comparing the calculated
determinant values with the expected outputs, you can verify if the determinant


function is working correctly.
But it is apparent that the unit test code missed a corner case: The 1 × 1 matrix. This
reveals that ChatGPT is not always perfect. You should only use it as your assistant not a
replacement. You should always verify the result.

15.3 Summary
In this chapter, you saw how ChatGPT can help you with programming. Not only can it
generate code as part of its response to your question, but also it can figure out the intention
of a code that you provided. Specifically, you have learned that:
⊲ You can use ChatGPT to generate the initial code for your software project or generate
test code for a function
⊲ You can ask ChatGPT to explain the code to you
⊲ You can make use of ChatGPT to refactor and clean up code
In the next chapter, you will see why ChatGPT’s ability to speak a computer language is
helpful, even if you are not writing software.
Generating Diagrams with
ChatGPT
16
A large language model trained with appropriate content can generate responses more than
just English text. ChatGPT, for example, is known to be able to generate code in many
programming languages. Indeed, you can make ChatGPT generate other content as well,
such as pictures. In this chapter, you will learn
⊲ How to make ChatGPT to generate block diagrams and sequence diagrams
⊲ The general rules to make ChatGPT to create diagrams for you
Let’s get started.

Overview
This chapter is divided into three parts; they are
⊲ Building a System Design Block Diagram
⊲ Building a Sequence Diagram
⊲ Limitations and Tips for Graphics Generation

16.1 Building a System Design Block Diagram


In today’s software industry, it is inevitable to consider scalability. That means a fairly large
system has to be broken down into smaller pieces and run on segregated hardware. These
pieces will collaborate over the network to finish a task. This contrasts the pre-Internet age
when software was designed to be installed and run on a single computer.
Let’s consider a cloud-based file storage system that can interact with a mobile app. If
you search on the Internet, it is not difficult to learn how such a system is built to support
massive number of users. But a picture is worth a thousand words. You can describe such a
system to ChatGPT and ask it to generate a picture. The prompt can be the following:


A cloud file storage service has the following components:
1. A mobile client that contains a local database, an index controller, a chunk
controller, and a watcher components
2. The controllers and watcher components are interacting with the server side
16.1 Building a System Design Block Diagram 99

through a load balancer


3. There is a notification server at the server side that push messages such as files
update to the client, which the watcher component at client will handle them
4. The upload and download of files are handled by a file processing server, which
files are indexed and broken down into chunks. The chunks are stored in the cloud
storage.
5. Metadata of files are processed by the metadata server and stored in the
metadata database
6. All these operations are streamlined using a message queue built on top of
Kafka.


Please create a block diagram for this using the Mermaid syntax.
There are two key properties in constructing such prompt:
⊲ You put down the system components and how they interact with each other clearly
⊲ You request to use Mermaid syntax for the diagram
Giving the detail of what components should include and how they should interact is important
to get the elements in the diagram right. However, ChatGPT can generate text but not
graphics. In order to have the diagram, you need a graphics generation language that can
present in plaintext form. Mermaid.js (https://mermaid.js.org/) is one example.
The response from ChatGPT is as follows:


Sure! Here’s a block diagram representing the components and their interactions
in the cloud file storage service:

mermaid
Copy code
graph TD

subgraph Mobile Client


A[Local Database] --> B[Index Controller]
B --> C[Chunk Controller]
C --> D[Watcher]
end

subgraph Server Side


E[Load Balancer] --> F[Controllers]
E --> G[Watcher]
F --> H[File Processing Server]
H --> I[Cloud Storage]
F --> J[Metadata Server]
J --> K[Metadata Database]
J --> L[Notification Server]
L --> G
end

subgraph Message Queue


M[Kafka]
end
16.1 Building a System Design Block Diagram 100

A -- Notify changes --> D


D -- Watch events --> G
G -- Notify events --> D
F -- Upload/Download files --> H
H -- Store/Retrieve chunks --> I
F -- Process metadata --> J
J -- Store metadata --> K
F -- Push notifications --> L
L -- Publish messages --> M
M -- Subscribe to messages --> G

In this diagram, the mobile client consists of a local database, an index controller,
a chunk controller, and a watcher component. These components interact with
the server-side components through a load balancer. The server side consists of
controllers, a file processing server, a metadata server, and a notification server.
The file processing server handles the upload and download of files, breaking
them down into chunks and storing them in the cloud storage. The metadata
server processes the metadata of files and stores it in the metadata database. The
notification server pushes messages, such as file updates, to the client, which are
handled by the watcher component. All these operations are streamlined using a
message queue built on top of Kafka.
Please note that this is a simplified representation, and there may be additional
components or interactions depending on the specific implementation of the cloud


file storage service.
The code block in the response is the diagram in Mermaid.js syntax. If you copy them to the
Mermaid Live Editor online (https://mermaid.live/), the following is what you get:

Figure 16.1: The diagram based on the Mermaid code produced by ChatGPT

Mermaid is a Javascript library that can render a variety of graphics on a web page. You
may further polish the Mermaid code to add color or move the blocks to a different location
16.2 Building a Sequence Diagram 101

on the canvas. However, it is a great help from ChatGPT already if you need a visualization
of a system.
In fact, you can combine this technique with others, such as providing a system’s high-
level goal to ChatGPT and asking it to tell you the system components. Then in the follow-up
prompt, ask ChatGPT to convert this into a diagram.
You can try out the following prompt as an example:


What are the system components behind a social media like Twitter and how do


they interact?
and then in the follow-up prompt,

“ ”
Please provide a block diagram for the above in the Mermaid syntax.

16.2 Building a Sequence Diagram


As another example, let’s make ChatGPT generate a sequence diagram. It is another commonly
used graphic in software engineering depicting how different components interact in a timeline.
Contrast to above, let’s make ChatGPT figure out the components and interactions and
generate the picture in the same prompt:


How can a user interact with an webapp and login using OAuth2? Please generate


a sequence diagram in PlantUML syntax to explain.
OAuth2 is a common way of authentication on webapps that the webapp server does not need
you to create an account, but instead uses other platform’s account. For example, you can use
your Google account to login to ChatGPT. Google checks your password, but the application
(ChatGPT) is not part of Google. There are multiple parties involved in the process.
The following is how ChatGPT explained this process to you:


Certainly! I can help you generate a sequence diagram in PlantUML syntax to
illustrate how a user can interact with a web app and login using OAuth2. Here’s
the diagram:

plantuml
Copy code
@startuml
actor User
participant "Web App" as WebApp
participant "OAuth2 Provider" as OAuthProvider

User -> WebApp: Access web app


WebApp -> User: Display login button
User -> WebApp: Clicks login button
WebApp -> OAuthProvider: Redirects user to OAuthProvider
User -> OAuthProvider: Enters credentials
OAuthProvider -> User: Validates credentials
OAuthProvider -> WebApp: Redirects user with authorization code
WebApp -> OAuthProvider: Sends authorization code
OAuthProvider -> WebApp: Sends access token
16.2 Building a Sequence Diagram 102

WebApp -> User: Logs in user


@enduml

In this diagram, the steps are as follows:


1. The User accesses the web app.
2. The Web App displays a login button to the User.
3. The User clicks the login button.
4. The Web App redirects the User to the OAuth2 Provider.
5. The User enters their credentials on the OAuth2 Provider’s login page.
6. The OAuth2 Provider validates the User’s credentials.
7. The OAuth2 Provider redirects the User back to the Web App with an
authorization code.
8. The Web App sends the authorization code to the OAuth2 Provider.
9. The OAuth2 Provider exchanges the authorization code for an access token.
10. The OAuth2 Provider sends the access token back to the Web App.
11. The Web App logs in the User using the access token.
Please note that this diagram provides a high-level overview of the OAuth2
login process and may not include all the intricacies of the protocol or specific


implementation details. It serves as a simplified representation of the general flow.
Here you asked for a different “language” of the graphics syntax: PlantUML. You can copy
the code above and run it on the PlantUML Online Server (https://www.plantuml.com/plant
uml/uml/). The picture you get is the following:

Figure 16.2: The UML diagram generated from the output of ChatGPT
16.3 Limitations and Tips for Graphics Generation 103

The sequence diagram explains how the login and authentication happened and how the access
token was created.
Note that this works because ChatGPT can accurately articulate how this process works.
If your process is too complicated or not known by ChatGPT, you should provide the detail
of how the different components interact in the prompt and ask ChatGPT to convert your
description into a graphics language.

16.3 Limitations and Tips for Graphics Generation


As a language model, its training data largely limits its capability. Generating graphics is
probably not the primary interest in building ChatGPT. It is well known that ChatGPT is
weak at some graphics, such as schematic diagrams of electronic circuits.
Also note that if you ask ChatGPT to give you a diagram, by default, it assumes you
mean some “ASCII art”, which usually doesn’t look right. Therefore it is essential to specify
some graphics language to use, and then you render the output into graphics. Below are some
examples:
⊲ Mermaid, as you saw in the first example above, can make flowcharts, sequence
diagram, entity-relationship diagram, Gantt chart, and mindmaps
⊲ PlantUML, as used in another example above, can make a lot of UML diagrams,
including sequence diagram, state diagram, and class diagram
⊲ For other simple graphics (e.g., those with only nodes and arrows), you can ask for
the Graphviz syntax, also known as the “dot language”
⊲ For generic graphics, you can ask for TikZ syntax, which is a package in LaTeX
⊲ For circuits, there is circuitikz which is a specialized version of TikZ

16.4 Summary
In this chapter, you learned that ChatGPT can generate text and graphics, albeit in the form
of some graphics language. Specifically, you saw how ChatGPT can
⊲ generate a block diagram depicting the interaction of different parties according to
your description
⊲ generate a sequence diagram to explain a complex logic to answer your question
Most importantly, the key to making ChatGPT generate graphics is to give enough details on
how the graph should be generated. You should specify the format (e.g., in Mermaid syntax)
and provide enough detail about what should be on the visualization.
In the next chapter, you will see one more example of combining the power of ChatGPT
with some other tool to boost productivity.
Creating a PowerPoint
Presentation using ChatGPT
17
Making ChatGPT your assistant to help you write an email is trivial since it is well-known
to be very capable of generating text. ChatGPT is not a robot that can light up your stove
and cook dinner. But you may wonder if it can generate something other than text. In the
previous chapter, you learned that ChatGPT could generate a graphic via an intermediate
language. In this chapter, you will learn about another example of using an intermediate
language, namely, VBA for PowerPoint. Specifically, you will learn:
⊲ How to make ChatGPT to generate a slide deck outline
⊲ How to convert a slide deck outline into an actual PowerPoint file
Let’s get started.

Overview
This chapter is divided into three parts; they are
⊲ Outline of a Pitching Deck
⊲ Running VBA and Obtaining the PowerPoint File
⊲ Generating Other File Formats

17.1 Outline of a Pitching Deck


Let’s consider a scenario: You were asked to explain to a software team and convince them
to switch from Java to Python. You know that Python is powerful, especially powered by its
ecosystem, community support, and online software repository. But building a story pitch
needs some thought.
You can make use of ChatGPT to create the story pitch. Your prompt should include:
⊲ Persona: ChatGPT should sound like an expert
⊲ Goal: You want an outline that you can use to build a slide deck
17.1 Outline of a Pitching Deck 105

⊲ Details: Your storyline should be that Python can work better than Java. Depending
on the use case, you may want to give more detail on a particular application, such
as REST API system
Therefore, you may try the following prompt:


You are an expert in Python programming and system development.
Write the outline for a slide deck to pitch the Python ecosystem to a Java veteran.
Tell them how Python can do everything they were doing with Java. Focus on the
benefits of easy to use, easy to develop, and easy to maintain. Especially focusing


on how Python supports building a scalable system with REST API support.
As expected, ChatGPT can give you an outline as follows:


Slide Deck: Pitching the Python Ecosystem to a Java Veteran
Slide 1: Introduction
⊲ Welcome and Introduction
⊲ Target Audience: Java Veterans
⊲ Objective: Show how Python can replace Java and offer benefits in ease
of use, development, and maintenance, with a focus on building scalable
systems with REST API support.
Slide 2: Overview of Python
⊲ Brief introduction to Python as a high-level programming language
⊲ Python’s popularity and its extensive ecosystem
Slide 3: Easy to Use
⊲ Python’s simplicity and readability compared to Java
⊲ Concise and expressive syntax
⊲ Reduced boilerplate code
Slide 4: Easy to Develop
⊲ Rapid prototyping and shorter development cycles
⊲ Wide range of built-in libraries and packages
⊲ Massive community support and extensive documentation
Slide 5: Easy to Maintain
⊲ Python’s emphasis on code readability and maintainability
⊲ Clean and organized code structure
⊲ Automated testing frameworks for better code quality
Slide 6: Scalable Systems
⊲ Python’s ability to build scalable systems with REST API support
⊲ Overview of Python frameworks such as Django and Flask
⊲ Support for microservices architecture
17.1 Outline of a Pitching Deck 106

Slide 7: REST API Support


⊲ Python’s robust libraries for REST API development
⊲ Introduction to popular libraries like Flask-RESTful and Django REST
framework
⊲ Building RESTful APIs with ease
Slide 8: Case Studies
⊲ Highlight successful companies and projects using Python for system
development
⊲ Showcase Python’s scalability and performance in real-world scenarios
Slide 9: Migration from Java to Python
⊲ Discuss strategies for migrating Java code to Python
⊲ Common challenges and how to overcome them
⊲ Tools and resources for a smooth transition
Slide 10: Conclusion
⊲ Recap the benefits of Python over Java in terms of ease of use, development,
and maintenance
⊲ Reinforce Python’s ability to build scalable systems with REST API
support
⊲ Encourage the Java veteran to explore the Python ecosystem
Slide 11: Questions and Discussion
⊲ Open the floor for questions, comments, and discussions
Slide 12: Thank You
⊲ Express gratitude for their time and attention
⊲ Provide contact information for further assistance or consultation


17.1 Outline of a Pitching Deck 107

Figure 17.1: ChatGPT generating an outline for a presentation

You should review what ChatGPT provided to you. You may also use a follow-up prompt
to ask ChatGPT to revise some slides or add some content. However, once you are satisfied
with the outline, you can tell ChatGPT to create the PowerPoint slide.
Since ChatGPT will not return a PowerPoint file to you, you need to find something to
generate PowerPoint. Just like you learned that Mermaid syntax is a way to present a sequence
diagram in the previous chapter, PowerPoint comes with Visual Basic for Application (VBA)
that can generate a slide deck using code.
For example, you can use this follow-up prompt to generate the VBA code that creates
the deck:


Now write the VBA code to create the PowerPoint slides for this deck. Occasionally


add humorous and whimsical content.
The output from ChatGPT is as follows:


Certainly! Here’s an example of VBA code that creates the PowerPoint slides for
the pitch deck, with occasional humorous and whimsical content:

Sub CreatePitchDeck()

Dim PowerPointApp As PowerPoint.Application


Dim PowerPointPres As PowerPoint.Presentation
Dim PowerPointSlide As PowerPoint.Slide
Dim SlideNum As Integer

...


17.2 Running VBA and Obtaining the PowerPoint File 108

Figure 17.2: ChatGPT generating VBA for a presentation

17.2 Running VBA and Obtaining the PowerPoint File


VBA is a language that PowerPoint has built-in support. You can run the code and obtain
a PowerPoint file in the following steps.
Firstly, open your PowerPoint application and create a new presentation. Then, you
should find “Visual Basic Editor” in the “Tools” menu, under “Macro” submenu.

Figure 17.3: Launching Visual Basic Editor

You should see a “VBAProject” window in the Visual Basic Editor. Right-click on that to
insert a new Module.
17.2 Running VBA and Obtaining the PowerPoint File 109

Figure 17.4: Inserting a new Module in the Visual Basic Editor

Then you can copy and paste the VBA code that ChatGPT generated into the Module window,
just as the screenshot below.
Then you are ready to run this VBA code to generate a PowerPoint file. All you need is
to click the “Run” button on the toolbar.

Figure 17.5: Pasting the VBA code and run

Running this will create another PowerPoint presentation with the content generated by
ChatGPT. You can discard the first presentation as it is empty and work on this one instead.
17.3 Generating Other File Formats 110

Figure 17.6: PowerPoint presentation generated

Note that the slides are bare, and you may want to apply a template to make them more
colorful. Instructions on switching a template to an existing presentation can be easily found
online. Also, note that the slide generated is not perfect. There could be some formatting
issues, for example. ChatGPT is just helping you to get started. It is your job to polish it
further.

17.3 Generating Other File Formats


You can see that the above provided a general workflow for producing any file format using
ChatGPT.
Firstly you need to know what programming language or markup language is possible for
that particular file format. For example, if it is not Microsoft PowerPoint but Google Slides,
there is a Google Slides API.
Then, it would help if you had a concrete idea of what to put in the file. In the above, you
mentioned the purpose and content that should be included in the PowerPoint presentation.
This helps ChatGPT generate the content for you. Of course, you can polish the result
ChatGPT provided using follow-up prompts such as “Remove the last slide” or “Add an
agenda slide at the beginning”.
Once you are ready with the content, you should ask ChatGPT to generate the code that
can, in turn, generate the final output. Depending on the desired file format, you may need
to run the code appropriately. In the example above, you launched PowerPoint and ran the
VBA. If you asked for a PDF and made ChatGPT generate LaTeX code for you, you need to
run the LaTeX compiler to generate the final output.

17.4 Summary
In this chapter, you learned how to create a PowerPoint file. In particular, you learned
⊲ How to make ChatGPT create an outline for your presentation
17.4 Summary 111

⊲ How to convert the outline into VBA code that can generate the actual presentation
⊲ How to execute the VBA to obtain the final output
This workflow may be adopted for other file formats.
This marks the end of this book.
III
Appendix
What Can ChatGPT Do?
A
ChatGPT or any other large language model is merely a trained machine learning model that
can generate text. Should there be any fact in the context it generates, it is either because
it remembered that from the training data, or because such combination fits probabilistically
according to the training data.
Consider the example if your prompt contains Albert Einstein, and relativity; you should
not be surprised if a model says Albert Einstein developed relativity and earned him a Nobel
prize (not for this reason, actually). Probably from the training data, the model learned about
the high probability of collocation between Einstein and relativity, as well as Einstein and
probability. Therefore mistakes were made. We call this the hallucination of a large langauge
model. After all, the model size is large, but the training data set is much larger. We should
not imagine a model can remember everything in the training dataset.
When using ChatGPT, you must consider whether hallucination works for you. See the
table below to compare:

Hallucinate Not Hallucinate


Use case Creative writing, brainstorming Information extraction, rewriting,
summarization, and translation
Prompt Describe output format and style Provide data and instruction for
action
Output Model is free to generate anything Instruction in the prompt confined the
that matches the prompt model’s focus to the provided data

There are use cases sitting in between. For example, making ChatGPT your teacher
to generate a study plan would require some imagination, but also preferred not to be too
creative that the output is out of context or unrealistic. This is the difficult part of the model
to keep the level of hallucination at the sweet spot.
Prompt Engineering Cheatsheet
B
Kids in United States had a game called funny fill-in which a template passage with a lot of
blanks are provided, and they are supposed to fill in words in the blanks to make up a story,
however ridiculous it would be. The blanks are hinted with “person’s name”, “color” and so
on to help make the passage meaningful.
Below are some fill-in templates of the same fashion. It can help you interact with
ChatGPT better.

B.1 Creative Generation


These use cases are to leverage large language model’s hallucination to help you brainstorm.
You provide the instructions on what you expect the output should be and let the model
generate the output. The output may contain false information, which you should polish it
further.

Writing
Write a format, e.g., blog post on topic, e.g., why electric car is not environmental friendly in style, e.g. humorous
style. You should provide number arguments, including list of ideas you want to include but do
not mention list of ideas you do not want to include .

Completion
Can you action, e.g., complete the following paragraph with instructions, e.g., the same style ?
put your partial paragraph here

Idea Generation
As a role, e.g., chemistry professor , you are an expert in topic, e.g., sports . Give me
number ideas / examples for use case, e.g., birthday gift about subject, e.g., data science covering
additional details .
B.2 Exact and Accurate Response 115

B.2 Exact and Accurate Response


Rewriting
Rewrite the following into adjective, e.g., friendly style, e.g., an email : paragraphs here

Summarization
Summarize the following into number words: paragraphs here

Information Extraction
Identify the topics, e.g., action items from the following format, e.g., meeting minutes and recap in
format, e.g., point forms : content here

Graphic Generation
Create a format, e.g., sequence diagram in Mermaid.js for description of all the components in detail

Follow-up Prompts
Make the above refer to the previous dialog into different style, e.g., longer but less formal

Translation
Traslate the following from a language, e.g., Java to another language, e.g., French : content to translate

B.3 In-between
Critiques
Provide number ways to improve my what should it be, e.g., press release : text to critique here

Guided Response
Provide a format, e.g., email response to the following format, e.g., letter to adjective, e.g., politely
theme, e.g., refuse the request : relevant text here .

How-to
Provide step-by-step instructions/N-day plan on topic, e.g., cutting down a tree

Generate names
Suggest number adjective, e.g., eye-catching topic, e.g., titles for my description, e.g., fiction on apocalypse
with additional detail
B.4 Keywords 116

Programming
What is the Excel formula / NumPy function for task, e.g., calculating the monthly payment for a fixed-rate mortgage

Review Code
Identify the bug in the following code and suggest a rewrite: insert your source code here

Testing Code
Please generate unit tests for the following code: insert your source code here

Software Engineering Projects


I want to your goal, e.g., build a web site support authentication using Gmail account , please generate the
task, e.g., backend code for me in language

B.4 Keywords
A good prompt can guide the model to generate useful response. In the prompt, think if you
provided details to the who, when, what, where, why, how questions. If you are struggling to
create a good prompt, let the keywords below to inspire you:

Role Experienced fitness trainer. Philosophy professor. Software engineering lead.


Marketing specialist.

Action Curate a list. Generate N keywords. Give N counterexamples. Tips and tricks.
Paraphrase. Rewrite. Correct typos and grammatical errors.

Style Explain to a 5-year-old. In 500 words. Concise. Using humor. Appealing tone. Playful
tone. Persuasive. Explain with a metaphor. With examples. With headings and subheadings.

Output format High-volume SEO keywords. Hashtags. Search terms. Blog post. Social
media ad. Journal article. Movie plot. School essay. Interview questions. Formal letter.
Step-by-step guide.

Details Highlight the benefits. Comfort the recipient. Emphasizing. Avoiding. Balance
between. Add a call-to-action.
How Far You Have Come

You made it. Well done. Take a moment and look back at how far you have come.
⊲ You learned what is ChatGPT and in general, what is a large language model
⊲ You learned what ChatGPT expects in the prompt, and how the prompt can shape
its response
⊲ You learned how to make use of the hallucination as a feature to help you brainstorm
and generate creative contents
⊲ You also learned how to provide detailed information in the prompt to prohibit
hallucination, using ChatGPT merely as an assistant who understands your instruction
⊲ You discovered ChatGPT not only can help you write paragraphs, but also generate
graphics or files if you combine its output with some other tools
Don’t make light of this. You have come a long way in a short amount of time. You have
developed the important and valuable skill of being able to make ChatGPT work in your
favor. Once you are familiar with it, you have a high performance assistant at a very low cost,
and its help can boost your productivity a lot. To shed some light on what you can do now,
you can imagine you’re a student graduating from school and looking for a job, then
⊲ You can ask ChatGPT to give you some idea on what to mention in the cover letter
(Chapter 7)
⊲ You can describe your credential and interest and ask ChatGPT to write your resume
(chaptername 9)
⊲ You can ask ChatGPT to help you practice for interview (Chapter 10)
⊲ You can ask ChatGPT to write a very nice thank you letter in response to a job offer
(Chapter 14)
We want to take a moment and sincerely thank you for letting us help you start your
journey with ChatGPT. We hope you feel yourself empowered by this new technology.

You might also like