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

Sourcery refactored main branch #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
25 changes: 9 additions & 16 deletions asr_evaluation/asr_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def main(args):
wer = 0.0
# Compute SER
ser = sent_error_count / counter if counter > 0 else 0.0
print('Sentence count: {}'.format(counter))
print(f'Sentence count: {counter}')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

print('WER: {:10.3%} ({:10d} / {:10d})'.format(wer, error_count, ref_token_count))
print('WRR: {:10.3%} ({:10d} / {:10d})'.format(wrr, match_count, ref_token_count))
print('SER: {:10.3%} ({:10d} / {:10d})'.format(ser, sent_error_count, counter))
Expand Down Expand Up @@ -228,14 +228,12 @@ def track_confusions(sm, seq1, seq2):
"""Keep track of the errors in a global variable, given a sequence matcher."""
opcodes = sm.get_opcodes()
for tag, i1, i2, j1, j2 in opcodes:
if tag == 'insert':
for i in range(j1, j2):
word = seq2[i]
insertion_table[word] += 1
elif tag == 'delete':
if tag == 'delete':
for i in range(i1, i2):
word = seq1[i]
deletion_table[word] += 1
deletion_table[seq1[i]] += 1
elif tag == 'insert':
for i in range(j1, j2):
insertion_table[seq2[i]] += 1
Comment on lines -231 to +236
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function track_confusions refactored with the following changes:

  • Simplify conditional into switch-like form (switch)
  • Inline variable that is only used once (inline-variable)

elif tag == 'replace':
for w1 in seq1[i1:i2]:
for w2 in seq2[j1:j2]:
Expand Down Expand Up @@ -298,8 +296,6 @@ def print_diff(sm, seq1, seq2, prefix1='REF:', prefix2='HYP:', suffix1=None, suf
ref_tokens.append(seq1[i].lower())
for i in range(j1, j2):
hyp_tokens.append(seq2[i].lower())
# For insertions and deletions, put a filler of '***' on the other one, and
# make the other all caps
Comment on lines -301 to -302
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function print_diff refactored with the following changes:

This removes the following comments ( why? ):

# For insertions and deletions, put a filler of '***' on the other one, and
# More complicated logic for a substitution
# make the other all caps

elif tag == 'delete':
for i in range(i1, i2):
ref_token = colored(seq1[i].upper(), 'red')
Expand All @@ -314,7 +310,6 @@ def print_diff(sm, seq1, seq2, prefix1='REF:', prefix2='HYP:', suffix1=None, suf
for i in range(j1, j2):
hyp_token = colored(seq2[i].upper(), 'red')
hyp_tokens.append(hyp_token)
# More complicated logic for a substitution
elif tag == 'replace':
seq1_len = i2 - i1
seq2_len = j2 - j1
Expand All @@ -323,14 +318,12 @@ def print_diff(sm, seq1, seq2, prefix1='REF:', prefix2='HYP:', suffix1=None, suf
s2 = list(map(str.upper, seq2[j1:j2]))
# Pad the two lists with False values to get them to the same length
if seq1_len > seq2_len:
for i in range(0, seq1_len - seq2_len):
s2.append(False)
s2.extend(False for _ in range(seq1_len - seq2_len))
if seq1_len < seq2_len:
for i in range(0, seq2_len - seq1_len):
s1.append(False)
s1.extend(False for _ in range(seq2_len - seq1_len))
assert len(s1) == len(s2)
# Pair up words with their substitutions, or fillers
for i in range(0, len(s1)):
for i in range(len(s1)):
w1 = s1[i]
w2 = s2[i]
# If we have two words, make them the same length
Expand Down