Skip to content

Commit b0dd8f0

Browse files
committed
Merge pull request lisa-lab#86 from abergeron/lstm_float16
Use bigger epsilon for float16 so that it does not become 0.
2 parents 777c75a + cfba0cd commit b0dd8f0

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: code/lstm.py

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

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

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

0 commit comments

Comments
 (0)