-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathgru.h
More file actions
54 lines (41 loc) · 1.81 KB
/
Copy pathgru.h
File metadata and controls
54 lines (41 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef DYNET_GRU_H_
#define DYNET_GRU_H_
#include "dynet/dynet.h"
#include "dynet/rnn.h"
namespace dynet {
class ParameterCollection;
struct GRUBuilder : public RNNBuilder {
GRUBuilder() = default;
explicit GRUBuilder(unsigned layers,
unsigned input_dim,
unsigned hidden_dim,
ParameterCollection& model);
Expression back() const override { return (cur == -1? h0.back() : h[cur].back()); }
std::vector<Expression> final_h() const override { return (h.size() == 0 ? h0 : h.back()); }
std::vector<Expression> final_s() const override { return final_h(); }
std::vector<Expression> get_h(RNNPointer i) const override { return (i == -1 ? h0 : h[i]); }
std::vector<Expression> get_s(RNNPointer i) const override { return get_h(i); }
unsigned num_h0_components() const override { return layers; }
void copy(const RNNBuilder & params) override;
ParameterCollection & get_parameter_collection() override;
// first index is layer, then ...
std::vector<std::vector<Parameter>> params;
// first index is layer, then ...
std::vector<std::vector<Expression>> param_vars;
protected:
void new_graph_impl(ComputationGraph& cg, bool update) override;
void start_new_sequence_impl(const std::vector<Expression>& h0) override;
Expression add_input_impl(int prev, const Expression& x) override;
Expression set_h_impl(int prev, const std::vector<Expression>& h_new) override;
Expression set_s_impl(int prev, const std::vector<Expression>& s_new) override;
ParameterCollection local_model;
// first index is time, second is layer
std::vector<std::vector<Expression>> h;
// initial values of h at each layer
// - default to zero matrix input
std::vector<Expression> h0;
unsigned hidden_dim;
unsigned layers;
};
} // namespace dynet
#endif