NnetExample Struct Reference

NnetExample is the input data and corresponding label (or labels) for one or more frames of input, used for standard cross-entropy training of neural nets (and possibly for other objective functions). More...

#include <nnet-example.h>

Collaboration diagram for NnetExample:

Public Member Functions

void Write (std::ostream &os, bool binary) const
 
void Read (std::istream &is, bool binary)
 
 NnetExample ()
 
 NnetExample (const NnetExample &other)
 
void Swap (NnetExample *other)
 
void Compress ()
 Compresses any (input) features that are not sparse. More...
 
bool operator== (const NnetExample &other) const
 Caution: this operator == is not very efficient. More...
 

Public Attributes

std::vector< NnetIoio
 "io" contains the input and output. More...
 

Detailed Description

NnetExample is the input data and corresponding label (or labels) for one or more frames of input, used for standard cross-entropy training of neural nets (and possibly for other objective functions).

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

Constructor & Destructor Documentation

◆ NnetExample() [1/2]

NnetExample ( )
inline

Definition at line 121 of file nnet-example.h.

121 { }

◆ NnetExample() [2/2]

NnetExample ( const NnetExample other)
inline

Definition at line 123 of file nnet-example.h.

123 : io(other.io) { }
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116

Member Function Documentation

◆ Compress()

void Compress ( )

Compresses any (input) features that are not sparse.

Definition at line 130 of file nnet-example.cc.

Referenced by kaldi::nnet3::ProcessFile(), and kaldi::nnet3::WriteExamples().

130  {
131  std::vector<NnetIo>::iterator iter = io.begin(), end = io.end();
132  // calling features.Compress() will do nothing if they are sparse or already
133  // compressed.
134  for (; iter != end; ++iter)
135  iter->features.Compress();
136 }
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116

◆ operator==()

bool operator== ( const NnetExample other) const
inline

Caution: this operator == is not very efficient.

It's only used in testing code.

Definition at line 132 of file nnet-example.h.

References NnetExample::io.

132 { return io == other.io; }
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116

◆ Read()

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

Definition at line 116 of file nnet-example.cc.

References kaldi::nnet3::ExpectToken(), rnnlm::i, KALDI_ERR, NnetIo::Read(), and kaldi::ReadBasicType().

Referenced by kaldi::nnet3::UnitTestNnetExample().

116  {
117  ExpectToken(is, binary, "<Nnet3Eg>");
118  ExpectToken(is, binary, "<NumIo>");
119  int32 size;
120  ReadBasicType(is, binary, &size);
121  if (size <= 0 || size > 1000000)
122  KALDI_ERR << "Invalid size " << size;
123  io.resize(size);
124  for (int32 i = 0; i < size; i++)
125  io[i].Read(is, binary);
126  ExpectToken(is, binary, "</Nnet3Eg>");
127 }
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
kaldi::int32 int32
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
#define KALDI_ERR
Definition: kaldi-error.h:147
void Read(std::istream &is, bool binary)
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116

◆ Swap()

void Swap ( NnetExample other)
inline

Definition at line 125 of file nnet-example.h.

References NnetExample::io.

125 { io.swap(other->io); }
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116

◆ Write()

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

Definition at line 103 of file nnet-example.cc.

References rnnlm::i, KALDI_ASSERT, NnetIo::Write(), kaldi::WriteBasicType(), and kaldi::WriteToken().

Referenced by kaldi::nnet3::UnitTestNnetExample(), and kaldi::nnet3::UnitTestNnetMergeExamples().

103  {
104  // Note: weight, label, input_frames and spk_info are members. This is a
105  // struct.
106  WriteToken(os, binary, "<Nnet3Eg>");
107  WriteToken(os, binary, "<NumIo>");
108  int32 size = io.size();
109  KALDI_ASSERT(size > 0 && "Writing empty nnet example");
110  WriteBasicType(os, binary, size);
111  for (int32 i = 0; i < size; i++)
112  io[i].Write(os, binary);
113  WriteToken(os, binary, "</Nnet3Eg>");
114 }
kaldi::int32 int32
void Write(std::ostream &os, bool binary) const
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
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
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
std::vector< NnetIo > io
"io" contains the input and output.
Definition: nnet-example.h:116

Member Data Documentation

◆ io


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