Skip to content

Commit cfba0cd

Browse files
committed
Use bigger epsilon for float16 so that it does not become 0.
1 parent 408ea68 commit cfba0cd

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

code/lstm.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,11 @@ def build_model(tparams, options):
332332
f_pred_prob = theano.function([x, mask], pred, name='f_pred_prob')
333333
f_pred = theano.function([x, mask], pred.argmax(axis=1), name='f_pred')
334334

335-
cost = -tensor.log(pred[tensor.arange(n_samples), y] + 1e-8).mean()
335+
off = 1e-8
336+
if pred.dtype == 'float16':
337+
off = 1e-6
338+
339+
cost = -tensor.log(pred[tensor.arange(n_samples), y] + off).mean()
336340

337341
return use_noise, x, mask, y, f_pred_prob, f_pred, cost
338342

0 commit comments

Comments
 (0)