from Hacker News

Anki SRS Algorithm : Spaced repetition explained with code

by PixelForg on 12/27/22, 6:43 PM with 82 comments

  • by daniels11 on 12/27/22, 9:26 PM

    Nice article! This would've been very helpful a few years back when I was attempting to make an Anki clone while teaching myself to code.

    I'd still love to create a better open-source SRS algorithm at some point in the future. Mostly to use for language learning.

    When I was learning Chinese characters, I did a bit of a deep dive into the Anki algorithm and found that the biggest flaw (imho) was the Ease Factor knocking a card back to 0.

    If you mostly know a card, but miss it on one day for some reason - maybe you were tired or distracted, that card's learning progress should not be totally reset (as if you were learning it from scratch). That leads you to have too many cards to review on a daily basis. Instead, you should use some modifier to increase the interval to a reasonable level.

    More explanation here: https://readbroca.com/anki/ease-hell/

    I think it would be awesome to pair SRS with high quality images and audio, which I find most helpful for language learning. I've used Rosetta Stone and Duolingo in the past; Rosetta Stone has great audio and images but lacks a powerful SRS (it also has a number of other flaws in my mind, but I'll save that for another time). Duolingo is great for grammar and explanations, but I can't take the pronunciations and tediousness of it all.

  • by Kelamir on 12/27/22, 10:27 PM

    I've noticed this https://github.com/open-spaced-repetition/fsrs4anki set of modifications for the Anki algorithm is popular in the Anki Discord. Might be of interest to those exploring the code.
  • by jakobov on 12/27/22, 9:29 PM

    Shameless plug: I developed a space repetition algorithm which has a different goal. Mine is focused on learning a large number of new things fast, rather than adding new things over time and retaining memory of them.

    See: https://github.com/Jakobovski/SaneMemo

  • by cmehdy on 12/27/22, 9:56 PM

    The article is great - a visual that explains SRS in one single graph near the top of the page is a great proof that the article is solid.

    But I also want to say: what a clean and enjoyable website!!

    Thank you for having shared this.

  • by yosito on 12/28/22, 3:22 AM

    I've used Anki to learn languages with SRS for years. I keep running into the same problem, even with difficult languages: my knowledge of the language quickly outpaces the rate at which I can study new cards, and my ability to retain vocabulary doesn't really seem to fade. Once I learn words, I don't need to review them in x months or years. I just know them and, for the most part, won't forget.

    I learned Hungarian (one of the more difficult languages to learn) by loading up a database of ~10k cards. While it worked great in the beginning, within a year, I was just constantly telling the algorithm that I didn't need to review cards for 3-5 years. But the thing is, with a language, I'm not going to forget all those words in 5 years. There will be no point in reviewing them. So I just started deleting cards if I knew them already. And eventually I was spending so much time deleting cards that I just gave up on SRS altogether.

    It could be that I have some latent savant-like language learning abilities, though I doubt that. I think my experience is likely related to language learning itself. With a language, if you are immersed, you have constant daily repetition with or without the cards.

    All that to say, I think SRS algorithms should have a language learning mode that automatically archives vocabulary cards once you've mastered them to a certain degree. I'm not sure what would work best. Maybe once you've crossed the 6 month threshold, it could just automatically archive the card.

  • by adaszko on 12/28/22, 8:27 AM

    There’s a Bayesian stats approach to spaced repetition: https://fasiha.github.io/ebisu/

    AFAIU, SM2 computes the datetime of a next review, whereas Ebisu models a probability of remembering a given flashcard. It seems it’s a more straightforward representation that’s more amenable to implementing functionalities like “show me 10 least remembered cards”.

  • by _-____-_ on 12/28/22, 12:30 AM

    I enjoy using Anki and have found it effective in the very rare instances where I need to rapidly memorize a lot of material.

    But as a developer, I've never found a need for memorization. Am I missing out? Do any developers have suggestions for how to utilize Anki to make myself more professionally efficient?

    I suppose one starting point might be to track my most googled phrases ("trim newlines in sed," "bash printf into a variable," etc.) and turn those into cards.

  • by ukoki on 12/28/22, 7:49 AM

    Nice! When I was building a spaced repetition toy a few years ago I took a different 'bottom-up' approach, where I dynamically fit the forgetting curve to the user's actual performance on any given card to come up with a unique memory half-life value for that card for that user, which was then used to schedule the next review at a given estimated recall % (typically 70-95% depending on whether the user wanted an "easy" or "hard" experience). As you need at least two data points to be able to fit the curve, you never have enough data to schedule the second review of a given card, so for this I used the average half-life accross the set of cards, or hard-coded values if it was the first item in the group. This way a set of cards (such as world flags) was always initially scheduled as though they were similarly difficult for the user, and then harder cards within the set would naturally be reviewed with a higher priority.
  • by fallat on 12/27/22, 9:17 PM

    For anyone interested: https://len.falken.directory/code/sm2.git/ if you want to run something locally pretty easily.

    This post hits exactly what I found when researching months ago :) Absolutely captures everything well.

    This post has convinced me to even use Anki's algorithm.

  • by c7b on 12/28/22, 9:27 AM

    Reminds me of one of my backlogged projects: I'd like to have an SRS app that just draws cards at random, with probabilities proportional to how 'urgently' you need to review the cards (using the same logic of exponential growth in review intervals). I just couldn't get myself to stick with Anki so far, because I didn't like the 'X cards to review today' UX of the SM2 algorithm. I also think it's false accuracy trying to predict the exact review time down to the minute, I couldn't find much research supporting that any of the SM family algorithms would be the claimed optimum.

    If that already exists, ideally compatible with Anki cards, I'd be happy for recommendations. I have other projects and ideas that I feel would add more to the world than the umpteenth Anki-clone.

  • by nmca on 12/27/22, 7:51 PM

    I'm surprised that no spaced repetition systems seem to exploit relationships between facts/cards. One might imagine that capturing a graph of similar ideas would allow for better algorithms.
  • by GenericDev on 12/27/22, 8:37 PM

    I'm so thrilled to have come across this. Thank you for sharing this OP!
  • by jacquesm on 12/28/22, 4:48 AM

    This has been up for 10 hours and I don't see Gwern's article mentioned yet, so here it is:

    https://www.gwern.net/Spaced-repetition

  • by codetrotter on 12/27/22, 7:53 PM

    This is very nice and thorough.
  • by siduck on 12/28/22, 5:01 AM

    Bookmarked
  • by ZhangSWEFAANG on 12/28/22, 3:12 AM

    One underrated benefit of using Anki is you become a god. In a meeting, when I can recite the Q1 revenue along with the names of everyone working on the project, everyone automatically becomes submissive to me because they think they have just observed a superior intellect.