montreal_forced_aligner/transcription/transcriber.py
def evaluate(self):
        """
        Evaluates the transcripts if there are reference transcripts

        Raises
        ------
        :class:`~montreal_forced_aligner.exceptions.KaldiProcessingError`
            If there were any errors in running Kaldi binaries
        """
        self.logger.info("Evaluating transcripts...")
        self._load_transcripts()
        # Sentence-level measures

        correct = 0
        incorrect = 0
        # Word-level measures
        total_edits = 0
        total_length = 0
        issues = {}
        indices = []
        with mp.Pool(self.num_jobs) as pool:
            to_comp = []
            for utterance in self.utterances:
                utt_name = utterance.name
                if not utterance.text:
                    continue
                g = utterance.text.split()
                if not utterance.transcription_text:
                    incorrect += 1
                    total_edits += len(g)
                    total_length += len(g)
                    issues[utt_name] = [g, "", 1]
                    continue

                h = utterance.transcription_text.split()
                if g != h:
                    issues[utt_name] = [g, h]
                    indices.append(utt_name)
                    to_comp.append((g, h))
                else:
                    issues[utt_name] = [g, h, 0]
            gen = pool.starmap(score, to_comp)
            for i, (edits, length) in enumerate(gen):
                issues[indices[i]].append(edits / length)
                if edits == 0:
                    correct += 1
                else:
                    incorrect += 1
                total_edits += edits
                total_length += length
        output_path = os.path.join(self.evaluation_directory, "transcription_evaluation.csv")
        with open(output_path, "w", encoding="utf8") as f:
            f.write("utterance,gold_transcript,hypothesis,WER\n")
            for utt, (g, h, wer) in issues.items():
                self.utterances[utt].word_error_rate = wer
                g = " ".join(g)
                h = " ".join(h)
                f.write(f"{utt},{g},{h},{wer}\n")
        ser = 100 * incorrect / (correct + incorrect)
        wer = 100 * total_edits / total_length
        self.logger.info(f"SER: {ser:.2f}%, WER: {wer:.2f}%")
        return ser, wer

        Evaluates the transcripts if there are reference transcripts

        Raises
        ------
        :class:`~montreal_forced_aligner.exceptions.KaldiProcessingError`
            If there were any errors in running Kaldi binaries
        
Evaluates the transcripts if there are reference transcripts
Raises
Evaluates the transcripts if there are reference transcripts Raises
def evaluate(self):
        self.logger.info("Evaluating transcripts...")
        self._load_transcripts()
        correct = 0
        incorrect = 0
        total_edits = 0
        total_length = 0
        issues = {}
        indices = []
        with mp.Pool(self.num_jobs) as pool:
            to_comp = []
            for utterance in self.utterances:
                utt_name = utterance.name
                if not utterance.text:
                    continue
                g = utterance.text.split()
                if not utterance.transcription_text:
                    incorrect += 1
                    total_edits += len(g)
                    total_length += len(g)
                    issues[utt_name] = [g, "", 1]
                    continue
                h = utterance.transcription_text.split()
                if g != h:
                    issues[utt_name] = [g, h]
                    indices.append(utt_name)
                    to_comp.append((g, h))
                else:
                    issues[utt_name] = [g, h, 0]
            gen = pool.starmap(score, to_comp)
            for i, (edits, length) in enumerate(gen):
                issues[indices[i]].append(edits / length)
                if edits == 0:
                    correct += 1
                else:
                    incorrect += 1
                total_edits += edits
                total_length += length
        output_path = os.path.join(self.evaluation_directory, "transcription_evaluation.csv")
        with open(output_path, "w", encoding="utf8") as f:
            f.write("utterance,gold_transcript,hypothesis,WER\n")
            for utt, (g, h, wer) in issues.items():
                self.utterances[utt].word_error_rate = wer
                g = " ".join(g)
                h = " ".join(h)
                f.write(f"{utt},{g},{h},{wer}\n")
        ser = 100 * incorrect / (correct + incorrect)
        wer = 100 * total_edits / total_length
        self.logger.info(f"SER: {ser:.2f}%, WER: {wer:.2f}%")
        return ser, wer
def evaluate ( self ) : self . logger . info ( "Evaluating transcripts..." ) self . _load_transcripts ( ) correct = 0 incorrect = 0 total_edits = 0 total_length = 0 issues = { } indices = [ ] with mp . Pool ( self . num_jobs ) as pool : to_comp = [ ] for utterance in self . utterances : utt_name = utterance . name if not utterance . text : continue g = utterance . text . split ( ) if not utterance . transcription_text : incorrect += 1 total_edits += len ( g ) total_length += len ( g ) issues [ utt_name ] = [ g , "" , 1 ] continue h = utterance . transcription_text . split ( ) if g != h : issues [ utt_name ] = [ g , h ] indices . append ( utt_name ) to_comp . append ( ( g , h ) ) else : issues [ utt_name ] = [ g , h , 0 ] gen = pool . starmap ( score , to_comp ) for i , ( edits , length ) in enumerate ( gen ) : issues [ indices [ i ] ] . append ( edits / length ) if edits == 0 : correct += 1 else : incorrect += 1 total_edits += edits total_length += length output_path = os . path . join ( self . evaluation_directory , "transcription_evaluation.csv" ) with open ( output_path , "w" , encoding = "utf8" ) as f : f . write ( "utterance,gold_transcript,hypothesis,WER\n" ) for utt , ( g , h , wer ) in issues . items ( ) : self . utterances [ utt ] . word_error_rate = wer g = " " . join ( g ) h = " " . join ( h ) f . write ( f"{utt},{g},{h},{wer}\n" ) ser = 100 * incorrect / ( correct + incorrect ) wer = 100 * total_edits / total_length self . logger . info ( f"SER: {ser:.2f}%, WER: {wer:.2f}%" ) return ser , wer
Evaluates the transcripts if there are reference transcripts
Raises
Evaluates the transcripts if there are reference transcripts Raises
"""
        Evaluates the transcripts if there are reference transcripts

        Raises
        ------
        :class:`~montreal_forced_aligner.exceptions.KaldiProcessingError`
            If there were any errors in running Kaldi binaries
        """ # Sentence-level measures # Word-level measures
self
class
`~montreal_forced_aligner.exceptions.KaldiProcessingError`
If there were any errors in running Kaldi binaries
` ~montreal_forced_aligner . exceptions . KaldiProcessingError ` If there were any errors in running Kaldi binaries