PR #3279 - replaced tabulations by spaces

This commit is contained in:
godeffroy 2020-08-31 08:53:26 +02:00
parent 04a36fbf68
commit c3d6f8d923
2 changed files with 24 additions and 24 deletions

View File

@ -99,22 +99,22 @@ DecoderState::next(const double *probs,
if (prefix->score == -NUM_FLT_INF) { if (prefix->score == -NUM_FLT_INF) {
continue; continue;
} }
if (!prefix->is_empty() && prefix->timesteps.empty()) { if (!prefix->is_empty() && prefix->timesteps.empty()) {
// This should never happen. But we report it if it does. // This should never happen. But we report it if it does.
std::cerr<<"error: non-empty prefix has empty timestep sequence"<<std::endl; std::cerr<<"error: non-empty prefix has empty timestep sequence"<<std::endl;
continue; continue;
} }
// blank // blank
if (c == blank_id_) { if (c == blank_id_) {
// compute probability of current path // compute probability of current path
float log_p = log_prob_c + prefix->score; float log_p = log_prob_c + prefix->score;
// combine current path with previous ones with the same prefix // combine current path with previous ones with the same prefix
// the blank label comes last, so we can compare log_prob_nb_cur with log_p // the blank label comes last, so we can compare log_prob_nb_cur with log_p
if (prefix->log_prob_nb_cur < log_p) { if (prefix->log_prob_nb_cur < log_p) {
prefix->timesteps_cur = prefix->timesteps; prefix->timesteps_cur = prefix->timesteps;
} }
prefix->log_prob_b_cur = prefix->log_prob_b_cur =
log_sum_exp(prefix->log_prob_b_cur, log_p); log_sum_exp(prefix->log_prob_b_cur, log_p);
continue; continue;
@ -122,10 +122,10 @@ DecoderState::next(const double *probs,
// repeated character // repeated character
if (c == prefix->character) { if (c == prefix->character) {
// compute probability of current path // compute probability of current path
float log_p = log_prob_c + prefix->log_prob_nb_prev; float log_p = log_prob_c + prefix->log_prob_nb_prev;
// combine current path with previous ones with the same prefix // combine current path with previous ones with the same prefix
if (prefix->log_prob_nb_cur < log_p) { if (prefix->log_prob_nb_cur < log_p) {
prefix->timesteps_cur = prefix->timesteps; prefix->timesteps_cur = prefix->timesteps;
} }
@ -137,11 +137,11 @@ DecoderState::next(const double *probs,
auto prefix_new = prefix->get_path_trie(c, log_prob_c); auto prefix_new = prefix->get_path_trie(c, log_prob_c);
if (prefix_new != nullptr) { if (prefix_new != nullptr) {
// compute timesteps of current path // compute timesteps of current path
std::vector<unsigned int> timesteps_new=prefix->timesteps; std::vector<unsigned int> timesteps_new=prefix->timesteps;
timesteps_new.push_back(abs_time_step_); timesteps_new.push_back(abs_time_step_);
// compute probability of current path // compute probability of current path
float log_p = -NUM_FLT_INF; float log_p = -NUM_FLT_INF;
if (c == prefix->character && if (c == prefix->character &&
@ -172,7 +172,7 @@ DecoderState::next(const double *probs,
} }
} }
// combine current path with previous ones with the same prefix // combine current path with previous ones with the same prefix
if (prefix_new->log_prob_nb_cur < log_p) { if (prefix_new->log_prob_nb_cur < log_p) {
prefix_new->timesteps_cur = timesteps_new; prefix_new->timesteps_cur = timesteps_new;
} }
@ -240,10 +240,10 @@ DecoderState::decode(size_t num_results) const
for (PathTrie* prefix : prefixes_copy) { for (PathTrie* prefix : prefixes_copy) {
Output output; Output output;
output.tokens = prefix->get_path_vec(); output.tokens = prefix->get_path_vec();
output.timesteps = prefix->timesteps; output.timesteps = prefix->timesteps;
output.confidence = scores[prefix]; output.confidence = scores[prefix];
outputs.push_back(output); outputs.push_back(output);
if(outputs.size()>=num_returned) break; if(outputs.size()>=num_returned) break;
} }
return outputs; return outputs;

View File

@ -101,11 +101,11 @@ PathTrie* PathTrie::get_path_trie(unsigned int new_char, float cur_log_prob_c, b
std::vector<unsigned int> PathTrie::get_path_vec() { std::vector<unsigned int> PathTrie::get_path_vec() {
if (parent == nullptr) { if (parent == nullptr) {
return std::vector<unsigned int>{}; return std::vector<unsigned int>{};
} }
std::vector<unsigned int> output_tokens=parent->get_path_vec(); std::vector<unsigned int> output_tokens=parent->get_path_vec();
if (character != ROOT_) { if (character != ROOT_) {
output_tokens.push_back(character); output_tokens.push_back(character);
} }
return output_tokens; return output_tokens;
} }
@ -166,8 +166,8 @@ void PathTrie::iterate_to_vec(std::vector<PathTrie*>& output) {
score = log_sum_exp(log_prob_b_prev, log_prob_nb_prev); score = log_sum_exp(log_prob_b_prev, log_prob_nb_prev);
timesteps = std::move(timesteps_cur); timesteps = std::move(timesteps_cur);
timesteps_cur.clear(); timesteps_cur.clear();
output.push_back(this); output.push_back(this);
} }