If you want to use a trained model, this is useful to compute the probabilities of new examples.
(f_pred_prob, prepare_data, data, iterator, verbose=False)
| 404 | |
| 405 | |
| 406 | def pred_probs(f_pred_prob, prepare_data, data, iterator, verbose=False): |
| 407 | """ If you want to use a trained model, this is useful to compute |
| 408 | the probabilities of new examples. |
| 409 | """ |
| 410 | n_samples = len(data[0]) |
| 411 | probs = numpy.zeros((n_samples, 2)).astype(config.floatX) |
| 412 | |
| 413 | n_done = 0 |
| 414 | |
| 415 | for _, valid_index in iterator: |
| 416 | x, mask, y = prepare_data([data[0][t] for t in valid_index], |
| 417 | numpy.array(data[1])[valid_index], |
| 418 | maxlen=None) |
| 419 | pred_probs = f_pred_prob(x, mask) |
| 420 | probs[valid_index, :] = pred_probs |
| 421 | |
| 422 | n_done += len(valid_index) |
| 423 | if verbose: |
| 424 | print('%d/%d samples classified' % (n_done, n_samples)) |
| 425 | |
| 426 | return probs |
| 427 | |
| 428 | |
| 429 | def pred_error(f_pred, prepare_data, data, iterator, verbose=False): |
nothing calls this directly
no test coverage detected