-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathknowledge_tracing_quickstart.py
More file actions
68 lines (54 loc) · 1.91 KB
/
Copy pathknowledge_tracing_quickstart.py
File metadata and controls
68 lines (54 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
"""Knowledge tracing quickstart.
Run with: python examples/knowledge_tracing_quickstart.py
"""
from __future__ import annotations
import pandas as pd
from orchid_ranker.kt import SAKTTracer
def build_events() -> pd.DataFrame:
rows = []
catalog = [
(101, "number-sense", 0.20),
(102, "number-sense", 0.30),
(201, "fractions", 0.45),
(202, "fractions", 0.55),
(301, "ratios", 0.70),
]
abilities = {7: 0.48, 8: 0.35, 9: 0.62, 10: 0.80}
for user_id, ability in abilities.items():
for step, (item_id, concept, difficulty) in enumerate(catalog):
rows.append(
{
"user_id": user_id,
"item_id": item_id,
"concept": concept,
"correct": int(ability + 0.10 >= difficulty),
"timestamp": step,
}
)
return pd.DataFrame(rows)
def main() -> None:
events = build_events()
tracer = SAKTTracer(
max_seq_len=4,
d_model=16,
n_heads=2,
epochs=2,
batch_size=4,
random_state=42,
device="cpu",
).fit(events, timestamp_col="timestamp")
learner_id = "new-session"
candidates = [201, 202, 301]
before = tracer.recommend_practice(learner_id, candidates, top_k=3, target_correct=0.70)
print("Before live outcome:")
for rec in before:
print(f" item={rec.item_id} p_correct={rec.p_correct:.3f} stretch_score={rec.score:.3f}")
tracer.observe(learner_id, 201, correct=False)
after = tracer.recommend_practice(learner_id, candidates, top_k=3, target_correct=0.70)
print("After incorrect fractions outcome:")
for rec in after:
print(f" item={rec.item_id} p_correct={rec.p_correct:.3f} stretch_score={rec.score:.3f}")
print("Knowledge tracing quickstart complete.")
if __name__ == "__main__":
main()