montreal_forced_aligner/transcription/transcriber.py
def create_decoding_graph(self) -> None:
        """
        Create decoding graph for use in transcription

        Raises
        ------
        :class:`~montreal_forced_aligner.exceptions.KaldiProcessingError`
            If there were any errors in running Kaldi binaries
        """
        done_path = os.path.join(self.model_directory, "done")
        if os.path.exists(done_path):
            self.logger.info("Graph construction already done, skipping!")
        log_dir = os.path.join(self.model_directory, "log")
        os.makedirs(log_dir, exist_ok=True)
        self.write_lexicon_information(write_disambiguation=True)
        for dict_name, dictionary in self.dictionary_mapping.items():
            words_path = os.path.join(self.model_directory, f"words.{dict_name}.txt")
            shutil.copyfile(dictionary.words_symbol_path, words_path)

        big_arpa_path = self.language_model.carpa_path
        small_arpa_path = self.language_model.small_arpa_path
        medium_arpa_path = self.language_model.medium_arpa_path
        if not os.path.exists(small_arpa_path) or not os.path.exists(medium_arpa_path):
            self.logger.warning(
                "Creating small and medium language models from scratch, this may take some time. "
                "Running `mfa train_lm` on the ARPA file will remove this warning."
            )
            if sys.platform == "win32":
                raise PlatformError("ngram")
            self.logger.info("Parsing large ngram model...")
            mod_path = os.path.join(self.model_directory, "base_lm.mod")
            new_carpa_path = os.path.join(self.model_directory, "base_lm.arpa")
            with open(big_arpa_path, "r", encoding="utf8") as inf, open(
                new_carpa_path, "w", encoding="utf8"
            ) as outf:
                for line in inf:
                    outf.write(line.lower())
            big_arpa_path = new_carpa_path
            subprocess.call(["ngramread", "--ARPA", big_arpa_path, mod_path])

            if not os.path.exists(small_arpa_path):
                self.logger.info(
                    "Generating small model from the large ARPA with a pruning threshold of 3e-7"
                )
                prune_thresh_small = 0.0000003
                small_mod_path = mod_path.replace(".mod", "_small.mod")
                subprocess.call(
                    [
                        "ngramshrink",
                        "--method=relative_entropy",
                        f"--theta={prune_thresh_small}",
                        mod_path,
                        small_mod_path,
                    ]
                )
                subprocess.call(["ngramprint", "--ARPA", small_mod_path, small_arpa_path])

            if not os.path.exists(medium_arpa_path):
                self.logger.info(
                    "Generating medium model from the large ARPA with a pruning threshold of 1e-7"
                )
                prune_thresh_medium = 0.0000001
                med_mod_path = mod_path.replace(".mod", "_med.mod")
                subprocess.call(
                    [
                        "ngramshrink",
                        "--method=relative_entropy",
                        f"--theta={prune_thresh_medium}",
                        mod_path,
                        med_mod_path,
                    ]
                )
                subprocess.call(["ngramprint", "--ARPA", med_mod_path, medium_arpa_path])
        try:
            self.create_hclgs()
        except Exception as e:
            dirty_path = os.path.join(self.model_directory, "dirty")
            with open(dirty_path, "w"):
                pass
            if isinstance(e, KaldiProcessingError):
                log_kaldi_errors(e.error_logs, self.logger)
                e.update_log_file(self.logger)
            raise

        Create decoding graph for use in transcription

        Raises
        ------
        :class:`~montreal_forced_aligner.exceptions.KaldiProcessingError`
            If there were any errors in running Kaldi binaries
        
Create decoding graph for use in transcription
Raises
Create decoding graph for use in transcription Raises
def create_decoding_graph(self) -> None:
        done_path = os.path.join(self.model_directory, "done")
        if os.path.exists(done_path):
            self.logger.info("Graph construction already done, skipping!")
        log_dir = os.path.join(self.model_directory, "log")
        os.makedirs(log_dir, exist_ok=True)
        self.write_lexicon_information(write_disambiguation=True)
        for dict_name, dictionary in self.dictionary_mapping.items():
            words_path = os.path.join(self.model_directory, f"words.{dict_name}.txt")
            shutil.copyfile(dictionary.words_symbol_path, words_path)
        big_arpa_path = self.language_model.carpa_path
        small_arpa_path = self.language_model.small_arpa_path
        medium_arpa_path = self.language_model.medium_arpa_path
        if not os.path.exists(small_arpa_path) or not os.path.exists(medium_arpa_path):
            self.logger.warning(
                "Creating small and medium language models from scratch, this may take some time. "
                "Running `mfa train_lm` on the ARPA file will remove this warning."
            )
            if sys.platform == "win32":
                raise PlatformError("ngram")
            self.logger.info("Parsing large ngram model...")
            mod_path = os.path.join(self.model_directory, "base_lm.mod")
            new_carpa_path = os.path.join(self.model_directory, "base_lm.arpa")
            with open(big_arpa_path, "r", encoding="utf8") as inf, open(
                new_carpa_path, "w", encoding="utf8"
            ) as outf:
                for line in inf:
                    outf.write(line.lower())
            big_arpa_path = new_carpa_path
            subprocess.call(["ngramread", "--ARPA", big_arpa_path, mod_path])
            if not os.path.exists(small_arpa_path):
                self.logger.info(
                    "Generating small model from the large ARPA with a pruning threshold of 3e-7"
                )
                prune_thresh_small = 0.0000003
                small_mod_path = mod_path.replace(".mod", "_small.mod")
                subprocess.call(
                    [
                        "ngramshrink",
                        "--method=relative_entropy",
                        f"--theta={prune_thresh_small}",
                        mod_path,
                        small_mod_path,
                    ]
                )
                subprocess.call(["ngramprint", "--ARPA", small_mod_path, small_arpa_path])
            if not os.path.exists(medium_arpa_path):
                self.logger.info(
                    "Generating medium model from the large ARPA with a pruning threshold of 1e-7"
                )
                prune_thresh_medium = 0.0000001
                med_mod_path = mod_path.replace(".mod", "_med.mod")
                subprocess.call(
                    [
                        "ngramshrink",
                        "--method=relative_entropy",
                        f"--theta={prune_thresh_medium}",
                        mod_path,
                        med_mod_path,
                    ]
                )
                subprocess.call(["ngramprint", "--ARPA", med_mod_path, medium_arpa_path])
        try:
            self.create_hclgs()
        except Exception as e:
            dirty_path = os.path.join(self.model_directory, "dirty")
            with open(dirty_path, "w"):
                pass
            if isinstance(e, KaldiProcessingError):
                log_kaldi_errors(e.error_logs, self.logger)
                e.update_log_file(self.logger)
            raise
def create_decoding_graph ( self ) -> None : done_path = os . path . join ( self . model_directory , "done" ) if os . path . exists ( done_path ) : self . logger . info ( "Graph construction already done, skipping!" ) log_dir = os . path . join ( self . model_directory , "log" ) os . makedirs ( log_dir , exist_ok = True ) self . write_lexicon_information ( write_disambiguation = True ) for dict_name , dictionary in self . dictionary_mapping . items ( ) : words_path = os . path . join ( self . model_directory , f"words.{dict_name}.txt" ) shutil . copyfile ( dictionary . words_symbol_path , words_path ) big_arpa_path = self . language_model . carpa_path small_arpa_path = self . language_model . small_arpa_path medium_arpa_path = self . language_model . medium_arpa_path if not os . path . exists ( small_arpa_path ) or not os . path . exists ( medium_arpa_path ) : self . logger . warning ( "Creating small and medium language models from scratch, this may take some time. " "Running `mfa train_lm` on the ARPA file will remove this warning." ) if sys . platform == "win32" : raise PlatformError ( "ngram" ) self . logger . info ( "Parsing large ngram model..." ) mod_path = os . path . join ( self . model_directory , "base_lm.mod" ) new_carpa_path = os . path . join ( self . model_directory , "base_lm.arpa" ) with open ( big_arpa_path , "r" , encoding = "utf8" ) as inf , open ( new_carpa_path , "w" , encoding = "utf8" ) as outf : for line in inf : outf . write ( line . lower ( ) ) big_arpa_path = new_carpa_path subprocess . call ( [ "ngramread" , "--ARPA" , big_arpa_path , mod_path ] ) if not os . path . exists ( small_arpa_path ) : self . logger . info ( "Generating small model from the large ARPA with a pruning threshold of 3e-7" ) prune_thresh_small = 0.0000003 small_mod_path = mod_path . replace ( ".mod" , "_small.mod" ) subprocess . call ( [ "ngramshrink" , "--method=relative_entropy" , f"--theta={prune_thresh_small}" , mod_path , small_mod_path , ] ) subprocess . call ( [ "ngramprint" , "--ARPA" , small_mod_path , small_arpa_path ] ) if not os . path . exists ( medium_arpa_path ) : self . logger . info ( "Generating medium model from the large ARPA with a pruning threshold of 1e-7" ) prune_thresh_medium = 0.0000001 med_mod_path = mod_path . replace ( ".mod" , "_med.mod" ) subprocess . call ( [ "ngramshrink" , "--method=relative_entropy" , f"--theta={prune_thresh_medium}" , mod_path , med_mod_path , ] ) subprocess . call ( [ "ngramprint" , "--ARPA" , med_mod_path , medium_arpa_path ] ) try : self . create_hclgs ( ) except Exception as e : dirty_path = os . path . join ( self . model_directory , "dirty" ) with open ( dirty_path , "w" ) : pass if isinstance ( e , KaldiProcessingError ) : log_kaldi_errors ( e . error_logs , self . logger ) e . update_log_file ( self . logger ) raise
Create decoding graph for use in transcription
Raises
Create decoding graph for use in transcription Raises
"""
        Create decoding graph for use in transcription

        Raises
        ------
        :class:`~montreal_forced_aligner.exceptions.KaldiProcessingError`
            If there were any errors in running Kaldi binaries
        """
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