22 #ifndef KALDI_NNET_NNET_BLSTM_PROJECTED_H_ 23 #define KALDI_NNET_NNET_BLSTM_PROJECTED_H_ 70 float param_range = 0.1;
73 while (is >> std::ws, !is.eof()) {
75 if (token ==
"<ParamRange>")
ReadBasicType(is,
false, ¶m_range);
83 else KALDI_ERR <<
"Unknown token " << token <<
", a typo in config?" 84 <<
" (ParamRange|CellDim|LearnRateCoef|BiasLearnRateCoef|CellClip|DiffClip|GradClip)";
137 while (
'<' ==
Peek(is, binary)) {
140 switch (first_char) {
146 else KALDI_ERR <<
"Unknown token: " << token;
148 case 'L':
ExpectToken(is, binary,
"<LearnRateCoef>");
151 case 'B':
ExpectToken(is, binary,
"<BiasLearnRateCoef>");
196 WriteToken(os, binary,
"<BiasLearnRateCoef>");
208 if (!binary) os <<
"\n";
220 if (!binary) os <<
"\n";
254 offset += len; len =
f_bias_.Dim();
276 offset += len; len =
b_bias_.Dim();
307 offset += len; len =
f_bias_.Dim();
329 offset += len; len =
b_bias_.Dim();
360 offset += len; len =
f_bias_.Dim();
382 offset += len; len =
b_bias_.Dim();
410 "\n Forward Direction weights:" +
418 "\n Backward Direction weights:" +
470 return std::string(
"") +
476 "\n ### Gradients " +
493 "\n ### Activations (mostly after non-linearities)" +
512 "\n ### Derivatives (w.r.t. inputs of non-linearities)" +
570 F_YGIFO.RowRange(1*S, T*S).AddVecToRows(1.0,
f_bias_);
573 for (
int t = 1; t <= T; t++) {
603 y_c.AddMatMatElements(1.0, y_g, y_i, 0.0);
605 y_c.AddMatMatElements(1.0, F_YC.RowRange((t-1)*S, S), y_f, 1.0);
622 y_m.AddMatMatElements(1.0, y_h, y_o, 0.0);
629 for (
int s = 0; s < S; s++) {
631 y_all.Row(s).SetZero();
642 B_YGIFO.RowRange(1*S, T*S).AddVecToRows(1.0,
b_bias_);
645 for (
int t = T; t >= 1; t--) {
675 y_c.AddMatMatElements(1.0, y_g, y_i, 0.0);
677 y_c.AddMatMatElements(1.0, B_YC.RowRange((t+1)*S, S), y_f, 1.0);
694 y_m.AddMatMatElements(1.0, y_h, y_o, 0.0);
701 for (
int s = 0; s < S; s++) {
703 y_all.Row(s).SetZero();
759 for (
int t = T; t >= 1; t--) {
800 d_m.AddMatMat(1.0, d_r, kNoTrans,
f_w_r_m_, kNoTrans, 0.0);
803 d_h.AddMatMatElements(1.0, d_m, y_o, 0.0);
804 d_h.DiffTanh(y_h, d_h);
807 d_o.AddMatMatElements(1.0, d_m, y_h, 0.0);
808 d_o.DiffSigmoid(y_o, d_o);
816 d_c.AddMat(1.0, d_h);
817 d_c.AddMatMatElements(1.0, F_DC.RowRange((t+1)*S, S), F_YF.RowRange((t+1)*S, S), 1.0);
828 d_f.AddMatMatElements(1.0, d_c, F_YC.RowRange((t-1)*S, S), 0.0);
829 d_f.DiffSigmoid(y_f, d_f);
832 d_i.AddMatMatElements(1.0, d_c, y_g, 0.0);
833 d_i.DiffSigmoid(y_i, d_i);
836 d_g.AddMatMatElements(1.0, d_c, y_i, 0.0);
837 d_g.DiffTanh(y_g, d_g);
854 for (
int s = 0; s < S; s++) {
856 d_all.Row(s).SetZero();
888 for (
int t = 1; t <= T; t++) {
928 d_m.AddMatMat(1.0, d_r, kNoTrans,
b_w_r_m_, kNoTrans, 0.0);
931 d_h.AddMatMatElements(1.0, d_m, y_o, 0.0);
932 d_h.DiffTanh(y_h, d_h);
935 d_o.AddMatMatElements(1.0, d_m, y_h, 0.0);
936 d_o.DiffSigmoid(y_o, d_o);
944 d_c.AddMat(1.0, d_h);
945 d_c.AddMatMatElements(1.0, B_DC.RowRange((t-1)*S, S), B_YF.RowRange((t-1)*S, S), 1.0);
956 d_f.AddMatMatElements(1.0, d_c, B_YC.RowRange((t-1)*S, S), 0.0);
957 d_f.DiffSigmoid(y_f, d_f);
960 d_i.AddMatMatElements(1.0, d_c, y_g, 0.0);
961 d_i.DiffSigmoid(y_i, d_i);
964 d_g.AddMatMatElements(1.0, d_c, y_i, 0.0);
965 d_g.DiffTanh(y_g, d_g);
982 for (
int s = 0; s < S; s++) {
984 d_all.Row(s).SetZero();
1027 F_YR.RowRange(0*S, T*S),
kNoTrans, mmt);
1029 f_bias_corr_.AddRowSumMat(1.0, F_DGIFO.RowRange(1*S, T*S), mmt);
1033 F_YC.RowRange(0*S, T*S),
kNoTrans, mmt);
1036 F_YC.RowRange(0*S, T*S),
kNoTrans, mmt);
1039 F_YC.RowRange(1*S, T*S),
kNoTrans, mmt);
1042 F_YM.RowRange(1*S, T*S),
kNoTrans, mmt);
1049 B_YR.RowRange(0*S, T*S) ,
kNoTrans, mmt);
1051 b_bias_corr_.AddRowSumMat(1.0, B_DGIFO.RowRange(1*S, T*S), mmt);
1055 B_YC.RowRange(2*S, T*S),
kNoTrans, mmt);
1058 B_YC.RowRange(2*S, T*S),
kNoTrans, mmt);
1061 B_YC.RowRange(1*S, T*S),
kNoTrans, mmt);
1064 B_YM.RowRange(1*S, T*S),
kNoTrans, mmt);
1206 #endif // KALDI_NNET_NNET_BLSTM_PROJECTED_H_ void GetParams(VectorBase< BaseFloat > *params) const
Get the trainable parameters reshaped as a vector,.
std::string ToString(const T &t)
Convert basic type to a string (please don't overuse),.
CuVector< BaseFloat > b_peephole_i_c_
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 > b_propagate_buf_
CuVector< BaseFloat > b_peephole_o_c_corr_
CuMatrix< BaseFloat > b_w_gifo_x_corr_
BaseFloat diff_clip_
Clipping of 'derivatives' in backprop (per-frame),.
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 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),.
BaseFloat learn_rate_coef_
Scalar applied to learning rate for weight matrices (to be used in ::Update method),.
CuVector< BaseFloat > f_peephole_o_c_corr_
std::string InfoGradient() const
Print some additional info about gradient (after <...> and dims),.
void Update(const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > &diff)
Compute gradient and update parameters,.
CuMatrix< BaseFloat > b_w_r_m_
CuVector< BaseFloat > b_peephole_i_c_corr_
CuMatrix< BaseFloat > f_w_gifo_r_
CuMatrix< BaseFloat > f_w_gifo_x_corr_
CuVector< BaseFloat > f_bias_
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 ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
void WriteData(std::ostream &os, bool binary) const
Writes the component content.
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
CuMatrix< BaseFloat > f_backpropagate_buf_
CuVector< BaseFloat > f_peephole_o_c_
BaseFloat cell_diff_clip_
Clipping of 'cell-derivatives' accumulated over CEC (per-frame),.
void ReadData(std::istream &is, bool binary)
Reads the component content.
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,.
CuVector< BaseFloat > f_bias_corr_
CuVector< BaseFloat > b_bias_
int32 proj_dim_
recurrent projection layer dim,
void InitData(std::istream &is)
Initialize the content of the component by the 'line' from the prototype,.
void SetParams(const VectorBase< BaseFloat > ¶ms)
Set the trainable parameters from, reshaped as a vector,.
std::string Info() const
Print some additional info (after <ComponentName> and the dims),.
CuVector< BaseFloat > b_peephole_f_c_
BaseFloat grad_clip_
Clipping of the updates,.
void PropagateFnc(const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out)
Abstract interface for propagation/backpropagation.
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
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 GetGradient(VectorBase< BaseFloat > *gradient) const
Get gradient reshaped as a vector,.
CuVector< BaseFloat > f_peephole_i_c_corr_
CuVector< BaseFloat > f_peephole_f_c_
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.
ComponentType GetType() const
Get Type Identification of the component,.
CuVector< BaseFloat > b_peephole_o_c_
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.
int PeekToken(std::istream &is, bool binary)
PeekToken will return the first character of the next token, or -1 if end of file.
CuSubMatrix< Real > RowRange(const MatrixIndexT row_offset, const MatrixIndexT num_rows) const
CuVector< BaseFloat > b_peephole_f_c_corr_
Class MultistreamComponent is an extension of UpdatableComponent for recurrent networks, which are trained with parallel sequences.
CuMatrix< BaseFloat > f_w_gifo_x_
CuVector< BaseFloat > f_peephole_i_c_
BlstmProjected(int32 input_dim, int32 output_dim)
CuMatrix< BaseFloat > b_w_gifo_r_corr_
CuSubMatrix< Real > ColRange(const MatrixIndexT col_offset, const MatrixIndexT num_cols) const
CuMatrix< BaseFloat > f_w_r_m_corr_
Matrix for CUDA computing.
int32 NumParams() const
Number of trainable parameters,.
#define KALDI_ASSERT(cond)
CuVector< BaseFloat > f_peephole_f_c_corr_
Component * Copy() const
Copy component (deep copy),.
CuMatrix< BaseFloat > f_w_r_m_
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...
Abstract class, building block of the network.
CuMatrix< BaseFloat > f_propagate_buf_
int32 cell_dim_
the number of memory-cell blocks,
std::vector< int32 > sequence_lengths_
BaseFloat cell_clip_
Clipping of 'cell-values' in forward pass (per-frame),.
CuMatrix< BaseFloat > b_w_gifo_r_
CuMatrix< BaseFloat > b_w_r_m_corr_
MatrixIndexT NumRows() const
Dimensions.
Provides a vector abstraction class.
CuMatrix< BaseFloat > f_w_gifo_r_corr_
CuMatrix< BaseFloat > b_backpropagate_buf_
void Resize(MatrixIndexT rows, MatrixIndexT cols, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Allocate the memory.
CuMatrix< BaseFloat > b_w_gifo_x_
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).
CuVector< BaseFloat > b_bias_corr_