NumPy allowed · plain Python earns 10 bonus points
Computed matrix × vector transformation
Compute the softmax probability vector and negative log likelihood loss without floating-point overflow.
Implement stable_softmax_and_ce(logits, target_idx): subtract m = max(logits) to calculate p_i = exp(z_i - m) / sum_j exp(z_j - m). Compute cross entropy loss = -log(max(p_target, 1e-15)). Return {"probs": list[float], "loss": float} rounded to 4 decimals.
stable_softmax_and_ce(logits: list[float], target_idx: int) -> dict[str, Any]