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

2.0rc3 #393

Merged
merged 4 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
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
Next Next commit
Better WER calculation for compounds and clitics
  • Loading branch information
mmcauliffe committed Jan 16, 2022
commit 3fc59665bddc98e75d6ab3adb20cd7df81f015e3
8 changes: 8 additions & 0 deletions montreal_forced_aligner/dictionary/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ def base_phones(self) -> Dict[str, Set[str]]:

return base_phones

@property
def split_regex(self) -> re.Pattern:
"""Pattern for splitting arbitrary text"""
markers = self.compound_markers
if "-" in markers:
markers = ["-"] + [x for x in self.compound_markers if x != "-"]
return re.compile(rf'[{"".join(markers)} ]')

@property
def extra_questions_mapping(self) -> Dict[str, List[str]]:
"""Mapping of extra questions for the given phone set type"""
Expand Down
18 changes: 16 additions & 2 deletions montreal_forced_aligner/transcription/transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import itertools
import multiprocessing as mp
import os
import re
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -1347,7 +1348,8 @@ def evaluate(self):
utt_name = utterance.name
if not utterance.text:
continue
g = utterance.text.split()

g = self.split_regex.split(utterance.text)

total_count += 1
total_word_length += len(g)
Expand Down Expand Up @@ -1416,6 +1418,12 @@ def evaluate(self):

def _load_transcripts(self):
"""Load transcripts from Kaldi temporary files"""
initial_clitics = {
x for x in self.clitic_set if re.match(rf"^.*[{''.join(self.clitic_markers)}]$", x)
}
final_clitics = {
x for x in self.clitic_set if re.match(rf"^[{''.join(self.clitic_markers)}].*$", x)
}
for score_args in self.score_arguments():
for tra_path in score_args.tra_paths.values():

Expand All @@ -1431,7 +1439,13 @@ def _load_transcripts(self):
continue
transcription = []
for i in ints:
transcription.append(lookup[int(i)])
w = lookup[int(i)]
if len(transcription) and (
w in final_clitics or transcription[-1] in initial_clitics
):
transcription[-1] += w
continue
transcription.append(w)
utterance.transcription_text = " ".join(transcription)

def export_files(self, output_directory: str) -> None:
Expand Down