-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Same continuous phonemes are aggregated when computing gop features via compute-gop #4919
Open
a2d8a4v
wants to merge
10
commits into
kaldi-asr:master
Choose a base branch
from
a2d8a4v:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ae89665
Missing hyphen in --config option
a2d8a4v 32e4b9a
Merge branch 'kaldi-asr:master' into master
a2d8a4v 3373c6a
fix bug in compute-gop.cc
a2d8a4v 7c1c5e6
Update run.sh due to the changes in comput-gop.cc
a2d8a4v 768a23e
Correct the last commit of compute-gop.cc
a2d8a4v 0e61da9
Update README.md
a2d8a4v bef8132
Merge branch 'kaldi-asr:master' into master
a2d8a4v b8c3db9
Merge branch 'kaldi-asr:master' into master
a2d8a4v dc1ce30
Merge branch 'kaldi-asr:master' into master
a2d8a4v 6c74b9a
Merge branch 'kaldi-asr:master' into master
a2d8a4v File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// bin/compute-gop.cc | ||
|
||
// Copyright 2019 Junbo Zhang | ||
// 2024 Jiun-Ting Li (National Taiwan Normal University) | ||
|
||
// See ../../COPYING for clarification regarding multiple authors | ||
// | ||
|
@@ -107,7 +108,9 @@ int main(int argc, char *argv[]) { | |
const char *usage = | ||
"Compute Goodness Of Pronunciation (GOP) from a matrix of " | ||
"probabilities (e.g. from nnet3-compute).\n" | ||
"Usage: compute-gop [options] <model> <alignments-rspecifier> " | ||
"Usage: compute-gop [options] <model> " | ||
"<transition-alignments-respecifier> " | ||
"<phoneme-alignments-rspecifier> " | ||
"<prob-matrix-rspecifier> <gop-wspecifier> " | ||
"[<phone-feature-wspecifier>]\n" | ||
"e.g.:\n" | ||
|
@@ -130,16 +133,17 @@ int main(int argc, char *argv[]) { | |
|
||
po.Read(argc, argv); | ||
|
||
if (po.NumArgs() != 4 && po.NumArgs() != 5) { | ||
if (po.NumArgs() != 6) { | ||
po.PrintUsage(); | ||
exit(1); | ||
} | ||
|
||
std::string model_filename = po.GetArg(1), | ||
alignments_rspecifier = po.GetArg(2), | ||
prob_rspecifier = po.GetArg(3), | ||
gop_wspecifier = po.GetArg(4), | ||
feat_wspecifier = po.GetArg(5); | ||
transition_alignments_rspecifier = po.GetArg(2), | ||
phoneme_alignments_rspecifier = po.GetArg(3), | ||
prob_rspecifier = po.GetArg(4), | ||
gop_wspecifier = po.GetArg(5), | ||
feat_wspecifier = po.GetArg(6); | ||
|
||
TransitionModel trans_model; | ||
{ | ||
|
@@ -174,33 +178,50 @@ int main(int argc, char *argv[]) { | |
} | ||
} | ||
|
||
RandomAccessInt32VectorReader alignment_reader(alignments_rspecifier); | ||
RandomAccessInt32VectorReader phoneme_alignments_reader(phoneme_alignments_rspecifier); | ||
RandomAccessInt32VectorReader transition_alignments_reader(transition_alignments_rspecifier); | ||
SequentialBaseFloatMatrixReader prob_reader(prob_rspecifier); | ||
PosteriorWriter gop_writer(gop_wspecifier); | ||
BaseFloatVectorWriter feat_writer(feat_wspecifier); | ||
|
||
int32 num_done = 0; | ||
for (; !prob_reader.Done(); prob_reader.Next()) { | ||
std::string key = prob_reader.Key(); | ||
if (!alignment_reader.HasKey(key)) { | ||
KALDI_WARN << "No alignment for utterance " << key; | ||
if (!phoneme_alignments_reader.HasKey(key)) { | ||
KALDI_WARN << "No phoneme alignment for utterance " << key; | ||
continue; | ||
} | ||
auto alignment = alignment_reader.Value(key); | ||
if (!transition_alignments_reader.HasKey(key)) { | ||
KALDI_WARN << "No transition alignment for utterance " << key; | ||
continue; | ||
} | ||
auto phoneme_alignment = phoneme_alignments_reader.Value(key); | ||
auto transition_alignment = transition_alignments_reader.Value(key); | ||
Matrix<BaseFloat> &probs = prob_reader.Value(); | ||
if (log_applied) probs.ApplyExp(); | ||
|
||
std::vector<std::vector<int32> > split; | ||
SplitToPhones(trans_model, transition_alignment, &split); | ||
|
||
std::vector<int32> phone_boundary; | ||
for (int32 i = 0; i < split.size(); i++) { | ||
for (int32 j = 0; j < split[i].size(); j++) { | ||
phone_boundary.push_back(static_cast<int32>(i)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I got it. I will remove 'static_cast' |
||
} | ||
} | ||
|
||
Matrix<BaseFloat> lpps; | ||
ComputeLpps(probs, pdf2phones, &lpps); | ||
|
||
int32 frame_num = alignment.size(); | ||
if (alignment.size() != probs.NumRows()) { | ||
int32 frame_num = phoneme_alignment.size(); | ||
if (phoneme_alignment.size() != probs.NumRows()) { | ||
KALDI_WARN << "The frame numbers of alignment and prob are not equal."; | ||
if (frame_num > probs.NumRows()) frame_num = probs.NumRows(); | ||
} | ||
|
||
KALDI_ASSERT(frame_num > 0); | ||
int32 cur_phone_id = alignment[0]; | ||
int32 cur_phone_id = phoneme_alignment[0]; | ||
int32 cur_phone_pos = phone_boundary[0]; | ||
int32 duration = 0; | ||
Vector<BaseFloat> phone_level_feat(1 + phone_num * 2); // [phone LPPs LPRs] | ||
SubVector<BaseFloat> lpp_part(phone_level_feat, 1, phone_num); | ||
|
@@ -220,8 +241,9 @@ int main(int argc, char *argv[]) { | |
lpp_part.AddVec(1, frame_level_lpp); | ||
duration++; | ||
|
||
int32 next_phone_id = (i < frame_num - 1) ? alignment[i + 1]: -1; | ||
if (next_phone_id != cur_phone_id) { | ||
int32 next_phone_id = (i < frame_num - 1) ? phoneme_alignment[i + 1]: -1; | ||
int32 next_phone_pos = (i < frame_num - 1) ? phone_boundary[i + 1]: -1; | ||
if (next_phone_pos != cur_phone_pos) { | ||
int32 phone_id = phone_map.empty() ? cur_phone_id : phone_map[cur_phone_id]; | ||
|
||
// The current phone's feature have been ready | ||
|
@@ -248,6 +270,7 @@ int main(int argc, char *argv[]) { | |
duration = 0; | ||
} | ||
cur_phone_id = next_phone_id; | ||
cur_phone_pos = next_phone_pos; | ||
} | ||
|
||
// Write GOPs and the GOP-based features | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is problematic.
The help message at line 111 says it takes 5 required positional arguments and 1 optional one. So 5 is also a valid value. But this line requires that the number of arguments has to be exactly 6.
I am wondering how you have tested the changes.
[<phone-feature-wspecifier>]
the[]
means it is optional.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reviewing my code. I got it, thank you for your explanation, I fix this condition latter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized it is a problem with the original code.
I think the
[]
in[<phone-feature-wspecifier>]
can be removed. The code does actually need it as a required argument.