Splice Class Reference

Splices the time context of the input features in N, out k*N, FrameOffset o_1,o_2,...,o_k FrameOffset example 11frames: -5 -4 -3 -2 -1 0 1 2 3 4 5. More...

#include <nnet-various.h>

Inheritance diagram for Splice:
Collaboration diagram for Splice:

Public Member Functions

 Splice (int32 dim_in, int32 dim_out)
 
 ~Splice ()
 
ComponentCopy () const
 Copy component (deep copy),. More...
 
ComponentType GetType () const
 Get Type Identification of the component,. More...
 
void InitData (std::istream &is)
 Virtual interface for initialization and I/O,. More...
 
void ReadData (std::istream &is, bool binary)
 Reads the component content. More...
 
void WriteData (std::ostream &os, bool binary) const
 Writes the component content. More...
 
std::string Info () const
 Print some additional info (after <ComponentName> and the dims),. More...
 
void PropagateFnc (const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out)
 Abstract interface for propagation/backpropagation. More...
 
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...) More...
 
- Public Member Functions inherited from Component
 Component (int32 input_dim, int32 output_dim)
 Generic interface of a component,. More...
 
virtual ~Component ()
 
virtual bool IsUpdatable () const
 Check if componeny has 'Updatable' interface (trainable components),. More...
 
virtual bool IsMultistream () const
 Check if component has 'Recurrent' interface (trainable and recurrent),. More...
 
int32 InputDim () const
 Get the dimension of the input,. More...
 
int32 OutputDim () const
 Get the dimension of the output,. More...
 
void Propagate (const CuMatrixBase< BaseFloat > &in, CuMatrix< BaseFloat > *out)
 Perform forward-pass propagation 'in' -> 'out',. More...
 
void Backpropagate (const CuMatrixBase< BaseFloat > &in, const CuMatrixBase< BaseFloat > &out, const CuMatrixBase< BaseFloat > &out_diff, CuMatrix< BaseFloat > *in_diff)
 Perform backward-pass propagation 'out_diff' -> 'in_diff'. More...
 
void Write (std::ostream &os, bool binary) const
 Write the component to a stream,. More...
 
virtual std::string InfoGradient () const
 Print some additional info about gradient (after <...> and dims),. More...
 

Protected Attributes

CuArray< int32frame_offsets_
 
- Protected Attributes inherited from Component
int32 input_dim_
 Data members,. More...
 
int32 output_dim_
 Dimension of the output of the Component,. More...
 

Additional Inherited Members

- Public Types inherited from Component
enum  ComponentType {
  kUnknown = 0x0, kUpdatableComponent = 0x0100, kAffineTransform, kLinearTransform,
  kConvolutionalComponent, kLstmProjected, kBlstmProjected, kRecurrentComponent,
  kActivationFunction = 0x0200, kSoftmax, kHiddenSoftmax, kBlockSoftmax,
  kSigmoid, kTanh, kParametricRelu, kDropout,
  kLengthNormComponent, kTranform = 0x0400, kRbm, kSplice,
  kCopy, kTranspose, kBlockLinearity, kAddShift,
  kRescale, kKlHmm = 0x0800, kSentenceAveragingComponent, kSimpleSentenceAveragingComponent,
  kAveragePoolingComponent, kMaxPoolingComponent, kFramePoolingComponent, kParallelComponent,
  kMultiBasisComponent
}
 Component type identification mechanism,. More...
 
- Static Public Member Functions inherited from Component
static const char * TypeToMarker (ComponentType t)
 Converts component type to marker,. More...
 
static ComponentType MarkerToType (const std::string &s)
 Converts marker to component type (case insensitive),. More...
 
static ComponentInit (const std::string &conf_line)
 Initialize component from a line in config file,. More...
 
static ComponentRead (std::istream &is, bool binary)
 Read the component from a stream (static method),. More...
 
- Static Public Attributes inherited from Component
static const struct key_value kMarkerMap []
 The table with pairs of Component types and markers (defined in nnet-component.cc),. More...
 

Detailed Description

Splices the time context of the input features in N, out k*N, FrameOffset o_1,o_2,...,o_k FrameOffset example 11frames: -5 -4 -3 -2 -1 0 1 2 3 4 5.

Definition at line 42 of file nnet-various.h.

Constructor & Destructor Documentation

◆ Splice()

Splice ( int32  dim_in,
int32  dim_out 
)
inline

Definition at line 44 of file nnet-various.h.

Referenced by Splice::Copy().

44  :
45  Component(dim_in, dim_out)
46  { }
Component(int32 input_dim, int32 output_dim)
Generic interface of a component,.

◆ ~Splice()

~Splice ( )
inline

Definition at line 48 of file nnet-various.h.

49  { }

Member Function Documentation

◆ BackpropagateFnc()

void BackpropagateFnc ( const CuMatrixBase< BaseFloat > &  in,
const CuMatrixBase< BaseFloat > &  out,
const CuMatrixBase< BaseFloat > &  out_diff,
CuMatrixBase< BaseFloat > *  in_diff 
)
inlinevirtual

Backward pass transformation (to be implemented by descending class...)

Implements Component.

Definition at line 111 of file nnet-various.h.

References CuMatrixBase< Real >::AddMat(), CuArrayBase< T >::CopyToVec(), CuArrayBase< T >::Dim(), Splice::frame_offsets_, rnnlm::i, kaldi::kNoTrans, CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), CuMatrixBase< Real >::Range(), and CuMatrixBase< Real >::RowRange().

114  {
115  // WARNING!!! WARNING!!! WARNING!!!
116  // THIS BACKPROPAGATION CAN BE USED ONLY WITH 'PER-UTTERANCE' TRAINING!
117  // IN MINI-BATCH TRAINING, THIS <Splice> COMPONENT HAS TO BE PART OF THE
118  // 'feature_transform' SO WE DON'T BACKPROPAGATE THROUGH IT...
119 
120  // dims,
121  int32 input_dim = in.NumCols(),
122  num_frames = out_diff.NumRows();
123  // Copy offsets to 'host',
124  std::vector<int32> offsets(frame_offsets_.Dim());
125  frame_offsets_.CopyToVec(&offsets);
126  // loop over the offsets,
127  for (int32 i = 0; i < offsets.size(); i++) {
128  int32 o_i = offsets.at(i);
129  int32 n_rows = num_frames - abs(o_i),
130  src_row = std::max(-o_i, 0),
131  tgt_row = std::max(o_i, 0);
132  const CuSubMatrix<BaseFloat> src = out_diff.Range(src_row, n_rows, i*input_dim, input_dim);
133  CuSubMatrix<BaseFloat> tgt = in_diff->RowRange(tgt_row, n_rows);
134  tgt.AddMat(1.0, src, kNoTrans);
135  }
136  }
void CopyToVec(std::vector< T > *dst) const
This function resizes *dst if needed.
Definition: cu-array-inl.h:177
kaldi::int32 int32
CuArray< int32 > frame_offsets_
Definition: nnet-various.h:139
MatrixIndexT Dim() const
Return the vector dimension.
Definition: cu-array.h:49

◆ Copy()

Component* Copy ( ) const
inlinevirtual

Copy component (deep copy),.

Implements Component.

Definition at line 51 of file nnet-various.h.

References Splice::Splice().

51 { return new Splice(*this); }
Splice(int32 dim_in, int32 dim_out)
Definition: nnet-various.h:44

◆ GetType()

ComponentType GetType ( ) const
inlinevirtual

Get Type Identification of the component,.

Implements Component.

Definition at line 52 of file nnet-various.h.

References Component::kSplice.

Referenced by CopyComponent::BackpropagateFnc().

◆ Info()

std::string Info ( ) const
inlinevirtual

Print some additional info (after <ComponentName> and the dims),.

Reimplemented from Component.

Definition at line 98 of file nnet-various.h.

References Splice::frame_offsets_.

98  {
99  std::ostringstream ostr;
100  ostr << "\n frame_offsets " << frame_offsets_;
101  std::string str = ostr.str();
102  str.erase(str.end()-1);
103  return str;
104  }
CuArray< int32 > frame_offsets_
Definition: nnet-various.h:139

◆ InitData()

void InitData ( std::istream &  is)
inlinevirtual

Virtual interface for initialization and I/O,.

Initialize internal data of a component

Reimplemented from Component.

Definition at line 54 of file nnet-various.h.

References kaldi::nnet1::BuildIntegerVector(), CuArrayBase< T >::Dim(), Splice::frame_offsets_, Component::InputDim(), KALDI_ASSERT, KALDI_ERR, Component::OutputDim(), CuArray< T >::Read(), kaldi::ReadToken(), and kaldi::SplitStringToIntegers().

54  {
55  // define options,
56  std::vector<std::vector<int32> > build_vector;
57  // parse config,
58  std::string token;
59  while (is >> std::ws, !is.eof()) {
60  ReadToken(is, false, &token);
61  if (token == "<ReadVector>") {
62  frame_offsets_.Read(is, false);
63  } else if (token == "<BuildVector>") {
64  // Parse the list of 'matlab-like' indices:
65  // <BuildVector> 1:1:1000 1 2 3 1:10 </BuildVector>
66  while (is >> std::ws, !is.eof()) {
67  std::string colon_sep_list_or_end;
68  ReadToken(is, false, &colon_sep_list_or_end);
69  if (colon_sep_list_or_end == "</BuildVector>") break;
70  std::vector<int32> v;
71  SplitStringToIntegers(colon_sep_list_or_end, ":", false, &v);
72  build_vector.push_back(v);
73  }
74  } else {
75  KALDI_ERR << "Unknown token " << token << ", a typo in config?"
76  << " (ReadVector|BuildVector)";
77  }
78  }
79 
80  if (build_vector.size() > 0) {
81  // build the vector, using <BuildVector> ... </BuildVector> inputs,
82  BuildIntegerVector(build_vector, &frame_offsets_);
83  }
84 
85  // check dim
87  }
bool SplitStringToIntegers(const std::string &full, const char *delim, bool omit_empty_strings, std::vector< I > *out)
Split a string (e.g.
Definition: text-utils.h:68
void ReadToken(std::istream &is, bool binary, std::string *str)
ReadToken gets the next token and puts it in str (exception on failure).
Definition: io-funcs.cc:154
CuArray< int32 > frame_offsets_
Definition: nnet-various.h:139
void Read(std::istream &is, bool binary)
I/O.
Definition: cu-array-inl.h:300
int32 InputDim() const
Get the dimension of the input,.
void BuildIntegerVector(const std::vector< std::vector< int32 > > &in, std::vector< int32 > *out)
Build &#39;integer vector&#39; out of vector of &#39;matlab-like&#39; representation: &#39;b, b:e, b:s:e&#39;.
Definition: nnet-utils.h:239
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 OutputDim() const
Get the dimension of the output,.
MatrixIndexT Dim() const
Return the vector dimension.
Definition: cu-array.h:49

◆ PropagateFnc()

void PropagateFnc ( const CuMatrixBase< BaseFloat > &  in,
CuMatrixBase< BaseFloat > *  out 
)
inlinevirtual

Abstract interface for propagation/backpropagation.

Forward pass transformation (to be implemented by descending class...)

Implements Component.

Definition at line 106 of file nnet-various.h.

References Splice::frame_offsets_, and kaldi::cu::Splice().

107  {
108  cu::Splice(in, frame_offsets_, out);
109  }
CuArray< int32 > frame_offsets_
Definition: nnet-various.h:139
void Splice(const CuMatrixBase< Real > &src, const CuArray< int32 > &frame_offsets, CuMatrixBase< Real > *tgt)
Splice concatenates frames of src as specified in frame_offsets into tgt.
Definition: cu-math.cc:132

◆ ReadData()

void ReadData ( std::istream &  is,
bool  binary 
)
inlinevirtual

Reads the component content.

Reimplemented from Component.

Definition at line 89 of file nnet-various.h.

References CuArrayBase< T >::Dim(), Splice::frame_offsets_, Component::InputDim(), KALDI_ASSERT, Component::OutputDim(), and CuArray< T >::Read().

89  {
90  frame_offsets_.Read(is, binary);
92  }
CuArray< int32 > frame_offsets_
Definition: nnet-various.h:139
void Read(std::istream &is, bool binary)
I/O.
Definition: cu-array-inl.h:300
int32 InputDim() const
Get the dimension of the input,.
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
int32 OutputDim() const
Get the dimension of the output,.
MatrixIndexT Dim() const
Return the vector dimension.
Definition: cu-array.h:49

◆ WriteData()

void WriteData ( std::ostream &  os,
bool  binary 
) const
inlinevirtual

Writes the component content.

Reimplemented from Component.

Definition at line 94 of file nnet-various.h.

References Splice::frame_offsets_, and CuArray< T >::Write().

Referenced by kaldi::ConvertSpliceComponent().

94  {
95  frame_offsets_.Write(os, binary);
96  }
CuArray< int32 > frame_offsets_
Definition: nnet-various.h:139
void Write(std::ostream &is, bool binary) const
Definition: cu-array-inl.h:307

Member Data Documentation

◆ frame_offsets_


The documentation for this class was generated from the following file: