kpu / kenlm

KenLM: Faster and Smaller Language Model Queries
http://kheafield.com/code/kenlm/
Other
2.5k stars 513 forks source link

AttributeError: module 'kenlm' has no attribute 'Model' #396

Closed talhaanwarch closed 2 years ago

talhaanwarch commented 2 years ago

Hi, i am following Boosting Wav2Vec2 with n-grams in 🤗 Transformers tutorial But when i do

from pyctcdecode import build_ctcdecoder

decoder = build_ctcdecoder(
    labels=list(sorted_vocab_dict.keys()),
    kenlm_model_path="5gram_correct.arpa",
)

I got this error

AttributeError                            Traceback (most recent call last)
Input In [27], in <cell line: 3>()
      1 from pyctcdecode import build_ctcdecoder
----> 3 decoder = build_ctcdecoder(
      4     labels=list(sorted_vocab_dict.keys()),
      5     kenlm_model_path="5gram_correct.arpa",
      6 )

File ~/venv/lib/python3.8/site-packages/pyctcdecode/decoder.py:862, in build_ctcdecoder(labels, kenlm_model_path, unigrams, alpha, beta, unk_score_offset, lm_score_boundary)
    839 def build_ctcdecoder(
    840     labels: List[str],
    841     kenlm_model_path: Optional[str] = None,
   (...)
    846     lm_score_boundary: bool = DEFAULT_SCORE_LM_BOUNDARY,
    847 ) -> BeamSearchDecoderCTC:
    848     """Build a BeamSearchDecoderCTC instance with main functionality.
    849 
    850     Args:
   (...)
    860         instance of BeamSearchDecoderCTC
    861     """
--> 862     kenlm_model = None if kenlm_model_path is None else kenlm.Model(kenlm_model_path)
    863     if kenlm_model_path is not None and kenlm_model_path.endswith(".arpa"):
    864         logger.info("Using arpa instead of binary LM file, decoder instantiation might be slow.")

AttributeError: module 'kenlm' has no attribute 'Model'

I also try

import kenlm
lm = kenlm.Model("5gram.arpa")

but same error AttributeError: module 'kenlm' has no attribute 'Model'

PanwarJayant commented 1 year ago

How did you resolve it?