Anki is an incredibly helpful tool for learning and remembering information using spaced repetition. I won’t go into detail about why it works the way it does or the exact algorithm behind it, but if you don’t know Anki and spaced repetition learning:
The brain forgets new and old information at a given rate.
Hence, it would be very convenient for learning facts (such as vocabulary) if we had a program that gave us the information we are supposed to know at roughly the time we would forget it. One such program is Anki. It allows you to create decks with flashcards, go through them with a given rate of new cards per day, and repeat the older cards according to the spaced repetition idea.
As I mentioned in my previous blog Getting back into Japanese, I learned (and still learn) Japanese during COVID and now I am taking a Russian course at my university. For both, I have used Anki extensively, mainly for vocabulary, sentences with unknown verbs, or grammar.
For Japanese, I would just throw sentences with unknown words I encountered while reading (called sentence mining) into Anki and repeat (called repping) those. This is incredibly efficient if done correctly.
For Russian, however, since we have a set of vocabulary and grammar to learn during a semester, I simply generate Anki cards based on the provided vocabulary lists in a PDF. For that, I would parse the PDF (which neatly contained tables with Russian in one column and the translation in the other column) and generate the inputs for the cards automatically. However, creating the cards would still have been too much effort for me. So I used Anki Connect, an add-on for Anki which
communicates with Anki over a simple HTTP API.
This is very neat since we can now use something like Python to call this API and
execute queries against the user’s card deck, automatically creating new cards, and more.
So I parsed the PDF and generated the cards automatically, but then I had a much better idea. Considering we also have grammar to study, conjugations of words, and very specific topics to talk about in an oral exam, why not just generate short sentences with A1 grammar and rep those.
I didn’t have the time to immerse much in Russian, so I could not sentence mine, and repping Anki cards is way more efficient for passing tests. (As much as I like learning languages, I first and foremost need to pass exams with very little time to study due to other exams…).
But where to get the sentences with exactly the words and grammar I need? Well, you probably guessed from the title of the blog that I used AI, mainly Le Chat free version. I just needed a program to generate Anki cards based on an input, and then, if I knew my input format, I could just tell the AI to generate input data for me. The program for that roughly looked like this:
import requests
vocab = [
{
"russian": "Я встаю рано.",
"english": "Ich stehe früh auf.",
"category": "Grammar Test",
"grammar_explanation": "'Я встаю' ist die 1. Person Singular Präsens von 'вставать'."
},
{
"russian": "Ты встаёшь поздно.",
"english": "Du stehst spät auf.",
"category": "Grammar Test",
"grammar_explanation": "'Ты встаёшь' ist die 2. Person Singular Präsens von 'вставать'."
},
.......
]
def create_deck(deck_name):
result = requests.post('http://localhost:8765', json={
"action": "createDeck",
"version": 6,
"params": {
"deck": deck_name
}
}).json()
return result
def add_note_to_anki(note, deck_name):
result = requests.post('http://localhost:8765', json={
"action": "addNote",
"version": 6,
"params": {
"note": {
"deckName": deck_name,
"modelName": "Basic",
"fields": {
"Front": note["russian"],
"Back": note["english"]
},
"tags": ["russian", "A1", note["category"].lower()],
"options": {
"allowDuplicate": False
}
}
}
}).json()
return result
def main():
# Collect unique deck names
deck_names = set(f"Russian::Own Cards::{entry['category']}" for entry in vocab)
# Create each deck
for deck_name in deck_names:
result = create_deck(deck_name)
if result.get("error") is None:
print(f"Ensured deck exists: {deck_name}")
else:
print(f"Error creating deck {deck_name}: {result['error']}")
# Add notes
for entry in vocab:
deck_name = f"Russian::Own Cards::{entry['category']}"
result = add_note_to_anki(entry, deck_name)
if result.get("error") is None:
print(f"Added to {deck_name}: {entry['russian']} - {entry['english']}")
else:
print(f"Error adding {entry['russian']} to {deck_name}: {result['error']}")
if __name__ == "__main__":
main()
Loops through vocab
, looks at category
, creates a deck with this name in a given path (Russian::Own Cards::[category]
), writes the Russian sentence to the front, and the explanation to the back. Easy. The only thing I had to get now was the input data, and for that, I copied and pasted some example input into the message box for the AI and told it something along the lines of:
Look at my example data for a small Python script and generate similar input data. I want cards with short sentences with A1 grammar and A1 vocabulary, specifically example sentences with all conjugations of [….] and example sentences containing [….]
And so on. I copied and pasted that into the script above and generated my cards. category
could be anything. I have one for numbers
, I had some for directions
, etc.
I think this can be extended further: let’s assume you had a mining.txt
which contains sentences and words you found while immersing in your target language, each entry being one line. You automatically get a translation from LibreTranslate, which provides a nice API, and write that into the backside of the card. I.e., you have hundreds of lines of unknown words and sentences in one text file (all the words and sentences mined during a week) and then automatically add them to Anki in one go.
How this might work after the so-called monolingual transition (when you no longer use translations but dictionary entries from your target language) is up for debate. Not all languages and online dictionaries provide nice APIs, and it would be difficult to look up only that one unknown word in a sentence. The latter might be possible if you had a database of all your known words (i.e., Anki… assuming it contains your entire vocabulary in that language somehow).
There’s still room for improvement in this workflow, but the script is a nice way to generate Anki cards for studying specifically for tests at least.