#!/usr/bin/env python3# Copyright (c) Facebook, Inc. and its affiliates.## This source code is licensed under the MIT license found in the# LICENSE file in the root directory of this source tree.fromtypingimportUnionfromfairseq.data.dictionaryimportDictionaryfrom.decoder_configimportDecoderConfig,FlashlightDecoderConfigfrom.base_decoderimportBaseDecoderdefDecoder(cfg:Union[DecoderConfig,FlashlightDecoderConfig],tgt_dict:Dictionary)->BaseDecoder:ifcfg.type=="viterbi":from.viterbi_decoderimportViterbiDecoderreturnViterbiDecoder(tgt_dict)ifcfg.type=="kenlm":from.flashlight_decoderimportKenLMDecoderreturnKenLMDecoder(cfg,tgt_dict)ifcfg.type=="fairseqlm":from.flashlight_decoderimportFairseqLMDecoderreturnFairseqLMDecoder(cfg,tgt_dict)raiseNotImplementedError(f"Invalid decoder name: {cfg.name}")