You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2016/01/05 19:10:31 UTC

[02/10] incubator-singa git commit: SINGA-120 - Implemented GRU and BPTT: Fixed bugs of returning null

SINGA-120 - Implemented GRU and BPTT: Fixed bugs of returning null


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/d43af9fe
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/d43af9fe
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/d43af9fe

Branch: refs/heads/master
Commit: d43af9fef5889da55c22d56487b91989e841daa8
Parents: c440e4a
Author: Ju Fan <fa...@gmail.com>
Authored: Fri Jan 1 10:52:20 2016 +0800
Committer: Wei Wang <wa...@comp.nus.edu.sg>
Committed: Wed Jan 6 01:53:05 2016 +0800

----------------------------------------------------------------------
 include/singa/neuralnet/neuron_layer.h | 33 ++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/d43af9fe/include/singa/neuralnet/neuron_layer.h
----------------------------------------------------------------------
diff --git a/include/singa/neuralnet/neuron_layer.h b/include/singa/neuralnet/neuron_layer.h
index b02aa7d..3f126ab 100644
--- a/include/singa/neuralnet/neuron_layer.h
+++ b/include/singa/neuralnet/neuron_layer.h
@@ -120,16 +120,47 @@ class DropoutLayer : public NeuronLayer {
  * Use it as output layer, it will generate random grad;
  * Use it as neuron layer, it will replicates data and grad.
  */
-class DummyLayer: public Layer {
+class DummyLayer: public NeuronLayer {
  public:
   void Setup(const LayerProto& proto, const vector<Layer*>& srclayers) override;
   void ComputeFeature(int flag, const vector<Layer*>& srclayers) override;
   void ComputeGradient(int flag, const vector<Layer*>& srclayers) override;
+
  private:
   bool input_ = false;  // use as input layer
   bool output_ = false;  // use as output layer
 };
 
+class GRULayer : public NeuronLayer {
+ public:
+  ~GRULayer();
+  void Setup(const LayerProto& proto, const vector<Layer*>& srclayers) override;
+  void ComputeFeature(int flag, const vector<Layer*>& srclayers) override;
+  void ComputeGradient(int flag, const vector<Layer*>& srclayers) override;
+
+  const std::vector<Param*> GetParams() const override {
+    if (bias_z_ != nullptr && bias_r_ != nullptr && bias_c_ != nullptr) {
+      std::vector<Param*> params{weight_z_hx_, weight_r_hx_,weight_c_hx_,
+        weight_z_hh_, weight_r_hh_, weight_c_hh_,
+        bias_z_, bias_r_, bias_c_};
+      return params;
+    } else {
+      std::vector<Param*> params{weight_z_hx_, weight_r_hx_,weight_c_hx_,
+        weight_z_hh_, weight_r_hh_, weight_c_hh_};
+      return params;
+    }
+  }
+
+ private:
+  int batchsize_; // batch size
+  int vdim_, hdim_; // dimensions
+
+  Blob<float> *update_gate, *reset_gate, *new_memory;
+
+  Param *weight_z_hx_, *weight_z_hh_, *bias_z_; // update gate
+  Param *weight_r_hx_, *weight_r_hh_, *bias_r_; // reset gate
+  Param *weight_c_hx_, *weight_c_hh_, *bias_c_; // new memory
+};
 
 /**
  * Layer that applys linear transformations as