Spaced Repetition Algorithms in Python — Core Concepts

Spaced repetition systems (SRS) schedule review sessions based on how well a learner remembers each item. Instead of reviewing everything equally, the system concentrates effort on items the learner is about to forget. Python is a popular choice for building these systems because of its rich ecosystem for data modeling and its readability when implementing mathematical scheduling formulas.

The Forgetting Curve

Hermann Ebbinghaus discovered in 1885 that memory decays exponentially after learning. Without review, you lose roughly 50% of new information within a day and 80% within a week. Spaced repetition exploits a complementary effect: each successful recall strengthens the memory and slows future decay. The goal is to schedule reviews at the point where recall probability drops to a target threshold, typically around 90%.

The Leitner System

The simplest spaced repetition approach uses physical or virtual boxes. New items start in Box 1 and get reviewed daily. A correct answer moves the item to Box 2, which is reviewed every three days. Another correct answer sends it to Box 3 at weekly intervals, and so on. A wrong answer sends the item back to Box 1.

This is easy to implement in Python with a dictionary mapping box numbers to lists of items and a schedule dictionary mapping box numbers to day intervals. The downside is that every item in the same box gets the same interval regardless of individual difficulty.

SM-2: The Algorithm Behind Anki

SuperMemo 2 (SM-2), published in 1987 by Piotr Wozniak, assigns each item its own scheduling parameters. Three values track each item: an easiness factor (starting at 2.5), a repetition count, and the current interval in days.

After each review, the learner rates their recall on a 0–5 scale. Ratings below 3 reset the item to the beginning. Ratings of 3 or above increase the interval: the first successful review sets the interval to 1 day, the second to 6 days, and subsequent reviews multiply the previous interval by the easiness factor. The easiness factor itself adjusts after each review, increasing for easy recalls and decreasing for hard ones, with a floor of 1.3.

SM-2 remains the most widely deployed algorithm because it is simple, effective, and has decades of real-world validation through Anki’s millions of users.

FSRS: The Modern Approach

Free Spaced Repetition Scheduler (FSRS), developed by Jarrett Ye starting in 2022, uses a mathematical model based on the three-component theory of memory. Each item carries four stability-related parameters instead of SM-2’s single easiness factor. FSRS models both memory stability (how long until forgetting) and difficulty separately, then uses machine learning to optimize parameters from a user’s actual review history.

In benchmarks on millions of Anki reviews, FSRS reduced unnecessary reviews by 20–30% compared to SM-2 while maintaining the same retention rate. Anki adopted FSRS as a built-in option in version 23.10.

How It Works in Practice

A typical Python implementation maintains a database of items, each with scheduling metadata. When the user starts a session, the system queries for items whose next review date is today or earlier. After each review, the algorithm recalculates the next interval and updates the database.

The core loop is straightforward: fetch due items, present them to the user, collect a rating, update the schedule, and persist the changes. What makes each algorithm different is the update step — how it translates a rating into a new interval.

Key Tradeoffs

SM-2 is battle-tested and simple but treats all learners the same initially and adapts slowly. FSRS personalizes faster because it fits parameters to individual review data, but it requires enough history (roughly 400+ reviews) to outperform SM-2. The Leitner system works well for small decks with uniform difficulty but breaks down when items vary widely.

Another consideration is computational cost. SM-2 updates are pure arithmetic. FSRS parameter optimization involves gradient descent, which takes seconds on thousands of reviews. For most applications this happens offline and infrequently, so it rarely matters.

Common Misconception

Many people assume spaced repetition means reviewing at fixed, expanding intervals like 1-3-7-14-30 days. In reality, the intervals are dynamic and personalized. Two learners studying the same deck will have completely different schedules after a few weeks because their recall patterns diverge.

The one thing to remember: Spaced repetition algorithms like SM-2 and FSRS calculate when you are most likely to forget each item, then schedule a review just before that moment — turning forgetting from an enemy into a tool for building durable memory.

pythonspaced-repetitionlearningeducation-technology

See Also

  • Python Adaptive Learning Systems How Python builds learning apps that adjust to each student like a personal tutor who knows exactly what you need next.
  • Python Airflow Learn Airflow as a timetable manager that makes sure data tasks run in the right order every day.
  • Python Altair Learn Altair through the idea of drawing charts by describing rules, not by hand-placing every visual element.
  • Python Automated Grading How Python grades homework and exams automatically, from simple answer keys to understanding written essays.
  • Python Batch Vs Stream Processing Batch processing is like doing laundry once a week; stream processing is like a self-cleaning shirt that cleans itself constantly.