Articles
Research2 min read

Bayesian Knowledge Tracing, Explained with Code

How EduVision estimates what a student knows from noisy answers - four parameters, two equations and a dozen lines of Python.

#knowledge-tracing#eduvision#bayesian

A tutor has to answer one question over and over: does this student know this skill yet? We cannot observe knowledge directly - only answers, and answers are noisy. Students guess correctly and slip on things they know.

Bayesian Knowledge Tracing (BKT) treats mastery as a hidden variable and updates a probability after every answer. It is the Learner Engine in EduVision.

Four parameters

ParameterMeaningEduVision default
P(L0)P(L_0)Probability the skill is known before practice0.1
TTProbability of learning during one attempt0.1
GGGuess: correct answer without knowing0.2
SSSlip: wrong answer despite knowing0.1

Step 1 - update on evidence

After a correct answer, Bayes' rule gives:

P(Ltcorrect)=P(Lt)(1S)P(Lt)(1S)+(1P(Lt))GP(L_t \mid \text{correct}) = \frac{P(L_t)(1-S)}{P(L_t)(1-S) + (1-P(L_t))\,G}

After an incorrect answer:

P(Ltincorrect)=P(Lt)SP(Lt)S+(1P(Lt))(1G)P(L_t \mid \text{incorrect}) = \frac{P(L_t)\,S}{P(L_t)\,S + (1-P(L_t))(1-G)}

Step 2 - account for learning

The attempt itself is a learning opportunity, so some probability mass moves from "not known" to "known":

P(Lt+1)=P(Ltobs)+(1P(Ltobs))TP(L_{t+1}) = P(L_t \mid \text{obs}) + \big(1 - P(L_t \mid \text{obs})\big)\,T

The implementation

src/core/adaptive/bkt.py
L_prev = skill.p_mastery
 
if is_correct:
    numerator = L_prev * (1 - skill.p_slip)
    denominator = numerator + (1 - L_prev) * skill.p_guess
else:
    numerator = L_prev * skill.p_slip
    denominator = numerator + (1 - L_prev) * (1 - skill.p_guess)
 
L_given_evidence = numerator / (denominator + 1e-10)
L_new = L_given_evidence + (1 - L_given_evidence) * skill.p_learn
 
skill.p_mastery = min(0.99, max(0.01, L_new))

The final clamp to [0.01, 0.99] matters: a probability of exactly 0 or 1 can never move again, no matter what the student does next.

Why BKT and not a neural model?

Deep knowledge tracing models can be more accurate on large datasets, but BKT has properties that matter inside a tutor:

  • Interpretable - four numbers per skill that a teacher can reason about.
  • Cheap - one constant-time update per answer, no GPU.
  • Data-efficient - sensible from the very first answer.

In EduVision the mastery estimate feeds the reinforcement-learning agent that decides whether the next problem should be easier, the same, or harder.