pykaldi icon indicating copy to clipboard operation
pykaldi copied to clipboard

LatticeLmRescorer.from_files(...) occurs table_match_type error

Open hwiorn opened this issue 6 years ago • 4 comments

pykaldi version is 0.1.2 0ff6fb0 (latest). I tested with anaconda python 3.6 on macOS Mojave.

Below code occurs table_match_type error.

import kaldi.asr
kaldi.asr.LatticeLmRescorer.from_files("G.fst", "G.fst")
Python 3.6.8 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import kaldi.asr; kaldi.asr.LatticeLmRescorer.from_files("G.fst", "G.fst")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/gglee/Project/pykaldi/kaldi/asr.py", line 1997, in from_files
    return cls(old_lm, new_lm, phi_label)
  File "/Users/gglee/Project/pykaldi/kaldi/asr.py", line 1943, in __init__
    table_match_type=_fst_enums.MatchType.MATCH_INPUT))
TypeError: from_matcher_opts() argument table_match_type is not valid for ::fst::MatchType (MatchType instance given): expecting enum MatchType, got MatchType instance
>>>

hwiorn avatar Jun 19 '19 08:06 hwiorn

This seems to be a recurrent problem with clif. We are still not sure what the right fix is. We thought that doing the local import in kaldi/fstext/enums.py was enough but apparently not. Previously we were importing those in kaldi/fstext/init.py . During the refactor of package structure that was changed to kaldi/fstext/enums.py . Don't know why that changes things.

These are the relevant commits:

https://github.com/pykaldi/pykaldi/commit/bff0573d77582f2c487b8d0149738b000314dfe7#diff-4340e281875ddf317c4d103d5c229015

https://github.com/pykaldi/pykaldi/commit/02c0e5f76ceaf099c57e5fecc74a238073137efc#diff-63aeb4102fac2ba7bbbdc7091ce5d4b0

vrmpx avatar Jun 24 '19 02:06 vrmpx

I am getting the exact same error :

TypeError: from_matcher_opts() argument table_match_type is not valid for ::fst::MatchType (MatchType instance given): expecting enum MatchType, got MatchType instance

any insight on how to fix it?

slegroux avatar Jul 29 '19 20:07 slegroux

Hi, I have also the same problem. Is there a solution, please?

Thanks!

lucgeo avatar Aug 21 '20 13:08 lucgeo

As a test, I replaced that part of LatticeLmRescorer.__init__ with the following...

        MatchType = type(_fst_spec.TableComposeOptions().table_match_type)
        self.old_lm_compose_cache = _fst_spec.LatticeTableComposeCache.from_compose_opts(
            _fst_spec.TableComposeOptions.from_matcher_opts(
                _fst_spec.TableMatcherOptions(),
                table_match_type=MatchType.MATCH_INPUT))
        if not self.phi_label:
            self.new_lm_compose_cache = _fst_spec.LatticeTableComposeCache.from_compose_opts(
                _fst_spec.TableComposeOptions.from_matcher_opts(
                    _fst_spec.TableMatcherOptions(),
                    table_match_type=MatchType.MATCH_INPUT))

This works, so the type seems to get duplicated somewhere because of CLIF or the bindings. Getting the type directly works around it and doesn't require recompiling. It is absolutely awful, though.

asumagic avatar Jan 27 '23 11:01 asumagic