NnetDiscriminativeSupervision Struct Reference

#include <nnet-discriminative-example.h>

Collaboration diagram for NnetDiscriminativeSupervision:

Public Member Functions

 NnetDiscriminativeSupervision ()
 
 NnetDiscriminativeSupervision (const std::string &name, const discriminative::DiscriminativeSupervision &supervision, const VectorBase< BaseFloat > &deriv_weights, int32 first_frame, int32 frame_skip)
 
 NnetDiscriminativeSupervision (const NnetDiscriminativeSupervision &other)
 
void Write (std::ostream &os, bool binary) const
 
void Read (std::istream &is, bool binary)
 
void Swap (NnetDiscriminativeSupervision *other)
 
void CheckDim () const
 
bool operator== (const NnetDiscriminativeSupervision &other) const
 

Public Attributes

std::string name
 
std::vector< Indexindexes
 
discriminative::DiscriminativeSupervision supervision
 
Vector< BaseFloatderiv_weights
 

Detailed Description

Definition at line 42 of file nnet-discriminative-example.h.

Constructor & Destructor Documentation

◆ NnetDiscriminativeSupervision() [1/3]

◆ NnetDiscriminativeSupervision() [2/3]

NnetDiscriminativeSupervision ( const std::string &  name,
const discriminative::DiscriminativeSupervision supervision,
const VectorBase< BaseFloat > &  deriv_weights,
int32  first_frame,
int32  frame_skip 
)

Definition at line 91 of file nnet-discriminative-example.cc.

References NnetDiscriminativeSupervision::CheckDim(), DiscriminativeSupervision::frames_per_sequence, rnnlm::i, NnetDiscriminativeSupervision::indexes, rnnlm::j, KALDI_ASSERT, and DiscriminativeSupervision::num_sequences.

96  :
97  name(name),
100  // note: this will set the 'x' index to zero.
103  int32 k = 0, num_sequences = supervision.num_sequences,
104  frames_per_sequence = supervision.frames_per_sequence;
105  for (int32 i = 0; i < frames_per_sequence; i++) {
106  for (int32 j = 0; j < num_sequences; j++,k++) {
107  indexes[k].n = j;
108  indexes[k].t = i * frame_skip + first_frame;
109  }
110  }
111  KALDI_ASSERT(k == indexes.size());
112  CheckDim();
113 }
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
discriminative::DiscriminativeSupervision supervision

◆ NnetDiscriminativeSupervision() [3/3]

Member Function Documentation

◆ CheckDim()

void CheckDim ( ) const

Definition at line 57 of file nnet-discriminative-example.cc.

References NnetDiscriminativeSupervision::deriv_weights, DiscriminativeSupervision::frames_per_sequence, rnnlm::i, NnetDiscriminativeSupervision::indexes, rnnlm::j, KALDI_ASSERT, rnnlm::n, DiscriminativeSupervision::num_sequences, and NnetDiscriminativeSupervision::supervision.

Referenced by kaldi::nnet3::MergeSupervision(), NnetDiscriminativeSupervision::NnetDiscriminativeSupervision(), NnetDiscriminativeSupervision::Read(), NnetDiscriminativeSupervision::Swap(), and NnetDiscriminativeSupervision::Write().

57  {
58  if (supervision.frames_per_sequence == -1) {
59  // this object has not been set up.
60  KALDI_ASSERT(indexes.empty());
61  return;
62  }
66  int32 first_frame = indexes[0].t,
67  frame_skip = indexes[supervision.num_sequences].t - first_frame,
68  num_sequences = supervision.num_sequences,
69  frames_per_sequence = supervision.frames_per_sequence;
70  int32 k = 0;
71  for (int32 i = 0; i < frames_per_sequence; i++) {
72  for (int32 j = 0; j < num_sequences; j++,k++) {
73  int32 n = j, t = i * frame_skip + first_frame, x = 0;
74  Index index(n, t, x);
75  KALDI_ASSERT(indexes[k] == index);
76  }
77  }
78  if (deriv_weights.Dim() != 0) {
79  KALDI_ASSERT(deriv_weights.Dim() == indexes.size());
80  KALDI_ASSERT(deriv_weights.Min() >= 0.0 &&
81  deriv_weights.Max() <= 1.0);
82  }
83 }
kaldi::int32 int32
struct rnnlm::@11::@12 n
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
discriminative::DiscriminativeSupervision supervision

◆ operator==()

◆ Read()

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

Definition at line 45 of file nnet-discriminative-example.cc.

References NnetDiscriminativeSupervision::CheckDim(), NnetDiscriminativeSupervision::deriv_weights, kaldi::nnet3::ExpectToken(), NnetDiscriminativeSupervision::indexes, NnetDiscriminativeSupervision::name, DiscriminativeSupervision::Read(), kaldi::nnet3::ReadIndexVector(), kaldi::ReadToken(), kaldi::nnet3::ReadVectorAsChar(), and NnetDiscriminativeSupervision::supervision.

Referenced by NnetDiscriminativeSupervision::NnetDiscriminativeSupervision(), and NnetDiscriminativeExample::Read().

45  {
46  ExpectToken(is, binary, "<NnetDiscriminativeSup>");
47  ReadToken(is, binary, &name);
48  ReadIndexVector(is, binary, &indexes);
49  supervision.Read(is, binary);
50  ExpectToken(is, binary, "<DW>");
51  ReadVectorAsChar(is, binary, &deriv_weights);
52  ExpectToken(is, binary, "</NnetDiscriminativeSup>");
53  CheckDim();
54 }
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
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
void ReadIndexVector(std::istream &is, bool binary, std::vector< Index > *vec)
Definition: nnet-common.cc:143
void ReadVectorAsChar(std::istream &is, bool binary, Vector< BaseFloat > *vec)
discriminative::DiscriminativeSupervision supervision

◆ Swap()

void Swap ( NnetDiscriminativeSupervision other)

Definition at line 115 of file nnet-discriminative-example.cc.

References NnetDiscriminativeSupervision::CheckDim(), NnetDiscriminativeSupervision::deriv_weights, NnetDiscriminativeSupervision::indexes, NnetDiscriminativeSupervision::name, kaldi::RandInt(), NnetDiscriminativeSupervision::supervision, and DiscriminativeSupervision::Swap().

Referenced by NnetDiscriminativeSupervision::NnetDiscriminativeSupervision().

115  {
116  name.swap(other->name);
117  indexes.swap(other->indexes);
118  supervision.Swap(&(other->supervision));
119  deriv_weights.Swap(&(other->deriv_weights));
120  if (RandInt(0, 5) == 0)
121  CheckDim();
122 }
discriminative::DiscriminativeSupervision supervision
int32 RandInt(int32 min_val, int32 max_val, struct RandomState *state)
Definition: kaldi-math.cc:95

◆ Write()

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

Definition at line 28 of file nnet-discriminative-example.cc.

References NnetDiscriminativeSupervision::CheckDim(), NnetDiscriminativeSupervision::deriv_weights, NnetDiscriminativeSupervision::indexes, NnetDiscriminativeSupervision::name, NnetDiscriminativeSupervision::supervision, DiscriminativeSupervision::Write(), kaldi::nnet3::WriteIndexVector(), kaldi::WriteToken(), and kaldi::nnet3::WriteVectorAsChar().

Referenced by NnetDiscriminativeSupervision::NnetDiscriminativeSupervision().

28  {
29  CheckDim();
30  WriteToken(os, binary, "<NnetDiscriminativeSup>");
31  WriteToken(os, binary, name);
32  WriteIndexVector(os, binary, indexes);
33  supervision.Write(os, binary);
34  WriteToken(os, binary, "<DW>"); // for DerivWeights. Want to save space.
35  WriteVectorAsChar(os, binary, deriv_weights);
36  WriteToken(os, binary, "</NnetDiscriminativeSup>");
37 }
void WriteIndexVector(std::ostream &os, bool binary, const std::vector< Index > &vec)
Definition: nnet-common.cc:126
void Write(std::ostream &os, bool binary) const
void WriteVectorAsChar(std::ostream &os, bool binary, const VectorBase< BaseFloat > &vec)
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
discriminative::DiscriminativeSupervision supervision

Member Data Documentation

◆ deriv_weights

◆ indexes

◆ name

◆ supervision


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