Just compute the error f_pred: Theano fct computing the prediction prepare_data: usual prepare_data for that dataset.
(f_pred, prepare_data, data, iterator, verbose=False)
| 427 | |
| 428 | |
| 429 | def pred_error(f_pred, prepare_data, data, iterator, verbose=False): |
| 430 | """ |
| 431 | Just compute the error |
| 432 | f_pred: Theano fct computing the prediction |
| 433 | prepare_data: usual prepare_data for that dataset. |
| 434 | """ |
| 435 | valid_err = 0 |
| 436 | for _, valid_index in iterator: |
| 437 | x, mask, y = prepare_data([data[0][t] for t in valid_index], |
| 438 | numpy.array(data[1])[valid_index], |
| 439 | maxlen=None) |
| 440 | preds = f_pred(x, mask) |
| 441 | targets = numpy.array(data[1])[valid_index] |
| 442 | valid_err += (preds == targets).sum() |
| 443 | valid_err = 1. - numpy_floatX(valid_err) / len(data[0]) |
| 444 | |
| 445 | return valid_err |
| 446 | |
| 447 | |
| 448 | def train_lstm( |
no test coverage detected