Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [FSRS4Anki v1.6.1 Optimizer] Optimized Default Difficulty is too low on large revlog #31

Closed
kuroahna opened this issue Sep 26, 2022 · 2 comments · Fixed by #35
Closed
Labels
bug Something isn't working

Comments

@kuroahna
Copy link

kuroahna commented Sep 26, 2022

Describe the bug
After optimizing the parameters using fsrs4anki_optimizer on a large revlog, the default difficulty is too low

let defaultDifficulty = 1.1873;
let defaultStability = 3.6988;
let difficultyDecay = -0.9949;
let stabilityDecay = -0.1412;
let retrievabilityFactor = 1.2742;
let increaseFactor = 2.9295;
let lapsesBase = -0.062;

To Reproduce
Steps to reproduce the behavior:

  1. Download FSRS4Anki v1.6.1 Optimizer and import to Google Colab
  2. Upload a collection with large review history (about ~300k logs). See [REMOVED]
  3. Change settings to
# Here are some settings that you need to replace before running this optimizer.

filename = "collection.colpkg"
# If you upload deck file, replace it with your deck filename. E.g., ALL__Learning.apkg
# If you upload collection file, replace it with your colpgk filename. E.g., collection-2022-09-18@13-21-58.colpkg

# Replace it with your timezone. I'm in China, so I use Asia/Shanghai.
timezone = 'America/Toronto'

# Replace it with your Anki's setting in Prefernces -> Scheduling.
next_day_starts_at = 8

# Replace it if you don't want the optimizer to use the review logs before a specific date.
revlog_start_date = "2006-10-05"
  1. Runtime -> Run all

Output:

Extract successfully!

revlog.csv saved!
100%|██████████| 24582/24582 [04:35<00:00, 89.13it/s] 
Trainset saved!

100%|██████████| 313064/313064 [00:49<00:00, 6335.75it/s] 
Tensorized!
train:   0%|          | 16/313064 [00:00<1:50:46, 47.10it/s]iteration: 1
f_s: [1.9995]
f_d: [4.9995]
s_w: [3.0005, -0.6995, -0.2005, 1.0005, -0.3005]
train:  10%|█         | 31323/313064 [03:43<38:44, 121.21it/s]iteration: 31307
f_s: [2.8145]
f_d: [4.2811]
s_w: [3.1621, -0.7659, -0.1151, 1.1874, -0.0596]
train:  20%|██        | 62628/313064 [07:27<33:40, 123.94it/s]iteration: 62613
f_s: [3.1593]
f_d: [3.7107]
s_w: [3.2328, -0.9031, -0.0954, 1.2932, -0.0553]
train:  30%|███       | 93934/313064 [11:09<26:09, 139.61it/s]iteration: 93919
f_s: [3.4398]
f_d: [3.2537]
s_w: [3.2627, -0.9976, -0.0962, 1.3511, -0.0815]
train:  40%|████      | 125244/313064 [14:49<21:28, 145.81it/s]iteration: 125225
f_s: [3.6134]
f_d: [2.9337]
s_w: [3.2254, -0.998, -0.1659, 1.3523, -0.0869]
train:  50%|█████     | 156550/313064 [18:27<18:03, 144.47it/s]iteration: 156531
f_s: [3.605]
f_d: [2.6452]
s_w: [3.1698, -0.9975, -0.1452, 1.339, -0.0917]
train:  60%|██████    | 187855/313064 [22:05<13:34, 153.73it/s]iteration: 187837
f_s: [3.6384]
f_d: [2.3413]
s_w: [3.1219, -0.9863, -0.0997, 1.3147, -0.0245]
train:  70%|███████   | 219161/313064 [25:38<09:30, 164.48it/s]iteration: 219143
f_s: [3.6706]
f_d: [2.0742]
s_w: [3.0706, -0.9885, -0.1018, 1.2922, -0.0602]
train:  80%|████████  | 250468/313064 [29:06<07:48, 133.49it/s]iteration: 250449
f_s: [3.7285]
f_d: [1.6587]
s_w: [3.0623, -0.9938, -0.1125, 1.317, -0.0961]
train:  90%|█████████ | 281776/313064 [32:33<03:31, 148.23it/s]iteration: 281755
f_s: [3.8183]
f_d: [1.3745]
s_w: [2.9781, -0.9904, -0.179, 1.2664, -0.0859]
train: 100%|██████████| 313064/313064 [35:58<00:00, 145.05it/s]iteration: 313061
f_s: [3.6984]
f_d: [1.1872]
s_w: [2.9299, -0.9943, -0.1408, 1.2746, -0.0626]

Training finished!

let defaultDifficulty = 1.1873;
let defaultStability = 3.6988;
let difficultyDecay = -0.9949;
let stabilityDecay = -0.1412;
let retrievabilityFactor = 1.2742;
let increaseFactor = 2.9295;
let lapsesBase = -0.062;

1:again, 2:hard, 3:good, 4:easy

first rating: 1
rating history: 1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
interval history: 0,1,2,3,5,8,13,20,30,45,65,93,132,184,252,343
difficulty history: 0,3.2,3.2,3.2,3.2,3.2,3.2,3.2,3.2,3.2,3.2,3.2,3.2,3.2,3.2,3.2

first rating: 2
rating history: 2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
interval history: 0,2,4,8,14,25,43,71,115,181,279,420,621,902,1290,1817
difficulty history: 0,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2,2.2

first rating: 3
rating history: 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
interval history: 0,4,10,25,56,119,240,460,845,1493,2551,4227,6812,10707,16451,24757
difficulty history: 0,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2

first rating: 4
rating history: 4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
interval history: 0,7,54,320,1547,6295,22147,68839,192501,491578,1160631,2559857,5319872,10492922,19763234,35730756
difficulty history: 0,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2,0.2

rating history: 3,3,3,2,3,4,3,3,1,3,3,3
interval history: 0,4,10,25,30,80,183,421,992,4,9,20,42
difficulty history: 0,1.2,1.2,1.2,1.7,1.7,0.7,0.7,0.7,1.4,1.4,1.4,1.4

Expected behavior
The default difficultly should not be as low as 1.1873

Environment

  • Optimizer version: v1.6.1

Additional context
I believe the issue has come from the commit 4185f3d

Change the learning rate from lr=1e-4 to lr=5e-4 might be too aggressive?

@kuroahna kuroahna added the bug Something isn't working label Sep 26, 2022
@kuroahna kuroahna changed the title [BUG] Optimized Default Difficulty is too low on large revlog [BUG] [FSRS4Anki v1.6.1 Optimizer] Optimized Default Difficulty is too low on large revlog Sep 26, 2022
@L-M-Sherlock
Copy link
Member

But the default difficulty deceased monotonically in your case. I will test your collection tomorrow.

@kuroahna
Copy link
Author

kuroahna commented Sep 26, 2022

Hm actually, you might be right. A large majority of my cards have ~250% ease

image

image

And looking at the interval history if I keep pressing Good:

first rating: 3
rating history: 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
interval history: 0,4,10,25,56,119,240,460,845,1493,2551,4227,6812,10707,16451,24757
difficulty history: 0,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2

The change between each interval is:

0 -> 4 = N/A
4 -> 10 = 10 / 4 = 2.5 = 250%
10 -> 25 = 25 / 10 = 2.5 = 250%
25 -> 56 = 56/ 25 = 2.24 = 224%
56 -> 119 = 119 / 56 = 2.125 = 212.5%
119 -> 240 = 240 / 119 = 2.017 = 201.7%
...

This seems correct since most of my cards have 250% and I have about ~88% retention rate for my young cards. The FSRS4anki algorithm starts with 250% change for the interval and then it slowly decreases the change in interval as I keep pressing good.

In version FSRS4Anki v1.4.3 Optimizer however, I got the results:

let defaultDifficulty = 3.835;
let defaultStability = 3.2191;
let difficultyDecay = -0.9131;
let stabilityDecay = -0.0872;
let retrievabilityFactor = 1.2571;
let increaseFactor = 3.2025;
let lapsesBase = -0.0493;

stability, difficulty, lapses
     3.22        3.83       0
     5.77        3.84       0
    10.62        3.84       0
    19.06        3.83       0
    32.91        3.83       0
    55.86        3.83       0
    93.04        3.83       0
   152.10        3.83       0
   244.58        3.83       0
   387.58        3.83       0
   605.15        3.83       0
   931.47        3.83       0
  1415.08        3.83       0
  2123.76        3.83       0
  3150.51        3.83       0
0,3,6,11,19,33,56,93,152,245,388,605,931,1415,2124,3151

The change between each interval here is:

0 -> 3 = N/A
3 -> 6 = 6 / 3 = 2 = 200%
6 -> 11 = 11 /  6 = 1.83 = 183%
11 -> 19 = 19 / 11 = 1.73 = 173%
19 -> 33 = 33 / 19 = 1.74 = 174%
33 -> 56 = 56 / 33 = 1.70 = 170%
...

With these parameters, it starts with a change in interval of 200%, not 250%. It does seem like these new parameters are correct. I guess the larger learning rate allowed it to converge faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants