fsrs4anki-optimizer

A modern Anki custom scheduling based on free spaced repetition scheduler algorithm


Keywords
anki, anki-addon, deep-learning, fsrs, intelligent-tutoring-system, machine-learning, memory, optimal-control, reinforcement-learning, spaced-repetition, spaced-repetition-algorithm, srs
License
MIT
Install
pip install fsrs4anki-optimizer==4.4.1

Documentation

FSRS4Anki

FSRS4Anki

✨ A modern Anki custom scheduling based on Free Spaced Repetition Scheduler algorithm ✨

license release

Table of contents

Introduction

FSRS4Anki consists of two main parts: scheduler and optimizer.

The scheduler is based on a variant of the DSR (Difficulty, Stability, Retrievability) model, which is used to predict memory states. The scheduler aims to achieve the requested retention for each card and each review.

The optimizer applies Maximum Likelihood Estimation and Backpropagation Through Time to estimate the stability of memory and learn the laws of memory from time-series review logs. Then, it can find the optimal retention to minimize the repetitions via the stochastic shortest path algorithm.

For more detail on the mechanism of the FSRS algorithm, please see my papers: A Stochastic Shortest Path Algorithm for Optimizing Spaced Repetition Scheduling (free access) and Optimizing Spaced Repetition Schedule by Capturing the Dynamics of Memory (submit request).

FSRS4Anki Helper is an Anki add-on that supports the FSRS4Anki Scheduler. It has six features:

  1. Reschedule cards based on their entire review histories.
  2. Postpone due cards whose retention is higher than your target.
  3. Advance undue cards whose retention is lower than your target.
  4. Balance the load during rescheduling.
  5. No Anki on Free Days (such as weekends).
  6. Disperse Siblings (cards with the same note) to avoid interference & reminder.

Tutorial

δΈ­ζ–‡η‰ˆθ―·θ§οΌšFSRS4Anki δ½Ώη”¨ζŒ‡εŒ—

1 Quick Start

1.1 Enable Anki's V3 Scheduler

Preferences > Review > Enable V3 Scheduler

image

1.2 Paste FSRS Scheduler Code

In the deck options, find the Advanced Settings column, and paste the code in fsrs4anki_scheduler.js into the Custom Scheduling field:

image

Idealy, you've now started using the FSRS4Anki Scheduler. If you're unsure, you can change this part of the code:

const display_memory_state = false;

to:

const display_memory_state = true;

Then open any deck for review and you'll see:

image

This shows that your FSRS is running normally. You can then change the code back and the message will no longer display.

2 Advanced Usage

2.1 Generate Personalized Parameters

You can generate parameters in a variety of ways depending on which method you prefer.
For the most up to date methods please check the releases.

2.1a Google Colab

Open the optimizer's notebook and click on Open in Colab to run the optimizer on Google Colab. You don't need to configure the coding environment yourself and you can use Google's machines for free (you'll need to register a Google account):

image

After opening it in Colab, switch to the folder tab. Once the Optimizer connects to Google's machine, you can right-click to upload your deck file/collection file. When exporting these files, make sure to tick "Include scheduling information" and "Support older Anki versions".

image

image

After it's uploaded, change the filename in the notebook to the name of your uploaded file. And set your timezone and next_day_starts_at.

image

Then click "Run All".

image

Wait for the code to finish in section 2.3, then copy the personalized parameters that were output.

image

Replace the parameters in the FSRS code you copied earlier.

image

⚠️Note: when replacing these parameters, be sure not to delete the comma at the end.

2.1b Website

Simply upload your exported decks to this website and it will optimise it for you.
https://huggingface.co/spaces/open-spaced-repetition/fsrs4anki_app

image

2.1c Command Line

There is a python package for the optimizer. This package has torch as a dependency so note it might take about half a gigabyte of space.

Install this package with the command:

python -m pip install fsrs4anki_optimizer

Export your deck and cd into the folder in which you exported it.
Then you can run:

python -m fsrs4anki_optimizer "package.(colpkg/apkg)"

There are certain options which are as follows

options:
  -h, --help           show this help message and exit
  -y, --yes, --no-yes  If set automatically defaults on all stdin settings.
  -o OUT, --out OUT    File to APPEND the automatically generated profile to.

Expected Functionality:

image image

2.1d Anki Addon EXPERIMENTAL

Download and install this version of the anki helper addon either by git cloning it into the anki addons folder or downloading it as a zip and extracting the zip into the anki addons folder.

Install the optimizer locally.
image
Please pay attention to the popup.
image

After that has downloaded and installed you should be able to run the optimizer from within anki. Press the cog next to any given deck and hit the optimize option.
image
Anki may then hang a small while while it loads the optimizer.

image
Hit yes to find the optimum retention, Hit no to not or hit cancel to pick a different deck.

If all is well you should then get a toolbar popup which tells you the progress of the optimization. image

You should then get the stats in a format which is easy to copy into the javascript scheduler. image
These values are saved in the addons config file which can be found and edited in anki if you want to change the retention manually for example. image

If there are any issues with this please mention them on this pull request here.

2.2 Deck Parameter Settings

You can also generate different parameters for different decks and configure them separately in the code. In the default configuration, deckParams already contains three groups of parameters.

The group "global config for FSRS4Anki" is global parameters.

The group "MainDeck1" are the parameters applied to the deck "MainDeck1" and its sub-decks.

Similarly, the third group is the parameters applied to the deck "MainDeck2::SubDeck::SubSubDeck" and its sub-decks. You can replace these with the decks you want to configure. If you need more, feel free to copy and add them.

const deckParams = [
  {
    // Default parameters of FSRS4Anki for global
    "deckName": "global config for FSRS4Anki",
    "w": [0.4, 0.6, 2.4, 5.8, 4.93, 0.94, 0.86, 0.01, 1.49, 0.14, 0.94, 2.18, 0.05, 0.34, 1.26, 0.29, 2.61],
    // The above parameters can be optimized via FSRS4Anki optimizer.
    // For details about the parameters, please see: https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm
    // User's custom parameters for global
    "requestRetention": 0.9, // recommended setting: 0.8 ~ 0.9
    "maximumInterval": 36500,
    // FSRS only modifies the long-term scheduling. So (re)learning steps in deck options work as usual.
    // I recommend setting steps shorter than 1 day.
  },
  {
    // Example 1: User's custom parameters for this deck and its sub-decks.
    "deckName": "MainDeck1",
    "w": [0.6, 0.9, 2.9, 6.8, 4.72, 1.02, 1, 0.04, 1.49, 0.17, 1.02, 2.15, 0.07, 0.35, 1.17, 0.32, 2.53],
    "requestRetention": 0.9,
    "maximumInterval": 36500,
  },
  {
    // Example 2: User's custom parameters for this deck and its sub-decks.
    // Don't omit any keys.
    "deckName": "MainDeck2::SubDeck::SubSubDeck",
    "w": [0.6, 0.9, 2.9, 6.8, 4.72, 1.02, 1, 0.04, 1.49, 0.17, 1.02, 2.15, 0.07, 0.35, 1.17, 0.32, 2.53],
    "requestRetention": 0.9,
    "maximumInterval": 36500,
  }
];

If there are some decks you don't want to use FSRS with, you can add their names to the skip_decks list.

const skip_decks = ["MainDeck3", "MainDeck4::SubDeck"];

3 Using the Helper Add-on

Please see: FSRS4Anki Helper

FAQ

Here collect some questions from issues, forums, and others: FAQ

Compatibility

Some add-ons modify the scheduling of Anki, which would cause conflict with FSRS4Anki scheduler.

Add-on Compatible? Comment
Advanced Review Bottom Bar Yesβœ… Please use the latest version.
Incremental Reading v4.11.3 (unofficial clone) No❌ It shows the interval given by Anki's built-in scheduler, not the custom scheduler.
Auto Ease Factor Yesβœ… Ease Factor doesn't affect the interval given by FSRS.
Delay siblings Yesβœ… Delay siblings will modify the interval give by FSRS.
autoLapseNewInterval Yesβœ… New Interval doesn't affect the interval given by FSRS.
Straight Reward Yesβœ… Ease Factor doesn't affect the interval given by FSRS.
Pass/Fail Yesβœ… Pass is the equivalent of Good.

Let me know via issues if I miss any add-ons.

Contribute

You can contribute to FSRS4Anki by beta testing, submitting code, or sharing your data. If you want to share your data with me, please fill this form: https://forms.gle/KaojsBbhMCytaA7h8

Stargazers over time

Star History Chart