๐ง Anki Sentence Miner
AI-powered sentence generation for Anki โ Turn your vocabulary cards into natural, contextual sentences using Google's Gemini AI.
Sentence Miner bridges the gap between memorizing isolated words and understanding them in real conversation. It reads your vocabulary deck, identifies which words you know well and which you're still learning, then generates sentences that mix them together โ just like how you'd encounter them in the real world.
โจ Features
Two Card Types
| Type |
What It Does |
Example |
| ๐ฒ Cloze Recall |
Hides known words so you recall them from context |
็ซใ{{c1::ๅฑๆ น}}ใฎไธใซๅบงใฃใฆใใ |
| ๐ New Word |
Introduces unfamiliar words alongside known ones |
็ซใๅฑๆ นใฎไธใซๅบงใฃใฆใใ |
You control the mix with a slider (default: 70% cloze / 30% new word).
Smart Word Selection
The add-on doesn't just randomly pick words. It uses several strategies to create better sentences:
- Tag-Aware Sampling โ If your vocabulary cards are tagged (e.g.,
food, travel, JLPT_N3), the generator groups words by topic and creates thematically coherent sentences instead of random word combinations.
- Priority-Weighted New Words โ Words you struggle with (high lapse count, low ease factor) or haven't seen yet are prioritized for introduction. This means the sentences focus on words that need the most reinforcement.
- Confidence Threshold โ You define what "known" means by setting a minimum review interval (e.g., 7 days). Cards above that interval are considered known; everything below is a candidate for introduction.
Performance Optimized
- In-Memory Cache โ Word lists are cached for 5 minutes, so hitting "Generate" multiple times doesn't re-query your entire deck each time.
- Note-Level Deduplication โ Fetches each note only once even if it has multiple cards (e.g., forward + reverse cards), preventing duplicate words.
- Background Generation โ API calls run in a background thread so Anki's UI stays responsive.
Natural Sentences
The Gemini prompt is carefully crafted to produce sentences that:
- Sound like something a native speaker would actually say
- Fit daily conversation contexts
- Match the learner's current level
- Are NOT awkward combinations of random vocabulary
Natural Grammar & Conjugation
- Context-Aware Conjugation โ The AI understands that words in your deck are dictionary forms (lemmas). It automatically conjugates verbs and adjusts nouns/adjectives to fit the sentence context naturally (e.g., changing "go" to "went").
- Smart Cloze Matching โ Even when a word is conjugated, the cloze deletion handles it correctly, hiding the actual used form while preserving the underlying concept.
- Optional Grammar Breakdown โ Can't figure out why a word changed its ending? Enable "Grammar Breakdown" to get a word-by-word analysis of particles, tense, and sentence structure added to your card notes.
๐ฆ Installation
1. Locate Your Add-ons Folder
In Anki, go to Tools โ Add-ons โ View Files Folder (or open the folder manually):
| OS |
Path |
| Windows |
%APPDATA%\Anki2\addons21\ |
| macOS |
~/Library/Application Support/Anki2/addons21/ |
| Linux |
~/.local/share/Anki2/addons21/ |
2. Copy the Add-on
Copy or symlink the entire anki-sentence-miner folder into addons21/:
addons21/
โโโ anki-sentence-miner/
โโโ __init__.py
โโโ config.json
โโโ config.md
โโโ manifest.json
โโโ sentence_generator.py
โโโ note_manager.py
โโโ ui.py
3. Restart Anki
Close and reopen Anki. You should see a new Sentence Miner submenu under Tools.
๐ Setting Up Your Gemini API Key (Free)
On first launch, the add-on will prompt you to enter an API key. You can also access this anytime via Tools โ Sentence Miner โ API Key Setup.
- Go to Google AI Studio โ API Keys
- Sign in with your Google account
- Click "Create API Key"
- Select any Google Cloud project (or create one โ it's free, no credit card required)
- Copy the key and paste it into the add-on dialog
- Click "Test Key" to verify it works
- Click "Save"
Free Tier Limits
| Model |
Requests/Min |
Requests/Day |
| gemini-2.5-flash |
10 |
250 |
| gemini-2.5-flash-lite |
15 |
1,000 |
This is more than enough โ generating 5 sentences uses 1 request.
๐ Usage
Generating Sentences
- Go to Tools โ Sentence Miner โ Generate Sentences
- Configure the settings:
| Setting |
What It Controls |
| Source Deck |
The vocabulary deck to pull words from |
| Language I'm Learning |
Target language (e.g., Japanese, Spanish) |
| My Native Language |
Language for translations (e.g., English) |
| Known Word Threshold |
Minimum interval (days) for a word to count as "known" |
| Known Words in Sentence |
Target percentage of known words per sentence |
| Card Type Mix |
Ratio of Cloze cards vs New Word cards |
| Sentences to Generate |
How many sentences per batch (1โ20) |
| Sentence Deck |
Name of the deck where generated cards will go |
- Click โก Generate Sentences
- Review the generated sentences in the preview table
- Uncheck any sentences you don't want
- Click โ
Add Selected to Deck
Settings Are Remembered
All settings are saved automatically and restored next time you open the dialog.
๐ Card Structure
AI Sentence (Basic)
| Field |
Content |
| Sentence |
The target-language sentence with new words in bold |
| Translation |
Natural translation in your native language |
| NewWords |
List of new words with readings and definitions |
| Notes |
Additional context (if any) |
Front shows the sentence with a hint button for new words. Back reveals the translation and word definitions.
AI Sentence Cloze
| Field |
Content |
| Text |
The sentence with {{c1::hidden_word}} cloze deletions |
| Translation |
Natural translation in your native language |
| Notes |
Additional context (if any) |
Front shows the sentence with blanks. Back reveals the hidden words and translation.
Both card types include styled templates with:
- Clean typography (Noto Sans family)
- Dark mode support
- Color-coded new words (orange) and cloze words (blue)
โ๏ธ Configuration
You can edit the config via Tools โ Add-ons โ Sentence Miner โ Config, or directly in config.json:
{
"gemini_api_key": "",
"target_language": "",
"native_language": "",
"source_deck": "",
"sentence_deck": "AI Sentences",
"known_interval_days": 7,
"known_word_percentage": 70,
"cloze_percentage": 70,
"sentences_per_batch": 5,
"gemini_model": "gemini-flash-latest"
}
See config.md for detailed explanations of each setting.
๐งฉ How It Works Under the Hood
Word Classification
Your Vocabulary Deck
โ
โโโ Cards with interval >= threshold โโโ KNOWN WORDS
โ (e.g., interval >= 7 days) Used for cloze blanks
โ and sentence scaffolding
โ
โโโ Cards with interval < threshold โโโ NEW/WEAK WORDS
(new, learning, or young cards) Introduced in context
Sorted by priority: with known-word support
โข High lapses = higher priority
โข Low ease = higher priority
โข Brand new = high priority
Smart Sampling Pipeline
All Known Words (e.g., 3,000)
โ
โโโ Group by Anki tags
โ food: [rice, fish, cook, ...]
โ travel: [hotel, ticket, map, ...]
โ JLPT_N3: [ๆฑบใใ, ๅฑใใ, ...]
โ
โโโ Pick 1-2 focus tag groups
โ
โโโ Sample 70% from focus groups โโโ Thematic coherence
โโโ Sample 30% from others โโโโโโโโโ Variety
โ
50 words to prompt
All New Words (e.g., 500)
โ
โโโ Calculate priority score per word
โ score = lapsesร2 + (3-ease) + new_bonus
โ
โโโ Sort by priority (with jitter)
โ
โโโ Sample from top candidates โโโ 20 words to prompt
Generation Flow
[Smart-sampled words] โโโ [Gemini Prompt] โโโ [API Call]
โ
[JSON Response]
โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ โ
Cloze Cards New Word Cards
[[word]] โ {{c1::word}} **word** โ <b>word</b>
โ โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ
[Preview Table]
โ
[User accepts/rejects]
โ
[Add to Deck]
๐๏ธ Project Structure
anki-sentence-miner/
โโโ __init__.py # Entry point โ menu registration, first-run check
โโโ config.json # Default settings
โโโ config.md # User-facing config documentation
โโโ manifest.json # Anki add-on metadata
โโโ sentence_generator.py # Word retrieval, smart sampling, Gemini API
โโโ note_manager.py # Deck/note type creation, card templates
โโโ ui.py # PyQt dialogs (API key wizard + generator)
โโโ README.md # This file
๐ค Dependencies
- Anki 2.1.55+ (uses modern Qt6/PyQt6 APIs)
- google-genai Python package (auto-installed on first run if missing)
- A free Gemini API key
๐ License
MIT License โ feel free to use, modify, and distribute.