Jev-style decision models in PyTorch: encoder vs. decoder

Build Jev-style decision models in PyTorch with encoder scoring, decoder KV-cache reuse and custom attention masks. Training objectives are explained in theory.

Player not loading? Watch on YouTube

Vivek Kalyanarangan demonstrates Jev-style decision models using PyTorch and pretrained Hugging Face backbones. The examples return probabilities over predefined choices, ordinal scores or boolean answers instead of generating a complete JSON response token by token.

The course first steps through ordinary autoregressive generation and its KV cache. The encoder implementation then places mask tokens before answer options, averages the question's hidden states and scores interactions between question and option vectors. Its untrained output is inaccurate in the example. The speaker discusses training a linear head, using LoRA or fine-tuning the backbone. This encoder implementation processes the context again for every question because its attention is bidirectional.

The decoder implementation caches the context and packs multiple questions into a sequence. A custom causal attention mask lets each question attend to the context and its own tokens while blocking other questions. The code extracts candidate-token logits at each decision point and converts them to option probabilities. Demonstrated tasks include identifying a refund request and routing it to billing or technical support.

This decoder scores only the first token of each option. Options such as "fraud" and "fraud review" therefore collide. The course discusses renaming options, using letter labels or scoring more tokens. A separate ordinal sentiment example appears in the code but is not run.

The final section works through teacher-student distributions, perturbed scores, advantages and an RLCD training objective involving log scores, spherical scores and ranked probability scores for ordinal answers. It does not demonstrate model training or validate calibration. The closing comparison considers context reuse, option length, memory and implementation complexity.

Viewers need PyTorch fluency and familiarity with attention, KV caches and softmax. The speaker says the inference exercises do not require a GPU.

Course code: https://github.com/vivekkalyanarangan30/how-jev-works Source video: https://www.youtube.com/watch?v=aZglGvBPQGs