Skip to content
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

Extract framewise alignment information using CTC decoding #39

Merged
merged 17 commits into from
Oct 18, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'dan/master' into ctc-ali
csukuangfj committed Sep 23, 2021
commit 4580ff10df946eb9046eb1d870bcf7fb6ab0cf97
30 changes: 3 additions & 27 deletions icefall/decode.py
Original file line number Diff line number Diff line change
@@ -881,33 +881,9 @@ def rescore_with_attention_decoder(
+ n_scale * ngram_lm_scores.values
+ a_scale * attention_scores
)
ragged_tot_scores = k2.RaggedTensor(seq_to_path_shape, tot_scores)
argmax_indexes = ragged_tot_scores.argmax()

best_path_indexes = k2.index_select(new2old, argmax_indexes)

# best_path is a k2.RaggedTensor with 2 axes [path][arc_pos]
best_path, _ = path_2axes.index(
indexes=best_path_indexes, axis=0, need_value_indexes=False
)

# labels is a k2.RaggedTensor with 2 axes [path][token_id]
# Note that it contains -1s.
labels = k2.ragged.index(lattice.labels.contiguous(), best_path)

labels = labels.remove_values_eq(-1)

if isinstance(lattice.aux_labels, torch.Tensor):
aux_labels = k2.index_select(
lattice.aux_labels, best_path.values
)
else:
aux_labels, _ = lattice.aux_labels.index(
indexes=best_path.values, axis=0, need_value_indexes=False
)

best_path_fsa = k2.linear_fsa(labels)
best_path_fsa.aux_labels = aux_labels
ragged_tot_scores = k2.RaggedTensor(nbest.shape, tot_scores)
max_indexes = ragged_tot_scores.argmax()
best_path = k2.index_fsa(nbest.fsa, max_indexes)

key = f"ngram_lm_scale_{n_scale}_attention_scale_{a_scale}"
ans[key] = best_path
12 changes: 12 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -114,6 +114,18 @@ def test_attribute_dict():
s.c = 100
assert s["c"] == 100

assert hasattr(s, "a")
assert hasattr(s, "b")
assert getattr(s, "a") == 10
del s.a
assert hasattr(s, "a") is False
setattr(s, "c", 100)
s.c = 100
try:
del s.a
except AttributeError as ex:
print(f"Caught exception: {ex}")


def test_get_env_info():
s = get_env_info()
You are viewing a condensed version of this merge commit. You can view the full changes here.