MyCaffe  1.12.2.41
Deep learning software for Windows C# programmers.
LSTMAttentionParameter.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
6using MyCaffe.basecode;
7
8namespace MyCaffe.param
9{
26 [Serializable]
27 [TypeConverter(typeof(ExpandableObjectConverter))]
29 {
30 uint m_nNumOutput;
31 uint m_nNumIpOutput = 0;
32 double m_dfClippingThreshold = 0;
33 FillerParameter m_fillerWeights = new FillerParameter("xavier");
34 FillerParameter m_fillerBias = new FillerParameter("constant", 0.1);
35 bool m_bEnableClockworkForgetGateBias = false;
36 bool m_bEnableAttention = false;
37
40 {
41 }
42
46 [Description("Specifies the number of outputs for the layer.")]
47 public uint num_output
48 {
49 get { return m_nNumOutput; }
50 set { m_nNumOutput = value; }
51 }
52
56 [Description("Specifies the number of outputs for the layer. Note, whenb 0, no inner product is performed.")]
57 public uint num_output_ip
58 {
59 get { return m_nNumIpOutput; }
60 set { m_nNumIpOutput = value; }
61 }
62
66 [Description("Specifies the gradient clipping threshold, default = 0.0 (i.e. no clipping).")]
67 public double clipping_threshold
68 {
69 get { return m_dfClippingThreshold; }
70 set { m_dfClippingThreshold = value; }
71 }
72
76 [Description("Specifies the filler parameters for the weight filler.")]
77 [TypeConverter(typeof(ExpandableObjectConverter))]
79 {
80 get { return m_fillerWeights; }
81 set { m_fillerWeights = value; }
82 }
83
87 [Description("Specifies the filler parameters for the bias filler.")]
88 [TypeConverter(typeof(ExpandableObjectConverter))]
90 {
91 get { return m_fillerBias; }
92 set { m_fillerBias = value; }
93 }
94
101 [Description("When true, the forget gate bias is set to 5.0 as recommended by [1] Koutnik, J., Greff, K., Gomez, F., Schmidhuber, J., 'A Clockwork RNN', 2014")]
103 {
104 get { return m_bEnableClockworkForgetGateBias; }
105 set { m_bEnableClockworkForgetGateBias = value; }
106 }
107
112 [Description("When enabled, attention is applied to the input state on each cycle through the LSTM. Attention is used with encoder/decoder models.")]
114 {
115 get { return m_bEnableAttention; }
116 set { m_bEnableAttention = value; }
117 }
118
120 public override object Load(System.IO.BinaryReader br, bool bNewInstance = true)
121 {
122 RawProto proto = RawProto.Parse(br.ReadString());
124
125 if (!bNewInstance)
126 Copy(p);
127
128 return p;
129 }
130
132 public override void Copy(LayerParameterBase src)
133 {
135
136 m_nNumOutput = p.m_nNumOutput;
137 m_nNumIpOutput = p.m_nNumIpOutput;
138 m_dfClippingThreshold = p.m_dfClippingThreshold;
139 m_fillerWeights = p.m_fillerWeights.Clone();
140 m_fillerBias = p.m_fillerBias.Clone();
141 m_bEnableClockworkForgetGateBias = p.m_bEnableClockworkForgetGateBias;
142 m_bEnableAttention = p.m_bEnableAttention;
143 }
144
146 public override LayerParameterBase Clone()
147 {
149 p.Copy(this);
150 return p;
151 }
152
158 public override RawProto ToProto(string strName)
159 {
160 RawProtoCollection rgChildren = new RawProtoCollection();
161
162 rgChildren.Add("num_output", m_nNumOutput.ToString());
163 rgChildren.Add("num_output_ip", m_nNumIpOutput.ToString());
164
165 if (m_dfClippingThreshold != 0)
166 rgChildren.Add("clipping_threshold", m_dfClippingThreshold.ToString());
167
168 rgChildren.Add(m_fillerWeights.ToProto("weight_filler"));
169 rgChildren.Add(m_fillerBias.ToProto("bias_filler"));
170
171 if (m_bEnableClockworkForgetGateBias != false)
172 rgChildren.Add("enable_clockwork_forgetgate_bias", m_bEnableClockworkForgetGateBias.ToString());
173
174 rgChildren.Add("enable_attention", m_bEnableAttention.ToString());
175
176 return new RawProto(strName, "", rgChildren);
177 }
178
185 {
186 string strVal;
188
189 if ((strVal = rp.FindValue("num_output")) != null)
190 p.num_output = uint.Parse(strVal);
191
192 if ((strVal = rp.FindValue("num_output_ip")) != null)
193 p.num_output_ip = uint.Parse(strVal);
194
195 if ((strVal = rp.FindValue("clipping_threshold")) != null)
197
198 RawProto rpWeightFiller = rp.FindChild("weight_filler");
199 if (rpWeightFiller != null)
200 p.weight_filler = FillerParameter.FromProto(rpWeightFiller);
201
202 RawProto rpBiasFiller = rp.FindChild("bias_filler");
203 if (rpBiasFiller != null)
204 p.bias_filler = FillerParameter.FromProto(rpBiasFiller);
205
206 if ((strVal = rp.FindValue("enable_clockwork_forgetgate_bias")) != null)
207 p.enable_clockwork_forgetgate_bias = bool.Parse(strVal);
208
209 if ((strVal = rp.FindValue("enable_attention")) != null)
210 p.enable_attention = bool.Parse(strVal);
211
212 return p;
213 }
214 }
215}
static double ParseDouble(string strVal)
Parse double values using the US culture if the decimal separator = '.', then using the native cultur...
The RawProtoCollection class is a list of RawProto objects.
void Add(RawProto p)
Adds a RawProto to the collection.
The RawProto class is used to parse and output Google prototxt file data.
Definition: RawProto.cs:17
RawProto FindChild(string strName)
Searches for a given node.
Definition: RawProto.cs:231
static RawProto Parse(string str)
Parses a prototxt and places it in a new RawProto.
Definition: RawProto.cs:306
string FindValue(string strName)
Searches for a falue of a node within this nodes children.
Definition: RawProto.cs:105
Specifies the filler parameters used to create each Filler.
static FillerParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
FillerParameter Clone()
Creates a new copy of this instance of the parameter.
Specifies the parameters for the LSTMAttentionLayer that provides an attention based LSTM layer used ...
override object Load(System.IO.BinaryReader br, bool bNewInstance=true)
Load the parameter from a binary reader.
override RawProto ToProto(string strName)
Convert the parameter into a RawProto.
LSTMAttentionParameter()
Constructor for the parameter.
double clipping_threshold
Specifies the gradient clipping threshold, default = 0.0 (i.e. no clipping).
override void Copy(LayerParameterBase src)
Copy on parameter to another.
static LSTMAttentionParameter FromProto(RawProto rp)
Parses the parameter from a RawProto.
override LayerParameterBase Clone()
Creates a new copy of this instance of the parameter.
bool enable_clockwork_forgetgate_bias
When enabled, the forget gate bias is set to 5.0.
uint num_output_ip
Specifies the number of IP outputs for the layer. Note, when 0, no inner product is performed.
FillerParameter bias_filler
Specifies the filler parameters for the bias filler.
FillerParameter weight_filler
Specifies the filler parameters for the weight filler.
uint num_output
Specifies the number of outputs for the layer.
bool enable_attention
(default=false) When enabled, attention is applied to the input state on each cycle through the LSTM....
The LayerParameterBase is the base class for all other layer specific parameters.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
Definition: Annotation.cs:12
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...
Definition: Annotation.cs:12