verifyCrossEntropySimple function
void
verifyCrossEntropySimple()
Implementation
void verifyCrossEntropySimple() {
final x = Tensor.fill([1, 2], 0.0);
x.data = [0.0, 0.0]; // Softmax probabilities = [0.5, 0.5]
final loss = x.crossEntropy([1]);
loss.backward();
final grads = x.grad;
// With epsilon 0.1 and V=2:
// Target Prob = 0.95
// Grad = 0.5 - 0.95 = -0.45 (for target)
// Grad = 0.5 - 0.05 = 0.45 (for non-target)
bool ok = closeEnough(grads[0], 0.45) && closeEnough(grads[1], -0.45);
print(
"CROSS_ENTROPY: ${ok ? '✅ PASS' : '❌ FAIL (Got $grads, expected [0.45, -0.45])'}",
);
}