Download code/dataset/forgetting.py from Jommarn/Qwen3.5-0.8B-NestedMemory-v5: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/Jommarn/Qwen3.5-0.8B-NestedMemory-v5/resolve/main/code/dataset/forgetting.py
- Command line
-
hf download hf://Jommarn/Qwen3.5-0.8B-NestedMemory-v5/code/dataset/forgetting.py
-
curl -L -o forgetting.py https://huggingface.co/Jommarn/Qwen3.5-0.8B-NestedMemory-v5/resolve/main/code/dataset/forgetting.py
1.22 kB
| from __future__ import annotations | |
| import math | |
| import random | |
| from .schema import ForgettingParams, RecallLabel | |
| def compute_stability( | |
| memory_tendency: float, | |
| importance: float, | |
| arousal: float, | |
| n_rehearsals: int, | |
| params: ForgettingParams, | |
| ) -> float: | |
| """ | |
| Ebbinghaus-inspired stability formula (exp_stability_v1): | |
| S = S0 * tendency * (1 + a*importance) * (1 + b*arousal) * (1 + c)^n_rehearsals | |
| """ | |
| s = ( | |
| params.S0_days | |
| * memory_tendency | |
| * (1.0 + params.a_importance * importance) | |
| * (1.0 + params.b_arousal * arousal) | |
| * ((1.0 + params.c_rehearsal) ** n_rehearsals) | |
| ) | |
| return round(s, 4) | |
| def compute_p_recall(days_since_last_rehearsal: float, stability: float) -> float: | |
| """Exponential forgetting curve: p_recall = exp(-days / S).""" | |
| if stability <= 0: | |
| return 0.0 | |
| p = math.exp(-max(days_since_last_rehearsal, 0.0) / stability) | |
| return round(p, 6) | |
| def sample_recall_label( | |
| p_recall: float, | |
| partial_band: float, | |
| rng: random.Random, | |
| ) -> RecallLabel: | |
| u = rng.random() | |
| if u < p_recall: | |
| return "full" | |
| if u < p_recall + partial_band: | |
| return "partial" | |
| return "forgotten" | |