22 #ifndef KALDI_NNET_NNET_LSTM_PROJECTED_H_ 23 #define KALDI_NNET_NNET_LSTM_PROJECTED_H_ 68 float param_range = 0.1;
71 while (is >> std::ws, !is.eof()) {
73 if (token ==
"<ParamRange>")
ReadBasicType(is,
false, ¶m_range);
81 else KALDI_ERR <<
"Unknown token " << token <<
", a typo in config?" 82 <<
" (ParamRange|CellDim|LearnRateCoef|BiasLearnRateCoef|CellClip|DiffClip|GradClip)";
109 while (
'<' ==
Peek(is, binary)) {
112 switch (first_char) {
118 else KALDI_ERR <<
"Unknown token: " << token;
120 case 'L':
ExpectToken(is, binary,
"<LearnRateCoef>");
123 case 'B':
ExpectToken(is, binary,
"<BiasLearnRateCoef>");
141 bias_.Read(is, binary);
156 WriteToken(os, binary,
"<BiasLearnRateCoef>");
169 if (!binary) os <<
"\n";
172 bias_.Write(os, binary);
201 offset += len; len =
bias_.Dim();
213 offset += len; len =
w_r_m_.NumRows() *
w_r_m_.NumCols();
230 offset += len; len =
bias_.Dim();
231 params->
Range(offset, len).CopyFromVec(
bias_);
242 offset += len; len =
w_r_m_.NumRows() *
w_r_m_.NumCols();
243 params->
Range(offset, len).CopyRowsFromMat(
w_r_m_);
259 offset += len; len =
bias_.Dim();
271 offset += len; len =
w_r_m_.NumRows() *
w_r_m_.NumCols();
315 return std::string(
"") +
321 "\n ### Gradients " +
329 "\n ### Activations (mostly after non-linearities)" +
338 "\n ### Derivatives (w.r.t. inputs of non-linearities)" +
358 if (stream_reset_flag[s] == 1) {
401 YGIFO.RowRange(1*S, T*S).AddVecToRows(1.0,
bias_);
404 for (
int t = 1; t <= T; t++) {
434 y_c.AddMatMatElements(1.0, y_g, y_i, 0.0);
436 y_c.AddMatMatElements(1.0, YC.RowRange((t-1)*S, S), y_f, 1.0);
453 y_m.AddMatMatElements(1.0, y_h, y_o, 0.0);
460 for (
int s = 0; s < S; s++) {
462 y_all.Row(s).SetZero();
509 DR.
RowRange(1*S, T*S).CopyFromMat(out_diff);
512 for (
int t = T; t >= 1; t--) {
552 d_m.AddMatMat(1.0, d_r, kNoTrans,
w_r_m_, kNoTrans, 0.0);
555 d_h.AddMatMatElements(1.0, d_m, y_o, 0.0);
556 d_h.DiffTanh(y_h, d_h);
559 d_o.AddMatMatElements(1.0, d_m, y_h, 0.0);
560 d_o.DiffSigmoid(y_o, d_o);
568 d_c.AddMat(1.0, d_h);
569 d_c.AddMatMatElements(1.0, DC.RowRange((t+1)*S, S), YF.RowRange((t+1)*S,S), 1.0);
580 d_f.AddMatMatElements(1.0, d_c, YC.RowRange((t-1)*S,S), 0.0);
581 d_f.DiffSigmoid(y_f, d_f);
584 d_i.AddMatMatElements(1.0, d_c, y_g, 0.0);
585 d_i.DiffSigmoid(y_i, d_i);
588 d_g.AddMatMatElements(1.0, d_c, y_i, 0.0);
589 d_g.DiffTanh(y_g, d_g);
606 for (
int s = 0; s < S; s++) {
608 d_all.Row(s).SetZero();
636 YR.RowRange(0*S, T*S) ,
kNoTrans, mmt);
638 bias_corr_.AddRowSumMat(1.0, DGIFO.RowRange(1*S, T*S), mmt);
642 YC.RowRange(0*S, T*S),
kNoTrans, mmt);
645 YC.RowRange(0*S, T*S),
kNoTrans, mmt);
648 YC.RowRange(1*S, T*S),
kNoTrans, mmt);
651 YM.RowRange(1*S, T*S),
kNoTrans, mmt);
737 #endif // KALDI_NNET_NNET_LSTM_PROJECTED_H_ BaseFloat cell_diff_clip_
Clipping of 'cell-derivatives' accumulated over CEC (per-frame),.
std::string ToString(const T &t)
Convert basic type to a string (please don't overuse),.
void CopyFromMat(const MatrixBase< OtherReal > &src, MatrixTransposeType trans=kNoTrans)
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
CuMatrix< BaseFloat > backpropagate_buf_
void BackpropagateFnc(const CuMatrixBase< BaseFloat > &in, const CuMatrixBase< BaseFloat > &out, const CuMatrixBase< BaseFloat > &out_diff, CuMatrixBase< BaseFloat > *in_diff)
Backward pass transformation (to be implemented by descending class...)
void PropagateFnc(const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out)
Abstract interface for propagation/backpropagation.
ComponentType GetType() const
Get Type Identification of the component,.
CuVector< BaseFloat > peephole_f_c_corr_
void SetParams(const VectorBase< BaseFloat > ¶ms)
Set the trainable parameters from, reshaped as a vector,.
NnetTrainOptions opts_
Option-class with training hyper-parameters,.
std::string MomentStatistics(const VectorBase< Real > &vec)
Get a string with statistics of the data in a vector, so we can print them easily.
int32 input_dim_
Data members,.
void ResetStreams(const std::vector< int32 > &stream_reset_flag)
TODO: Do we really need this?
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
BaseFloat bias_learn_rate_coef_
Scalar applied to learning rate for bias (to be used in ::Update method),.
CuMatrix< BaseFloat > propagate_buf_
BaseFloat learn_rate_coef_
Scalar applied to learning rate for weight matrices (to be used in ::Update method),.
LstmProjected(int32 input_dim, int32 output_dim)
CuMatrix< BaseFloat > w_gifo_r_corr_
void RandUniform(BaseFloat mu, BaseFloat range, CuMatrixBase< Real > *mat, struct RandomState *state=NULL)
Fill CuMatrix with random numbers (Uniform distribution): mu = the mean value, range = the 'width' of...
void GetGradient(VectorBase< BaseFloat > *gradient) const
Get gradient reshaped as a vector,.
CuVector< BaseFloat > peephole_o_c_
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
BaseFloat diff_clip_
Clipping of 'derivatives' in backprop (per-frame),.
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
int Peek(std::istream &is, bool binary)
Peek consumes whitespace (if binary == false) and then returns the peek() value of the stream...
ComponentType
Component type identification mechanism,.
int32 NumParams() const
Number of trainable parameters,.
CuMatrix< BaseFloat > w_r_m_
CuVector< BaseFloat > peephole_i_c_
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
BaseFloat grad_clip_
Clipping of the updates,.
CuMatrix< BaseFloat > w_gifo_r_
CuVector< BaseFloat > peephole_i_c_corr_
CuVector< BaseFloat > peephole_f_c_
Component * Copy() const
Copy component (deep copy),.
void AddMatMat(Real alpha, const CuMatrixBase< Real > &A, MatrixTransposeType transA, const CuMatrixBase< Real > &B, MatrixTransposeType transB, Real beta)
C = alpha * A(^T)*B(^T) + beta * C.
This class is used for a piece of a CuMatrix.
int32 proj_dim_
recurrent projection layer dim
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
MatrixIndexT Dim() const
Returns the dimension of the vector.
CuVector< BaseFloat > peephole_o_c_corr_
int PeekToken(std::istream &is, bool binary)
PeekToken will return the first character of the next token, or -1 if end of file.
void GetParams(VectorBase< BaseFloat > *params) const
Get the trainable parameters reshaped as a vector,.
CuSubMatrix< Real > RowRange(const MatrixIndexT row_offset, const MatrixIndexT num_rows) const
Class MultistreamComponent is an extension of UpdatableComponent for recurrent networks, which are trained with parallel sequences.
std::string Info() const
Print some additional info (after <ComponentName> and the dims),.
CuMatrix< BaseFloat > w_r_m_corr_
BaseFloat cell_clip_
Clipping of 'cell-values' in forward pass (per-frame),.
CuVector< BaseFloat > bias_
Matrix for CUDA computing.
void ReadData(std::istream &is, bool binary)
Reads the component content.
#define KALDI_ASSERT(cond)
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
CuVector< BaseFloat > bias_corr_
Abstract class, building block of the network.
std::string InfoGradient() const
Print some additional info about gradient (after <...> and dims),.
CuMatrix< BaseFloat > prev_nnet_state_
std::vector< int32 > sequence_lengths_
void InitData(std::istream &is)
Initialize the content of the component by the 'line' from the prototype,.
MatrixIndexT NumRows() const
Dimensions.
Provides a vector abstraction class.
void WriteData(std::ostream &os, bool binary) const
Writes the component content.
CuMatrix< BaseFloat > w_gifo_x_corr_
CuMatrix< BaseFloat > w_gifo_x_
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).
void Update(const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > &diff)
Compute gradient and update parameters,.