DiscriminativeSupervision Struct Reference

#include <discriminative-supervision.h>

Collaboration diagram for DiscriminativeSupervision:

Public Member Functions

 DiscriminativeSupervision ()
 
 DiscriminativeSupervision (const DiscriminativeSupervision &other)
 
bool Initialize (const std::vector< int32 > &alignment, const Lattice &lat, BaseFloat weight)
 
void Swap (DiscriminativeSupervision *other)
 
bool operator== (const DiscriminativeSupervision &other) const
 
void Check () const
 
int32 NumFrames () const
 
void Write (std::ostream &os, bool binary) const
 
void Read (std::istream &is, bool binary)
 

Public Attributes

BaseFloat weight
 
int32 num_sequences
 
int32 frames_per_sequence
 
std::vector< int32num_ali
 
Lattice den_lat
 

Detailed Description

Definition at line 75 of file discriminative-supervision.h.

Constructor & Destructor Documentation

◆ DiscriminativeSupervision() [1/2]

◆ DiscriminativeSupervision() [2/2]

Member Function Documentation

◆ Check()

void Check ( ) const

Definition at line 124 of file discriminative-supervision.cc.

References DiscriminativeSupervision::den_lat, DiscriminativeSupervision::frames_per_sequence, KALDI_ASSERT, kaldi::LatticeStateTimes(), DiscriminativeSupervision::num_ali, and DiscriminativeSupervision::num_sequences.

Referenced by DiscriminativeSupervisionSplitter::GetFrameRange(), DiscriminativeSupervision::Initialize(), and kaldi::discriminative::MergeSupervision().

124  {
125  int32 num_frames_subsampled = num_ali.size();
126  KALDI_ASSERT(num_frames_subsampled ==
128 
129  {
130  std::vector<int32> state_times;
131  int32 max_time = LatticeStateTimes(den_lat, &state_times);
132  KALDI_ASSERT(max_time == num_frames_subsampled);
133  }
134 }
int32 LatticeStateTimes(const Lattice &lat, vector< int32 > *times)
This function iterates over the states of a topologically sorted lattice and counts the time instance...
kaldi::int32 int32
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ Initialize()

bool Initialize ( const std::vector< int32 > &  alignment,
const Lattice lat,
BaseFloat  weight 
)

Definition at line 105 of file discriminative-supervision.cc.

References DiscriminativeSupervision::Check(), DiscriminativeSupervision::den_lat, DiscriminativeSupervision::frames_per_sequence, KALDI_ASSERT, DiscriminativeSupervision::num_ali, DiscriminativeSupervision::num_sequences, and DiscriminativeSupervision::weight.

Referenced by main().

107  {
108  if (num_ali.size() == 0) return false;
109  if (den_lat.NumStates() == 0) return false;
110 
111  this->weight = weight;
112  this->num_sequences = 1;
113  this->frames_per_sequence = num_ali.size();
114  this->num_ali = num_ali;
115  this->den_lat = den_lat;
116  KALDI_ASSERT(TopSort(&(this->den_lat)));
117 
118  // Checks if num frames in alignment matches lattice
119  Check();
120 
121  return true;
122 }
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ NumFrames()

◆ operator==()

◆ Read()

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

Definition at line 75 of file discriminative-supervision.cc.

References DiscriminativeSupervision::den_lat, kaldi::ExpectToken(), DiscriminativeSupervision::frames_per_sequence, KALDI_ASSERT, KALDI_ERR, DiscriminativeSupervision::num_ali, DiscriminativeSupervision::num_sequences, kaldi::ReadBasicType(), kaldi::ReadIntegerVector(), kaldi::ReadLattice(), and DiscriminativeSupervision::weight.

Referenced by NnetDiscriminativeSupervision::Read().

75  {
76  ExpectToken(is, binary, "<DiscriminativeSupervision>");
77  ExpectToken(is, binary, "<Weight>");
78  ReadBasicType(is, binary, &weight);
79  ExpectToken(is, binary, "<NumSequences>");
80  ReadBasicType(is, binary, &num_sequences);
81  ExpectToken(is, binary, "<FramesPerSeq>");
82  ReadBasicType(is, binary, &frames_per_sequence);
84  num_sequences > 0);
85 
86  ExpectToken(is, binary, "<NumAli>");
87  ReadIntegerVector(is, binary, &num_ali);
88 
89  ExpectToken(is, binary, "<DenLat>");
90  {
91  Lattice *lat = NULL;
92  if (!ReadLattice(is, binary, &lat) || lat == NULL) {
93  // We can't return error status from this function so we
94  // throw an exception.
95  KALDI_ERR << "Error reading Lattice from stream";
96  }
97  den_lat = *lat;
98  delete lat;
99  TopSort(&den_lat);
100  }
101 
102  ExpectToken(is, binary, "</DiscriminativeSupervision>");
103 }
bool ReadLattice(std::istream &is, bool binary, Lattice **lat)
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 ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
Definition: io-funcs-inl.h:232
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
fst::VectorFst< LatticeArc > Lattice
Definition: kaldi-lattice.h:44
#define KALDI_ERR
Definition: kaldi-error.h:147
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185

◆ Swap()

◆ Write()

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

Definition at line 51 of file discriminative-supervision.cc.

References DiscriminativeSupervision::den_lat, DiscriminativeSupervision::frames_per_sequence, KALDI_ASSERT, KALDI_ERR, DiscriminativeSupervision::num_ali, DiscriminativeSupervision::num_sequences, DiscriminativeSupervision::weight, kaldi::WriteBasicType(), kaldi::WriteIntegerVector(), kaldi::WriteLattice(), and kaldi::WriteToken().

Referenced by NnetDiscriminativeSupervision::Write().

51  {
52  WriteToken(os, binary, "<DiscriminativeSupervision>");
53  WriteToken(os, binary, "<Weight>");
54  WriteBasicType(os, binary, weight);
55  WriteToken(os, binary, "<NumSequences>");
56  WriteBasicType(os, binary, num_sequences);
57  WriteToken(os, binary, "<FramesPerSeq>");
60  num_sequences > 0);
61 
62  WriteToken(os, binary, "<NumAli>");
63  WriteIntegerVector(os, binary, num_ali);
64 
65  WriteToken(os, binary, "<DenLat>");
66  if (!WriteLattice(os, binary, den_lat)) {
67  // We can't return error status from this function so we
68  // throw an exception.
69  KALDI_ERR << "Error writing denominator lattice to stream";
70  }
71 
72  WriteToken(os, binary, "</DiscriminativeSupervision>");
73 }
#define KALDI_ERR
Definition: kaldi-error.h:147
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
bool WriteLattice(std::ostream &os, bool binary, const Lattice &t)
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:185
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
Definition: io-funcs-inl.h:198
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

◆ den_lat

◆ frames_per_sequence

◆ num_ali

◆ num_sequences

◆ weight


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