22 #ifndef KALDI_NNET_NNET_RECURRENT_STREAMS_H_ 23 #define KALDI_NNET_NNET_RECURRENT_STREAMS_H_ 57 float param_scale = 0.02;
60 while (is >> std::ws, !is.eof()) {
66 else if (token ==
"<ParamScale>")
ReadBasicType(is,
false, ¶m_scale);
67 else KALDI_ERR <<
"Unknown token " << token <<
", a typo in config?" 68 <<
" (GradClip|DiffClip|LearnRateCoef|BiasLearnRateCoef|ParamScale)";
83 while (
'<' ==
Peek(is, binary)) {
93 case 'L':
ExpectToken(is, binary,
"<LearnRateCoef>");
96 case 'B':
ExpectToken(is, binary,
"<BiasLearnRateCoef>");
107 bias_.Read(is, binary);
118 WriteToken(os, binary,
"<BiasLearnRateCoef>");
121 if (!binary) os <<
"\n";
124 bias_.Write(os, binary);
160 offset += len; len =
bias_.Dim();
161 params->
Range(offset, len).CopyFromVec(
bias_);
177 offset += len; len =
bias_.Dim();
185 return std::string(
" ") +
192 return std::string(
"") +
203 "\n Backward-pass:" +
224 for (
int32 t = 1; t < T; t++) {
229 for (
int32 s = 0; s < S; s++) {
231 out->
Row(t*S + s).SetZero();
253 for (
int32 t = T-1; t >= 1; t--) {
271 for (
int32 s = 0; s < S; s++) {
346 #endif // KALDI_NNET_NNET_RECURRENT_STREAMS_H_ std::string ToString(const T &t)
Convert basic type to a string (please don't overuse),.
ComponentType GetType() const
Get Type Identification of the component,.
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void ApplyCeiling(Real ceiling_val)
void GetGradient(VectorBase< BaseFloat > *gradient) const
Get gradient reshaped as a vector,.
const CuSubVector< Real > Row(MatrixIndexT i) const
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 > bias_corr_
void ApplyFloor(Real floor_val)
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).
std::string InfoGradient() const
Print some additional info about gradient (after <...> and dims),.
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,.
Component * Copy() const
Copy component (deep copy),.
CuMatrix< BaseFloat > w_recurrent_corr_
BaseFloat diff_clip_
Clipping in the BPTT loop,.
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 GetParams(VectorBase< BaseFloat > *params) const
Get the trainable parameters reshaped as a vector,.
void Update(const CuMatrixBase< BaseFloat > &input, const CuMatrixBase< BaseFloat > &diff)
Compute gradient and update parameters,.
CuMatrix< BaseFloat > w_recurrent_
void AddVecToRows(Real alpha, const CuVectorBase< Real > &row, Real beta=1.0)
(for each row r of *this), r = alpha * row + beta * r
void WriteData(std::ostream &os, bool binary) const
Writes the component content.
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 PropagateFnc(const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out)
Abstract interface for propagation/backpropagation.
void InitData(std::istream &is)
Initialize the content of the component by the 'line' from the prototype,.
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.
CuMatrix< BaseFloat > out_diff_bptt_
This class is used for a piece of a CuMatrix.
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
Class MultistreamComponent is an extension of UpdatableComponent for recurrent networks, which are trained with parallel sequences.
void DiffTanh(const CuMatrixBase< Real > &value, const CuMatrixBase< Real > &diff)
Differentiate backward through the tanh function.
std::string Info() const
Print some additional info (after <ComponentName> and the dims),.
CuMatrix< BaseFloat > w_forward_corr_
int32 output_dim_
Dimension of the output of the Component,.
int32 NumParams() const
Number of trainable parameters,.
Matrix for CUDA computing.
void SetParams(const VectorBase< BaseFloat > ¶ms)
Set the trainable parameters from, reshaped as a vector,.
CuVector< BaseFloat > bias_
#define KALDI_ASSERT(cond)
Component with recurrent connections, 'tanh' non-linearity.
BaseFloat grad_clip_
Clipping of the update,.
CuMatrix< BaseFloat > out_
void ReadData(std::istream &is, bool binary)
Reads the component content.
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.
std::vector< int32 > sequence_lengths_
int32 OutputDim() const
Get the dimension of the output,.
MatrixIndexT NumRows() const
Dimensions.
Provides a vector abstraction class.
CuMatrix< BaseFloat > w_forward_
RecurrentComponent(int32 input_dim, int32 output_dim)
SubVector< Real > Range(const MatrixIndexT o, const MatrixIndexT l)
Returns a sub-vector of a vector (a range of elements).