MCPcopy Create free account
hub / github.com/clab/dynet / Train

Method Train

examples/read-write/train_read-write.cc:45–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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;

Callers 1

mainFunction · 0.80

Calls 8

as_scalarFunction · 0.85
inputFunction · 0.50
tanhFunction · 0.50
squared_distanceFunction · 0.50
sizeMethod · 0.45
forwardMethod · 0.45
backwardMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected