Casting a spell on ChatGPT: Let it write Anki cards for you — A Prompt Engineering Case

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:

dair-ai/Prompt-Engineering-Guide: Guides, papers, lecture, and resources for prompt engineering (github.com)

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:

open-spaced-repetition/fsrs4anki: A modern Anki custom scheduling based on free spaced repetition scheduler algorithm (github.com)

This tutorial is posted firstly in my medium:

Casting a spell on ChatGPT: Let it write Anki cards for you — A Prompt Engineering Case | by Jarrett Ye | Feb, 2023 | Medium

13 Likes

Hi i love your prompt. But for some reason when i copy the table into google sheets or Excel they are pasted in one straight line and not in the cells. Do you know a solution for that?

chatGTP told me how to!
To add the above table to Excel, you can follow these steps:

  1. Open Excel and create a new workbook or open an existing one.
  2. Select the cell where you want to start entering the table, usually A1.
  3. Copy the table from this chat window by selecting all rows and columns, right-clicking and selecting “Copy” or pressing “Ctrl+C” on your keyboard.
  4. Go back to Excel and right-click on the cell where you want to paste the table.
  5. Select “Paste” or press “Ctrl+V” on your keyboard.
  6. Excel will automatically detect the rows and columns and paste the table into your worksheet.

You can then adjust the formatting and styles as needed

I made a service that is doing all the stuff: https://ankigpt.wtf

2 Likes

The other day I had an idea that might be better.
The problem with telling CGPT to make flashcards for you is,
it does not target specifically your weak points. It does not target specifically the knowledge you are looking for.

So my idea is something like this.

  1. Use AutoHotkey so that every ctrl+c you do is sent to a .txt file separated by lines. (The contents of your ctrl+c are the bits of information you wish to remember.) Pass that .txt file to an .xlsx excel file.
  2. The result is you have a sheet with the bits of knowledge that you wish to remember
  3. Use the CGPT plugin on google sheets to get cgpt to generate the questions for you.

The input: a column(“Column A”) with all the bits of information you wish to remmember
The output: Column A, with another column(Column B) containing the questions for Column A

This new sheet can easily be turned into an Anki deck.

So my idea is kind of the same, but cgpt generates the questions for you, instead of both the questions and answers. This makes the flashcards more suited to your knowledge and circumstances.

1 Like

chatgpt is just gpt 3.5, only got 30% on usmle,

try gpt4, it got 80% on usmle.

much smarter.

and the plugins.

Hey! I like your prompt. But I’m having a bit of trouble with it. Whenever I try to copy the table into Google Sheets or Excel, it passes as one long line instead of filling it into separate cells. Do you have any ideas on how to fix this?

hi,

i am a med student.

i have used the OP’s prompt and mine, which is a simple 1 line prompt.

Let others (likely the one in the field) to compare the results.

text: (subtitle from a utube video on hematuria)
This summary presents the essential points about the causes of hematuria, as outlined in the provided video transcript. Hematuria, the presence of blood in urine, can arise from various conditions affecting different parts of the urinary and reproductive systems in both males and females. The video begins by reviewing the anatomy of the male and female urinary systems, highlighting key structures. It then discusses the significance of identifying the timing of hematuria during urination (initial, terminal, or throughout) to localize the potential source of bleeding, with early or terminal hematuria suggesting a lower urinary tract source, and persistent hematuria indicating potential kidney or bladder involvement.

The video enumerates several differential diagnoses for hematuria:

  • Recent urological procedures, such as bladder catheterization, urethral stents, or prostate biopsy.
  • Conditions like benign prostatic hyperplasia, urinary tract infections (UTIs), pyelonephritis, trauma, and cancers along the urinary tract.
  • Glomerular diseases, including glomerulonephritis, caused by various factors like infections, drugs, autoimmune diseases, diabetes, and hypertension.
  • Kidney stones, particularly those lodging in the ureter (urolethiasis), typically formed from calcium oxalate and often stuck at narrow points along the ureter.
  • Polycystic kidney disease, a genetic disorder leading to the formation of cysts around the kidneys.
  • For females, specific considerations include endometriosis and pseudo-hematuria, which can be related to menstrual bleeding or recent sexual activity.
  • Coagulopathies, where impaired blood clotting leads to bleeding.

Investigations for hematuria may include a full blood count to check for anemia and infection, urine dipstick tests followed by microscopic examination and culture, coagulation studies, urinary bladder cancer markers (especially in individuals over 40 years old), prostate-specific antigen (PSA) tests for prostate cancer, and imaging studies like CT scans or ultrasounds to visualize the kidneys and urinary tract for abnormalities such as cysts indicative of polycystic kidney disease.

These diagnostic steps are crucial for determining the underlying cause of hematuria and guiding appropriate treatment and management strategies.

^-- the above is subtitle from a utube video on hematuria.

trial 1

trial 2

trial 3

let’s guess it blindly.

thank you.

ps: i appreciate LMS’s work. i am proud of him.

off topic, deleted