Commit 6b2086cf authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Add deprecation warning to decoder (#3055)

Summary:
Flashlight Text decoder is now available on PyPI and KenLM support is being added at
https://github.com/flashlight/text/pull/43

Once this work is merged, we can rely on the official distribution of Flashlight Text package, so we are adding deprecation warning.

Once the decoder is fully available, one can install it with

```
pip install flashlight-text
pip install git+https://github.com/kpu/kenlm.git
```

Pull Request resolved: https://github.com/pytorch/audio/pull/3055

Reviewed By: hwangjeff, nateanl

Differential Revision: D43239150

Pulled By: mthrok

fbshipit-source-id: 728cb208b8403100cd4ccd80c6295d454756b414
parent b799fcd6
from __future__ import annotations from __future__ import annotations
import itertools as it import itertools as it
import warnings
from abc import abstractmethod from abc import abstractmethod
from collections import namedtuple from collections import namedtuple
from typing import Dict, List, NamedTuple, Optional, Tuple, Union from typing import Dict, List, NamedTuple, Optional, Tuple, Union
...@@ -9,13 +11,13 @@ import torch ...@@ -9,13 +11,13 @@ import torch
import torchaudio import torchaudio
from torchaudio.utils import download_asset from torchaudio.utils import download_asset
try:
# We prioritize the version from upstream flashlight here. # We prioritize the version from upstream flashlight here.
# This will allow applications that use the upstream flashlight # This will allow applications that use the upstream flashlight
# alongside torchaudio. # alongside torchaudio.
if torchaudio._internal.module_utils.is_module_available("flashlight"):
from flashlight.lib.text.decoder import ( from flashlight.lib.text.decoder import (
CriterionType as _CriterionType, CriterionType as _CriterionType,
KenLM as _KenLM,
LexiconDecoder as _LexiconDecoder, LexiconDecoder as _LexiconDecoder,
LexiconDecoderOptions as _LexiconDecoderOptions, LexiconDecoderOptions as _LexiconDecoderOptions,
LexiconFreeDecoder as _LexiconFreeDecoder, LexiconFreeDecoder as _LexiconFreeDecoder,
...@@ -31,7 +33,16 @@ try: ...@@ -31,7 +33,16 @@ try:
Dictionary as _Dictionary, Dictionary as _Dictionary,
load_words as _load_words, load_words as _load_words,
) )
except Exception:
try:
from flashlight.lib.text.decoder import KenLM as _KenLM
except Exception:
_KenLM = None
else:
warnings.warn(
"The built-in flashlight integration is deprecated, and will be removed in future release."
"Please install flashlight-text. https://pypi.org/project/flashlight-text/"
)
torchaudio._extension._load_lib("libflashlight-text") torchaudio._extension._load_lib("libflashlight-text")
from torchaudio.lib.flashlight_lib_text_decoder import ( from torchaudio.lib.flashlight_lib_text_decoder import (
CriterionType as _CriterionType, CriterionType as _CriterionType,
...@@ -427,6 +438,8 @@ def ctc_decoder( ...@@ -427,6 +438,8 @@ def ctc_decoder(
word_dict = _get_word_dict(lexicon, lm, lm_dict, tokens_dict, unk_word) word_dict = _get_word_dict(lexicon, lm, lm_dict, tokens_dict, unk_word)
if type(lm) == str: if type(lm) == str:
if _KenLM is None:
raise RuntimeError("flashlight is installed, but KenLM is not installed. Please install KenLM.")
lm = _KenLM(lm, word_dict) lm = _KenLM(lm, word_dict)
elif lm is None: elif lm is None:
lm = _ZeroLM() lm = _ZeroLM()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment