montreal_forced_aligner/language_modeling/trainer.py
def evaluate(self) -> None:
        """
        Run an evaluation over the training data to generate perplexity score
        """
        log_path = os.path.join(self.working_log_directory, "evaluate.log")

        small_mod_path = self.mod_path.replace(".mod", "_small.mod")
        med_mod_path = self.mod_path.replace(".mod", "_med.mod")
        with open(log_path, "w", encoding="utf8") as log_file:
            perplexity_proc = subprocess.Popen(
                [
                    "ngramperplexity",
                    f'--OOV_symbol="{self.oov_word}"',
                    self.mod_path,
                    self.far_path,
                ],
                stdout=subprocess.PIPE,
                stderr=log_file,
                encoding="utf8",
            )
            stdout, stderr = perplexity_proc.communicate()
            num_sentences = None
            num_words = None
            num_oovs = None
            perplexity = None
            for line in stdout.splitlines():
                m = re.search(r"(\d+) sentences", line)
                if m:
                    num_sentences = m.group(0)
                m = re.search(r"(\d+) words", line)
                if m:
                    num_words = m.group(0)
                m = re.search(r"(\d+) OOVs", line)
                if m:
                    num_oovs = m.group(0)
                m = re.search(r"perplexity = ([\d.]+)", line)
                if m:
                    perplexity = m.group(0)

            self.log_info(f"{num_sentences} sentences, {num_words} words, {num_oovs} oovs")
            self.log_info(f"Perplexity of large model: {perplexity}")

            perplexity_proc = subprocess.Popen(
                [
                    "ngramperplexity",
                    f'--OOV_symbol="{self.oov_word}"',
                    med_mod_path,
                    self.far_path,
                ],
                stdout=subprocess.PIPE,
                stderr=log_file,
                encoding="utf8",
            )
            stdout, stderr = perplexity_proc.communicate()

            perplexity = None
            for line in stdout.splitlines():
                m = re.search(r"perplexity = ([\d.]+)", line)
                if m:
                    perplexity = m.group(0)
            self.log_info(f"Perplexity of medium model: {perplexity}")
            perplexity_proc = subprocess.Popen(
                [
                    "ngramperplexity",
                    f'--OOV_symbol="{self.oov_word}"',
                    small_mod_path,
                    self.far_path,
                ],
                stdout=subprocess.PIPE,
                stderr=log_file,
                encoding="utf8",
            )
            stdout, stderr = perplexity_proc.communicate()

            perplexity = None
            for line in stdout.splitlines():
                m = re.search(r"perplexity = ([\d.]+)", line)
                if m:
                    perplexity = m.group(0)
            self.log_info(f"Perplexity of small model: {perplexity}")

        Run an evaluation over the training data to generate perplexity score
        
Run an evaluation over the training data to generate perplexity score
Run an evaluation over the training data to generate perplexity score
def evaluate(self) -> None:
        log_path = os.path.join(self.working_log_directory, "evaluate.log")
        small_mod_path = self.mod_path.replace(".mod", "_small.mod")
        med_mod_path = self.mod_path.replace(".mod", "_med.mod")
        with open(log_path, "w", encoding="utf8") as log_file:
            perplexity_proc = subprocess.Popen(
                [
                    "ngramperplexity",
                    f'--OOV_symbol="{self.oov_word}"',
                    self.mod_path,
                    self.far_path,
                ],
                stdout=subprocess.PIPE,
                stderr=log_file,
                encoding="utf8",
            )
            stdout, stderr = perplexity_proc.communicate()
            num_sentences = None
            num_words = None
            num_oovs = None
            perplexity = None
            for line in stdout.splitlines():
                m = re.search(r"(\d+) sentences", line)
                if m:
                    num_sentences = m.group(0)
                m = re.search(r"(\d+) words", line)
                if m:
                    num_words = m.group(0)
                m = re.search(r"(\d+) OOVs", line)
                if m:
                    num_oovs = m.group(0)
                m = re.search(r"perplexity = ([\d.]+)", line)
                if m:
                    perplexity = m.group(0)
            self.log_info(f"{num_sentences} sentences, {num_words} words, {num_oovs} oovs")
            self.log_info(f"Perplexity of large model: {perplexity}")
            perplexity_proc = subprocess.Popen(
                [
                    "ngramperplexity",
                    f'--OOV_symbol="{self.oov_word}"',
                    med_mod_path,
                    self.far_path,
                ],
                stdout=subprocess.PIPE,
                stderr=log_file,
                encoding="utf8",
            )
            stdout, stderr = perplexity_proc.communicate()
            perplexity = None
            for line in stdout.splitlines():
                m = re.search(r"perplexity = ([\d.]+)", line)
                if m:
                    perplexity = m.group(0)
            self.log_info(f"Perplexity of medium model: {perplexity}")
            perplexity_proc = subprocess.Popen(
                [
                    "ngramperplexity",
                    f'--OOV_symbol="{self.oov_word}"',
                    small_mod_path,
                    self.far_path,
                ],
                stdout=subprocess.PIPE,
                stderr=log_file,
                encoding="utf8",
            )
            stdout, stderr = perplexity_proc.communicate()
            perplexity = None
            for line in stdout.splitlines():
                m = re.search(r"perplexity = ([\d.]+)", line)
                if m:
                    perplexity = m.group(0)
            self.log_info(f"Perplexity of small model: {perplexity}")
def evaluate ( self ) -> None : log_path = os . path . join ( self . working_log_directory , "evaluate.log" ) small_mod_path = self . mod_path . replace ( ".mod" , "_small.mod" ) med_mod_path = self . mod_path . replace ( ".mod" , "_med.mod" ) with open ( log_path , "w" , encoding = "utf8" ) as log_file : perplexity_proc = subprocess . Popen ( [ "ngramperplexity" , f'--OOV_symbol="{self.oov_word}"' , self . mod_path , self . far_path , ] , stdout = subprocess . PIPE , stderr = log_file , encoding = "utf8" , ) stdout , stderr = perplexity_proc . communicate ( ) num_sentences = None num_words = None num_oovs = None perplexity = None for line in stdout . splitlines ( ) : m = re . search ( r"(\d+) sentences" , line ) if m : num_sentences = m . group ( 0 ) m = re . search ( r"(\d+) words" , line ) if m : num_words = m . group ( 0 ) m = re . search ( r"(\d+) OOVs" , line ) if m : num_oovs = m . group ( 0 ) m = re . search ( r"perplexity = ([\d.]+)" , line ) if m : perplexity = m . group ( 0 ) self . log_info ( f"{num_sentences} sentences, {num_words} words, {num_oovs} oovs" ) self . log_info ( f"Perplexity of large model: {perplexity}" ) perplexity_proc = subprocess . Popen ( [ "ngramperplexity" , f'--OOV_symbol="{self.oov_word}"' , med_mod_path , self . far_path , ] , stdout = subprocess . PIPE , stderr = log_file , encoding = "utf8" , ) stdout , stderr = perplexity_proc . communicate ( ) perplexity = None for line in stdout . splitlines ( ) : m = re . search ( r"perplexity = ([\d.]+)" , line ) if m : perplexity = m . group ( 0 ) self . log_info ( f"Perplexity of medium model: {perplexity}" ) perplexity_proc = subprocess . Popen ( [ "ngramperplexity" , f'--OOV_symbol="{self.oov_word}"' , small_mod_path , self . far_path , ] , stdout = subprocess . PIPE , stderr = log_file , encoding = "utf8" , ) stdout , stderr = perplexity_proc . communicate ( ) perplexity = None for line in stdout . splitlines ( ) : m = re . search ( r"perplexity = ([\d.]+)" , line ) if m : perplexity = m . group ( 0 ) self . log_info ( f"Perplexity of small model: {perplexity}" )
Run an evaluation over the training data to generate perplexity score
Run an evaluation over the training data to generate perplexity score
"""
        Run an evaluation over the training data to generate perplexity score
        """
self