| 43 | } |
| 44 | |
| 45 | float Train(const vector<dynet::real>& input, dynet::real gold_output, SimpleSGDTrainer& trainer) { |
| 46 | ComputationGraph cg; |
| 47 | NewGraph(cg); |
| 48 | |
| 49 | Expression x = dynet::input(cg, {(unsigned int)input.size()}, &input); |
| 50 | Expression y = dynet::input(cg, &gold_output); |
| 51 | |
| 52 | Expression h = tanh(W*x + b); |
| 53 | Expression y_pred = V*h + a; |
| 54 | Expression loss = squared_distance(y_pred, y); |
| 55 | |
| 56 | float return_loss = as_scalar(cg.forward(loss)); |
| 57 | cg.backward(loss); |
| 58 | trainer.update(); |
| 59 | return return_loss; |
| 60 | } |
| 61 | |
| 62 | float Decode(vector<dynet::real>& input) { |
| 63 | ComputationGraph cg; |