MaxoutComponent Class Reference

#include <nnet-component.h>

Inheritance diagram for MaxoutComponent:
Collaboration diagram for MaxoutComponent:

Public Member Functions

void Init (int32 input_dim, int32 output_dim)
 
 MaxoutComponent (int32 input_dim, int32 output_dim)
 
 MaxoutComponent ()
 
virtual std::string Type () const
 
virtual void InitFromString (std::string args)
 Initialize, typically from a line of a config file. More...
 
virtual int32 InputDim () const
 Get size of input vectors. More...
 
virtual int32 OutputDim () const
 Get size of output vectors. More...
 
virtual void Propagate (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in, CuMatrixBase< BaseFloat > *out) const
 Perform forward pass propagation Input->Output. More...
 
virtual void Backprop (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in_value, const CuMatrixBase< BaseFloat > &, const CuMatrixBase< BaseFloat > &out_deriv, Component *to_update, CuMatrix< BaseFloat > *in_deriv) const
 Perform backward pass propagation of the derivative, and also either update the model (if to_update == this) or update another model or compute the model derivative (otherwise). More...
 
virtual bool BackpropNeedsInput () const
 
virtual bool BackpropNeedsOutput () const
 
virtual ComponentCopy () const
 Copy component (deep copy). More...
 
virtual void Read (std::istream &is, bool binary)
 
virtual void Write (std::ostream &os, bool binary) const
 Write component to stream. More...
 
virtual std::string Info () const
 
- Public Member Functions inherited from Component
 Component ()
 
virtual int32 Index () const
 Returns the index in the sequence of layers in the neural net; intended only to be used in debugging information. More...
 
virtual void SetIndex (int32 index)
 
virtual std::vector< int32Context () const
 Return a vector describing the temporal context this component requires for each frame of output, as a sorted list. More...
 
void Propagate (const ChunkInfo &in_info, const ChunkInfo &out_info, const CuMatrixBase< BaseFloat > &in, CuMatrix< BaseFloat > *out) const
 A non-virtual propagate function that first resizes output if necessary. More...
 
virtual ~Component ()
 

Protected Attributes

int32 input_dim_
 
int32 output_dim_
 

Additional Inherited Members

- Static Public Member Functions inherited from Component
static ComponentReadNew (std::istream &is, bool binary)
 Read component from stream. More...
 
static ComponentNewFromString (const std::string &initializer_line)
 Initialize the Component from one line that will contain first the type, e.g. More...
 
static ComponentNewComponentOfType (const std::string &type)
 Return a new Component of the given type e.g. More...
 

Detailed Description

Definition at line 411 of file nnet-component.h.

Constructor & Destructor Documentation

◆ MaxoutComponent() [1/2]

MaxoutComponent ( int32  input_dim,
int32  output_dim 
)
inlineexplicit

Definition at line 414 of file nnet-component.h.

414  {
415  Init(input_dim, output_dim);
416  }
void Init(int32 input_dim, int32 output_dim)

◆ MaxoutComponent() [2/2]

MaxoutComponent ( )
inline

Definition at line 417 of file nnet-component.h.

Member Function Documentation

◆ Backprop()

void Backprop ( const ChunkInfo in_info,
const ChunkInfo out_info,
const CuMatrixBase< BaseFloat > &  in_value,
const CuMatrixBase< BaseFloat > &  out_value,
const CuMatrixBase< BaseFloat > &  out_deriv,
Component to_update,
CuMatrix< BaseFloat > *  in_deriv 
) const
virtual

Perform backward pass propagation of the derivative, and also either update the model (if to_update == this) or update another model or compute the model derivative (otherwise).

Note: in_value and out_value are the values of the input and output of the component, and these may be dummy variables if respectively BackpropNeedsInput() or BackpropNeedsOutput() return false for that component (not all components need these).

num_chunks lets us treat the input matrix as contiguous-in-time chunks of equal size; it only matters if splicing is involved.

Implements Component.

Definition at line 452 of file nnet-component.cc.

References CuMatrixBase< Real >::GroupMaxDeriv(), kaldi::kSetZero, CuMatrixBase< Real >::MulRowsGroupMat(), CuMatrixBase< Real >::NumCols(), CuMatrixBase< Real >::NumRows(), and CuMatrix< Real >::Resize().

458  {
459  in_deriv->Resize(in_value.NumRows(), in_value.NumCols(), kSetZero);
460  in_deriv->GroupMaxDeriv(in_value, out_value);
461  in_deriv->MulRowsGroupMat(out_deriv);
462 }

◆ BackpropNeedsInput()

virtual bool BackpropNeedsInput ( ) const
inlinevirtual

Reimplemented from Component.

Definition at line 434 of file nnet-component.h.

434 { return true; }

◆ BackpropNeedsOutput()

virtual bool BackpropNeedsOutput ( ) const
inlinevirtual

Reimplemented from Component.

Definition at line 435 of file nnet-component.h.

435 { return true; }

◆ Copy()

virtual Component* Copy ( ) const
inlinevirtual

Copy component (deep copy).

Implements Component.

Definition at line 436 of file nnet-component.h.

◆ Info()

std::string Info ( ) const
virtual

Reimplemented from Component.

Definition at line 481 of file nnet-component.cc.

References Component::Type().

481  {
482  std::stringstream stream;
483  stream << Type() << ", input-dim = " << input_dim_
484  << ", output-dim = " << output_dim_;
485  return stream.str();
486 }
virtual std::string Type() const

◆ Init()

void Init ( int32  input_dim,
int32  output_dim 
)

Definition at line 419 of file nnet-component.cc.

References KALDI_ASSERT.

419  {
420  input_dim_ = input_dim;
421  output_dim_ = output_dim;
422  if (input_dim_ == 0)
423  input_dim_ = 10 * output_dim_; // default group size : 10
424  KALDI_ASSERT(input_dim_ > 0 && output_dim_ >= 0);
426 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ InitFromString()

void InitFromString ( std::string  args)
virtual

Initialize, typically from a line of a config file.

The "args" will contain any parameters that need to be passed to the Component, e.g. dimensions.

Implements Component.

Definition at line 428 of file nnet-component.cc.

References NonlinearComponent::Init(), KALDI_ERR, KALDI_LOG, kaldi::nnet2::ParseFromString(), and Component::Type().

Referenced by kaldi::nnet2::UnitTestMaxoutComponent().

428  {
429  std::string orig_args(args);
430  int32 input_dim = 0;
431  int32 output_dim = 0;
432  bool ok = ParseFromString("output-dim", &args, &output_dim) &&
433  ParseFromString("input-dim", &args, &input_dim);
434  KALDI_LOG << output_dim << " " << input_dim << " " << ok;
435  if (!ok || !args.empty() || output_dim <= 0)
436  KALDI_ERR << "Invalid initializer for layer of type "
437  << Type() << ": \"" << orig_args << "\"";
438  Init(input_dim, output_dim);
439 }
kaldi::int32 int32
virtual std::string Type() const
bool ParseFromString(const std::string &name, std::string *string, int32 *param)
Functions used in Init routines.
#define KALDI_ERR
Definition: kaldi-error.h:147
void Init(int32 input_dim, int32 output_dim)
#define KALDI_LOG
Definition: kaldi-error.h:153

◆ InputDim()

virtual int32 InputDim ( ) const
inlinevirtual

Get size of input vectors.

Implements Component.

Definition at line 420 of file nnet-component.h.

◆ OutputDim()

virtual int32 OutputDim ( ) const
inlinevirtual

Get size of output vectors.

Implements Component.

Definition at line 421 of file nnet-component.h.

References Component::Propagate().

◆ Propagate()

void Propagate ( const ChunkInfo in_info,
const ChunkInfo out_info,
const CuMatrixBase< BaseFloat > &  in,
CuMatrixBase< BaseFloat > *  out 
) const
virtual

Perform forward pass propagation Input->Output.

Each row is one frame or training example. Interpreted as "num_chunks" equally sized chunks of frames; this only matters for layers that do things like context splicing. Typically this variable will either be 1 (when we're processing a single contiguous chunk of data) or will be the same as in.NumFrames(), but other values are possible if some layers do splicing.

Implements Component.

Definition at line 442 of file nnet-component.cc.

References ChunkInfo::CheckSize(), CuMatrixBase< Real >::GroupMax(), KALDI_ASSERT, and ChunkInfo::NumChunks().

445  {
446  in_info.CheckSize(in);
447  out_info.CheckSize(*out);
448  KALDI_ASSERT(in_info.NumChunks() == out_info.NumChunks());
449  out->GroupMax(in);
450 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ Read()

void Read ( std::istream &  is,
bool  binary 
)
virtual

Implements Component.

Definition at line 464 of file nnet-component.cc.

References kaldi::nnet2::ExpectOneOrTwoTokens(), kaldi::ExpectToken(), and kaldi::ReadBasicType().

464  {
465  ExpectOneOrTwoTokens(is, binary, "<MaxoutComponent>", "<InputDim>");
466  ReadBasicType(is, binary, &input_dim_);
467  ExpectToken(is, binary, "<OutputDim>");
468  ReadBasicType(is, binary, &output_dim_);
469  ExpectToken(is, binary, "</MaxoutComponent>");
470 }
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...
Definition: io-funcs-inl.h:55
void ExpectToken(std::istream &is, bool binary, const char *token)
ExpectToken tries to read in the given token, and throws an exception on failure. ...
Definition: io-funcs.cc:191
static void ExpectOneOrTwoTokens(std::istream &is, bool binary, const std::string &token1, const std::string &token2)

◆ Type()

virtual std::string Type ( ) const
inlinevirtual

Implements Component.

Definition at line 418 of file nnet-component.h.

418 { return "MaxoutComponent"; }

◆ Write()

void Write ( std::ostream &  os,
bool  binary 
) const
virtual

Write component to stream.

Implements Component.

Definition at line 472 of file nnet-component.cc.

References kaldi::WriteBasicType(), and kaldi::WriteToken().

472  {
473  WriteToken(os, binary, "<MaxoutComponent>");
474  WriteToken(os, binary, "<InputDim>");
475  WriteBasicType(os, binary, input_dim_);
476  WriteToken(os, binary, "<OutputDim>");
477  WriteBasicType(os, binary, output_dim_);
478  WriteToken(os, binary, "</MaxoutComponent>");
479 }
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
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...
Definition: io-funcs-inl.h:34

Member Data Documentation

◆ input_dim_

int32 input_dim_
protected

Definition at line 447 of file nnet-component.h.

◆ output_dim_

int32 output_dim_
protected

Definition at line 448 of file nnet-component.h.


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