31 opts(opts), nnet(*nnet) {
49 opts(opts),
nnet(am_nnet->GetNnet()),
log_priors(am_nnet->Priors()) {
61 int32 left_context, right_context;
62 int32 extra_right_context = 0;
75 int32 num_sequences = 1;
98 int32 online_ivector_period):
103 ivector_(ivector), online_ivector_feats_(online_ivectors),
104 online_ivector_period_(online_ivector_period),
105 num_chunks_computed_(0),
106 current_log_post_subsampled_offset_(-1) {
110 KALDI_ASSERT(!(ivector != NULL && online_ivectors != NULL));
111 KALDI_ASSERT(!(online_ivectors != NULL && online_ivector_period <= 0 &&
112 "You need to set the --online-ivector-period option!"));
119 "Frames must be accessed in order.");
138 int32 begin_input_frame, end_input_frame;
152 if (begin_input_frame >= 0 && end_input_frame <= num_features) {
155 end_input_frame - begin_input_frame,
161 for (
int32 r = begin_input_frame; r < end_input_frame; r++) {
162 int32 input_frame = r;
163 if (input_frame < 0) input_frame = 0;
164 if (input_frame >= num_features) input_frame = num_features - 1;
165 this_feats.
Row(r - begin_input_frame).CopyFromVec(
168 feats_chunk.CopyFromMat(this_feats);
220 (num_chunks_computed_ - 1) *
233 KALDI_ERR <<
"Neural net expects iVectors but none provided.";
240 KALDI_ASSERT(ivector_frame >= 0 &&
"ivector matrix cannot be empty.");
251 int32 online_ivector_period):
252 decodable_nnet_(info, feats, ivector, online_ivectors, online_ivector_period),
253 trans_model_(trans_model) { }
256 int32 transition_id) {
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void ModifyNnetIvectorPeriod(int32 ivector_period, Nnet *nnet)
This function modifies the descriptors in the neural network to change the periodicity with which it ...
NnetComputation computation
int32 InputDim(const std::string &input_name) const
const VectorBase< BaseFloat > * ivector_
ComputationRequest request1
int32 frame_subsampling_factor
const CuSubVector< Real > Row(MatrixIndexT i) const
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
int32 TransitionIdToPdfFast(int32 trans_id) const
void GetCurrentIvector(int32 input_frame, Vector< BaseFloat > *ivector)
Base class which provides matrix operations not involving resizing or allocation. ...
void ComputeCudaIndexes()
int32 GetChunkSize(const Nnet &nnet, int32 frame_subsampling_factor, int32 advised_chunk_size)
void CreateLoopedComputationRequest(const Nnet &nnet, int32 chunk_size, int32 frame_subsampling_factor, int32 ivector_period, int32 left_context_begin, int32 right_context, int32 num_sequences, ComputationRequest *request1, ComputationRequest *request2, ComputationRequest *request3)
This function creates computation request suitable for giving to ComputeLooped(). ...
ComputationRequest request2
const MatrixBase< BaseFloat > * online_ivector_feats_
int32 online_ivector_period_
int32 frames_right_context
int32 extra_left_context_initial
std::vector< IoSpecification > inputs
This class represents a matrix that's stored on the GPU if we have one, and in memory if not...
int32 current_log_post_subsampled_offset_
void Swap(Matrix< Real > *other)
Swaps the contents of *this and *other. Shallow swap.
void CopyFromMat(const MatrixBase< OtherReal > &M, MatrixTransposeType trans=kNoTrans)
Copy given matrix. (no resize is done).
const Nnet & GetNnet() const
DecodableNnetSimpleLoopedInfo(const NnetSimpleLoopedComputationOptions &opts, Nnet *nnet)
const MatrixBase< BaseFloat > & feats_
int32 OutputDim(const std::string &output_name) const
This file contains some miscellaneous functions dealing with class Nnet.
const NnetSimpleLoopedComputationOptions & opts
void AcceptInput(const std::string &node_name, CuMatrix< BaseFloat > *input)
e.g.
void CopyFromVec(const VectorBase< Real > &v)
Copy data from another vector (must match own size).
int32 num_chunks_computed_
void CompileLooped(const Nnet &nnet, const NnetOptimizeOptions &optimize_opts, const ComputationRequest &request1, const ComputationRequest &request2, const ComputationRequest &request3, NnetComputation *computation)
CompileLooped() provides an internal interface for 'looped' computation.
const TransitionModel & trans_model_
const SubVector< Real > Row(MatrixIndexT i) const
Return specific row of matrix [const].
void AddVecToRows(Real alpha, const CuVectorBase< Real > &row, Real beta=1.0)
(for each row r of *this), r = alpha * row + beta * r
virtual BaseFloat LogLikelihood(int32 frame, int32 transition_id)
Returns the log likelihood, which will be negated in the decoder.
void ComputeSimpleNnetContext(const Nnet &nnet, int32 *left_context, int32 *right_context)
ComputeSimpleNnetContext computes the left-context and right-context of a nnet.
NnetOptimizeOptions optimize_config
int32 frames_left_context
Matrix< BaseFloat > current_log_post_
void GetOutputForFrame(int32 subsampled_frame, VectorBase< BaseFloat > *output)
MatrixIndexT Dim() const
Returns the dimension of the vector.
bool IsSimpleNnet(const Nnet &nnet)
This function returns true if the nnet has the following properties: It has an output called "output"...
DecodableNnetSimpleLooped decodable_nnet_
A class representing a vector.
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
ComputationRequest request3
void Resize(const MatrixIndexT r, const MatrixIndexT c, MatrixResizeType resize_type=kSetZero, MatrixStrideType stride_type=kDefaultStride)
Sets matrix to a specified size (zero is OK as long as both r and c are zero).
BaseFloat GetOutput(int32 subsampled_frame, int32 pdf_id)
DecodableAmNnetSimpleLooped(const DecodableNnetSimpleLoopedInfo &info, const TransitionModel &trans_model, const MatrixBase< BaseFloat > &feats, const VectorBase< BaseFloat > *ivector=NULL, const MatrixBase< BaseFloat > *online_ivectors=NULL, int32 online_ivector_period=1)
This constructor takes features as input, and you can either supply a single iVector input...
void GetOutputDestructive(const std::string &output_name, CuMatrix< BaseFloat > *output)
Provides a vector abstraction class.
void CopyRowsFromVec(const VectorBase< Real > &v)
This function has two modes of operation.
When you instantiate class DecodableNnetSimpleLooped, you should give it a const reference to this cl...
CuVector< BaseFloat > log_priors
void Init(const NnetSimpleLoopedComputationOptions &opts, Nnet *nnet)
Sub-matrix representation.
int32 num_subsampled_frames_
int32 GetIvectorDim() const
DecodableNnetSimpleLooped(const DecodableNnetSimpleLoopedInfo &info, const MatrixBase< BaseFloat > &feats, const VectorBase< BaseFloat > *ivector=NULL, const MatrixBase< BaseFloat > *online_ivectors=NULL, int32 online_ivector_period=1)
This constructor takes features as input, and you can either supply a single iVector input...
const DecodableNnetSimpleLoopedInfo & info_
void Run()
This does either the forward or backward computation, depending when it is called (in a typical compu...