NumPy allowed · plain Python earns 10 bonus points
Q · Kᵀ / √d scores normalized with softmax
Compute the cross-entropy loss for a single-token prediction from raw logits and true target index.
Implement cross_entropy_loss(logits, target_idx). Apply numerically stable softmax by subtracting max(logits), then return -log(p_target) rounded to 4 decimal places. Raise ValueError if logits is empty, or IndexError if target_idx is out of bounds.
cross_entropy_loss(logits: list[float], target_idx: int) -> float