From ac29bcf2e6d7a15adff1f4f1664c8f07a5f4eea5 Mon Sep 17 00:00:00 2001 From: Michael McAuliffe Date: Mon, 4 Mar 2024 20:19:43 -0800 Subject: [PATCH] Fix bug in lexicon compiler (#16) --- docs/source/conf.py | 13 ++++--------- environment.yml | 2 +- extensions/feat/feat.cpp | 1 + kalpy/feat/mfcc.py | 4 ++-- kalpy/fstext/lexicon.py | 28 ++++++++++++++++------------ 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 17f5c70..5e7bcee 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -173,8 +173,7 @@ # autodoc_typehints_description_target = 'documented' # autoclass_content = 'both' autodoc_docstring_signature = True -autodoc_type_aliases = { -} +autodoc_type_aliases = {} napoleon_preprocess_types = False napoleon_attr_annotations = False @@ -245,7 +244,7 @@ # The reST default role (used for this markup: `text`) to use for all # documents. # -default_role = "autolink" +default_role = "code" # If true, '()' will be appended to :func: etc. cross-reference text. # @@ -262,9 +261,7 @@ # show_authors = False # nitpicky = True -nitpick_ignore = [ - -] +nitpick_ignore = [] # The name of the Pygments (syntax highlighting) style to use. pygments_style = "sphinx" @@ -512,9 +509,7 @@ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) -texinfo_documents = [ - -] +texinfo_documents = [] # Documents to append as an appendix to all manuals. # diff --git a/environment.yml b/environment.yml index 407fda8..c08c7f5 100644 --- a/environment.yml +++ b/environment.yml @@ -10,7 +10,7 @@ dependencies: - kaldi=*=*cpu* - scipy - pynini - - openfst + - openfst=1.8.3 - setuptools_scm - pybind11 - pytest diff --git a/extensions/feat/feat.cpp b/extensions/feat/feat.cpp index 1ca5136..e45779f 100644 --- a/extensions/feat/feat.cpp +++ b/extensions/feat/feat.cpp @@ -209,6 +209,7 @@ void feat_feat_functions(py::module& m){ left_context, right_context, &output_features); + py::gil_scoped_acquire acquire; return output_features; }, diff --git a/kalpy/feat/mfcc.py b/kalpy/feat/mfcc.py index cea854e..482f345 100644 --- a/kalpy/feat/mfcc.py +++ b/kalpy/feat/mfcc.py @@ -82,7 +82,7 @@ def __init__( sample_frequency: float = 16000, frame_length: int = 25, frame_shift: int = 10, - dither: float = 1.0, + dither: float = 0.0, preemphasis_coefficient: float = 0.97, remove_dc_offset: bool = True, window_type: str = "povey", @@ -97,7 +97,7 @@ def __init__( vtln_high: float = -500, num_coefficients: int = 13, use_energy: bool = True, - energy_floor: float = 0.0, + energy_floor: float = 1.0, raw_energy: bool = True, cepstral_lifter: float = 22.0, htk_compatibility: bool = False, diff --git a/kalpy/fstext/lexicon.py b/kalpy/fstext/lexicon.py index 62a7e46..22fc8c6 100644 --- a/kalpy/fstext/lexicon.py +++ b/kalpy/fstext/lexicon.py @@ -26,11 +26,11 @@ class Pronunciation: orthography: str pronunciation: str - probability: typing.Optional[float] - silence_after_probability: typing.Optional[float] - silence_before_correction: typing.Optional[float] - non_silence_before_correction: typing.Optional[float] - disambiguation: typing.Optional[int] + probability: typing.Optional[float] = None + silence_after_probability: typing.Optional[float] = None + silence_before_correction: typing.Optional[float] = None + non_silence_before_correction: typing.Optional[float] = None + disambiguation: typing.Optional[int] = None def parse_dictionary_file( @@ -192,10 +192,9 @@ def __init__( self._align_lexicon = None self.word_begin_label = word_begin_label self.word_end_label = word_end_label - self.start_state = None - self.loop_state = None - self.silence_state = None - self.non_silence_state = None + self.start_state = 0 + self.non_silence_state = 1 + self.silence_state = 2 def clear(self): self.pronunciations = [] @@ -364,12 +363,17 @@ def create_fsts(self, phonological_rule_fst: pynini.Fst = None): self.word_table.find(self.silence_word) self._fst = pynini.Fst() self._align_fst = pynini.Fst() - self.start_state = self._fst.add_state() + # Start state = 0 + self._fst.add_state() self._align_fst.add_state() self._fst.set_start(self.start_state) - self.non_silence_state = self._fst.add_state() # Also loop state + + # Non silence state = 1 + self._fst.add_state() # Also loop state self._align_fst.add_state() - self.silence_state = self._fst.add_state() + + # Silence state = 2 + self._fst.add_state() self._align_fst.add_state() self._align_fst.set_start(self.start_state)