slightly improve how cross entropy loss is compute
btw: directly implemented cross entropy loss seems to have way lower magnitudes than when implemented with softmax and log. probably the input to log gets closer to zero due to float numerics. maybe the multiplication by (1.0-eps)/sum is more accurate..
This commit is contained in:
parent
5f5aa20078
commit
89475fb320
1 changed files with 2 additions and 2 deletions
4
ggml.c
4
ggml.c
|
@ -12961,10 +12961,10 @@ static void ggml_compute_forward_cross_entropy_loss_f32(
|
|||
}
|
||||
|
||||
assert(sum > 0.0);
|
||||
sum = 1.0/sum;
|
||||
// sum = 1.0/sum;
|
||||
}
|
||||
// avoid log(0) by rescaling from [0..1] to [eps..1]
|
||||
sum = sum * (1.0f - eps);
|
||||
sum = (1.0f - eps) / sum;
|
||||
ggml_vec_scale_f32(nc, st, sum);
|
||||
ggml_vec_add1_f32(nc, st, st, eps);
|
||||
ggml_vec_log_f32(nc, st, st);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue