I meant to take a break today, but my hands itched. It’s been a while since I produced original writing, so I want to share my lessons on tinkering with ChatGPT recently.
If you have read my Reddit post — AnkiGPT: teach ChatGPT to create cards for you, you may be impressed by the flashcards made by ChatGPT:
You may wonder how I teach ChatGPT to make flashcards. Let me show you how to instruct ChatGPT to succeed step by step with some basic techniques of Prompt Engineering.
Prompts involve instructions and context passed to a language model to achieve a desired task.
Prompt engineering is the practice of developing and optimizing prompts to efficiently use language models (LMs) for a variety of applications.
Basic Prompt
To begin with, what’s the first prompt that comes to your mind if you want to make ChatGPT create flashcards for you? As the simplest form:
Me: balabalabala (a text). I want you to create a deck of flashcards from the above text.
However, this prompt didn’t work well:
It looks like ChatGPT understands the concept of flashcards. But the flashcards it made had lengthy answers. This stands against the Minimum Information Principle and is impossible to memorize.
Let’s improve on the prompt and specify our requirements for flashcards:
I want you to create a deck of flashcards from the text.
Instructions to create a deck of flashcards:
- Keep the flashcards simple, clear, and focused on the most important information.
- Make sure the questions are specific and unambiguous.
- Use simple and direct language to make the cards easy to read and understand.
- Answers should contain only a single key fact/name/concept/term.
Text: The contraction of any muscle is associated with electrical changes called ‘depolarization’, and these changes can be detected by electrodes attached to the surface of the body. Since all muscular contraction will be detected, the electrical changes associated with contraction of the heart muscle will only be clear if the patient is fully relaxed and no skeletal muscles are contracting. Although the heart has four chambers, from the electrical point of view it can be thought of as having only two, because the two atria contract together (‘depolarization’), and then the two ventricles contract together.
The result:
Turns out the generated cards have shorter answers than before. Maybe some of you find it good enough, but I see some room for improvement. What’s next? Give ChatGPT some examples!
Few-shot prompts
There is a classic example of writing good cards, i.e. the 20 rules proposed by SuperMemo:
Let’s try teaching ChatGPT with this example:
I want you to create a deck of flashcards from the text.
Instructions to create a deck of flashcards:
- Keep the flashcards simple, clear, and focused on the most important information.
- Make sure the questions are specific and unambiguous.
- Use simple and direct language to make the cards easy to read and understand.
- Answers should contain only a single key fact/name/concept/term.
Text: The characteristics of the Dead Sea: Salt lake located on the border between Israel and Jordan. Its shoreline is the lowest point on the Earth's surface, averaging 396 m below sea level. It is 74 km long. It is seven times as salty (30% by volume) as the ocean. Its density keeps swimmers afloat. Only simple organisms can live in its saline waters
A deck of flashcards:
Q: Where is the Dead Sea located?
A: on the border between Israel and Jordan
Q: What is the lowest point on the Earth's surface?
A: The Dead Sea shoreline
Q: What is the average level on which the Dead Sea is located?
A: 396 meters (below sea level)
Q: How long is the Dead Sea?
A: 74 km
Q: How much saltier is the Dead Sea as compared with the oceans?
A: 7 times
Q: What is the volume content of salt in the Dead Sea?
A: 30%
Q: Why can the Dead Sea keep swimmers afloat?
A: due to high salt content
Q: Why is the Dead Sea called Dead?
A: because only simple organisms can live in it
Q: Why only simple organisms can live in the Dead Sea?
A: because of high salt content
Text: The contraction of any muscle is associated with electrical changes called ‘depolarization’, and these changes can be detected by electrodes attached to the surface of the body. Since all muscular contraction will be detected, the electrical changes associated with contraction of the heart muscle will only be clear if the patient is fully relaxed and no skeletal muscles are contracting. Although the heart has four chambers, from the electrical point of view it can be thought of as having only two, because the two atria contract together (‘depolarization’), and then the two ventricles contract together.
As expected, ChatGPT got what I wanted to do, and it created two more cards making the result well-around:
Is there any other way to improve it?
Chain-of-Thought (CoT) Prompting
Don’t forget that there is something called the Chain of Thought ability. Given some reasoning, ChatGPT generates better results. Therefore, we can teach him how to create flashcards step by step to meet our needs (To keep the example short, I removed the few-shot examples, which helps you observe the effect of CoT on its own )
I want you to create a deck of flashcards from the text.
Instructions to create a deck of flashcards:
- Keep the flashcards simple, clear, and focused on the most important information.
- Make sure the questions are specific and unambiguous.
- Use simple and direct language to make the cards easy to read and understand.
- Answers should contain only a single key fact/name/concept/term.
Let's do it step by step when creating a deck of flashcards:
1. Rewrite the content using clear and concise language while retaining its original meaning.
2. Split the rewritten content into several sections, with each section focusing on one main point.
3. Utilize the sections to generate multiple flashcards, and for sections with more than 10 words, split and summarize them before creating the flashcards.
Text: The contraction of any muscle is associated with electrical changes called ‘depolarization’, and these changes can be detected by electrodes attached to the surface of the body. Since all muscular contraction will be detected, the electrical changes associated with contraction of the heart muscle will only be clear if the patient is fully relaxed and no skeletal muscles are contracting. Although the heart has four chambers, from the electrical point of view it can be thought of as having only two, because the two atria contract together (‘depolarization’), and then the two ventricles contract together.
A deck of flashcards:
Now ChatGPT knows how to keep the answer short and easy to understand:
Could it be better? I applied Few-shot and Chain-of-Thought together and got the following results:
They feel much better than the original cards! Of course, this prompt can also be improved, so I’ll leave this task to you.
Adjust the output format
So how do you get ChatGPT to output a table? It’s really simple, just add an extra step in Chain-of-Thought to instruct ChatGPT to output in the specified format. Or in Few-shot, change the example to the output format you want.
I want you to create a deck of flashcards from the text.
Instructions to create a deck of flashcards:
- Keep the flashcards simple, clear, and focused on the most important information.
- Make sure the questions are specific and unambiguous.
- Use simple and direct language to make the cards easy to read and understand.
- Answers should contain only a single key fact/name/concept/term.
Let's do it step by step when creating a deck of flashcards:
1. Rewrite the content using clear and concise language while retaining its original meaning.
2. Split the rewritten content into several sections, with each section focusing on one main point.
3. Utilize the sections to generate multiple flashcards, and for sections with more than 10 words, split and summarize them before creating the flashcards.
Text: The characteristics of the Dead Sea: Salt lake located on the border between Israel and Jordan. Its shoreline is the lowest point on the Earth's surface, averaging 396 m below sea level. It is 74 km long. It is seven times as salty (30% by volume) as the ocean. Its density keeps swimmers afloat. Only simple organisms can live in its saline waters
A deck of flashcards:
|Question|Answer|
|---|---|
|Where is the Dead Sea located?|on the border between Israel and Jordan|
|What is the lowest point on the Earth's surface?|The Dead Sea shoreline|
|What is the average level on which the Dead Sea is located?|396 meters (below sea level)|
|How long is the Dead Sea?|74 km|
|How much saltier is the Dead Sea as compared with the oceans?|7 times|
|What is the volume content of salt in the Dead Sea?|30%|
|Why can the Dead Sea keep swimmers afloat?|due to high salt content|
|Why is the Dead Sea called Dead?|because only simple organisms can live in it|
|Why only simple organisms can live in the Dead Sea?|because of high salt content|
Text: The contraction of any muscle is associated with electrical changes called ‘depolarization’, and these changes can be detected by electrodes attached to the surface of the body. Since all muscular contraction will be detected, the electrical changes associated with contraction of the heart muscle will only be clear if the patient is fully relaxed and no skeletal muscles are contracting. Although the heart has four chambers, from the electrical point of view it can be thought of as having only two, because the two atria contract together (‘depolarization’), and then the two ventricles contract together.
Then ChatGPT learned:
Importing the cards into Anki
Although ChatGPT is so smart at making cards, you can’t just copy and paste them one by one into Anki, right? What a bummer!
In fact, many people don’t know that Anki can import .csv table files. And ChatGPT output table can be directly pasted into Excel!
Then save it in .csv format:
Open Anki and click Import:
Open the .csv file that you just saved, choose Basic template, choose what deck you want to import into, and click Import:
The final result:
I hope this tutorial will be helpful to you.
References
Prompt engineering guides:
Principles of writing good cards:
20 rules of formulating knowledge in learning
How to write good prompts: using spaced repetition to create understanding (andymatuschak.org)
By the way, I have also developed a new spaced repetition algorithm for Anki:
This tutorial is posted firstly in my medium: