diff --git a/examples/other/1xt2x/src_deepspeech2x/models/ds2/deepspeech2.py b/examples/other/1xt2x/src_deepspeech2x/models/ds2/deepspeech2.py index 003b02e2d2c6921319bc57e3c4561d86a7ea7326..e25e40309395484da4aa345359f9c75bca27aa75 100644 --- a/examples/other/1xt2x/src_deepspeech2x/models/ds2/deepspeech2.py +++ b/examples/other/1xt2x/src_deepspeech2x/models/ds2/deepspeech2.py @@ -12,12 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. """Deepspeech2 ASR Model""" -from typing import Optional - import paddle from paddle import nn from src_deepspeech2x.models.ds2.rnn import RNNStack -from yacs.config import CfgNode from paddlespeech.s2t.models.ds2.conv import ConvStack from paddlespeech.s2t.modules.ctc import CTCDecoder diff --git a/examples/other/1xt2x/src_deepspeech2x/test_model.py b/examples/other/1xt2x/src_deepspeech2x/test_model.py index 246fb1070bcf2a181577a7d4c20175c2039c1fea..2a38fb5cd9bf0fcb80494d0bc28525089440586b 100644 --- a/examples/other/1xt2x/src_deepspeech2x/test_model.py +++ b/examples/other/1xt2x/src_deepspeech2x/test_model.py @@ -15,8 +15,6 @@ import time from collections import defaultdict from contextlib import nullcontext -from pathlib import Path -from typing import Optional import numpy as np import paddle @@ -24,7 +22,6 @@ from paddle import distributed as dist from paddle.io import DataLoader from src_deepspeech2x.models.ds2 import DeepSpeech2InferModel from src_deepspeech2x.models.ds2 import DeepSpeech2Model -from yacs.config import CfgNode from paddlespeech.s2t.frontend.featurizer.text_featurizer import TextFeaturizer from paddlespeech.s2t.io.collator import SpeechCollator diff --git a/paddlespeech/s2t/exps/deepspeech2/bin/deploy/runtime.py b/paddlespeech/s2t/exps/deepspeech2/bin/deploy/runtime.py index ccb85906a917a0db882c9e1e4eb53b25514c6d9a..5755a5f101c18927aff975262d627f81a74fb783 100644 --- a/paddlespeech/s2t/exps/deepspeech2/bin/deploy/runtime.py +++ b/paddlespeech/s2t/exps/deepspeech2/bin/deploy/runtime.py @@ -19,8 +19,8 @@ import paddle from paddle.inference import Config from paddle.inference import create_predictor from paddle.io import DataLoader - from yacs.config import CfgNode + from paddlespeech.s2t.io.collator import SpeechCollator from paddlespeech.s2t.io.dataset import ManifestDataset from paddlespeech.s2t.models.ds2 import DeepSpeech2Model diff --git a/paddlespeech/s2t/exps/deepspeech2/bin/deploy/server.py b/paddlespeech/s2t/exps/deepspeech2/bin/deploy/server.py index 85c2466f5809602c33f7219c10665a6c224d33fe..0d0b4f2197c05383285bbf590f53f334d134c969 100644 --- a/paddlespeech/s2t/exps/deepspeech2/bin/deploy/server.py +++ b/paddlespeech/s2t/exps/deepspeech2/bin/deploy/server.py @@ -17,8 +17,8 @@ import functools import numpy as np import paddle from paddle.io import DataLoader - from yacs.config import CfgNode + from paddlespeech.s2t.io.collator import SpeechCollator from paddlespeech.s2t.io.dataset import ManifestDataset from paddlespeech.s2t.models.ds2 import DeepSpeech2Model diff --git a/paddlespeech/s2t/exps/deepspeech2/bin/export.py b/paddlespeech/s2t/exps/deepspeech2/bin/export.py index 090b5fabffe71e558acd3777fd49bc75997a1663..ee013d79e6ed3d39516ee65d5c4df5ec30a24b42 100644 --- a/paddlespeech/s2t/exps/deepspeech2/bin/export.py +++ b/paddlespeech/s2t/exps/deepspeech2/bin/export.py @@ -13,6 +13,7 @@ # limitations under the License. """Export for DeepSpeech2 model.""" from yacs.config import CfgNode + from paddlespeech.s2t.exps.deepspeech2.model import DeepSpeech2Tester as Tester from paddlespeech.s2t.training.cli import default_argument_parser from paddlespeech.s2t.utils.utility import print_arguments diff --git a/paddlespeech/s2t/exps/deepspeech2/bin/test_export.py b/paddlespeech/s2t/exps/deepspeech2/bin/test_export.py index 176028ed89eee9867be3dbbbcd923f5823eb5309..707eb9e1bc26204fe5b6a9070e02f7ad95d5f334 100644 --- a/paddlespeech/s2t/exps/deepspeech2/bin/test_export.py +++ b/paddlespeech/s2t/exps/deepspeech2/bin/test_export.py @@ -13,6 +13,7 @@ # limitations under the License. """Evaluation for DeepSpeech2 model.""" from yacs.config import CfgNode + from paddlespeech.s2t.exps.deepspeech2.model import DeepSpeech2ExportTester as ExportTester from paddlespeech.s2t.training.cli import default_argument_parser from paddlespeech.s2t.utils.utility import print_arguments diff --git a/paddlespeech/s2t/exps/deepspeech2/bin/test_wav.py b/paddlespeech/s2t/exps/deepspeech2/bin/test_wav.py index e2cb7e2f8a591cb11fd1642e2c85a56a75ffe1a4..a909dd416a03766dba505129a20edaeb9bee0cd8 100644 --- a/paddlespeech/s2t/exps/deepspeech2/bin/test_wav.py +++ b/paddlespeech/s2t/exps/deepspeech2/bin/test_wav.py @@ -20,7 +20,6 @@ import paddle import soundfile from yacs.config import CfgNode -from paddlespeech.s2t.exps.deepspeech2.config import get_cfg_defaults from paddlespeech.s2t.frontend.featurizer.text_featurizer import TextFeaturizer from paddlespeech.s2t.io.collator import SpeechCollator from paddlespeech.s2t.models.ds2 import DeepSpeech2Model diff --git a/paddlespeech/s2t/exps/deepspeech2/bin/train.py b/paddlespeech/s2t/exps/deepspeech2/bin/train.py index 5e8c0fffec586943d17a7bf03ff360bfc8985fdf..09e8662f1ce75ff351d7981dc1c4382082f9b61a 100644 --- a/paddlespeech/s2t/exps/deepspeech2/bin/train.py +++ b/paddlespeech/s2t/exps/deepspeech2/bin/train.py @@ -13,8 +13,8 @@ # limitations under the License. """Trainer for DeepSpeech2 model.""" from paddle import distributed as dist - from yacs.config import CfgNode + from paddlespeech.s2t.exps.deepspeech2.model import DeepSpeech2Trainer as Trainer from paddlespeech.s2t.training.cli import default_argument_parser from paddlespeech.s2t.utils.utility import print_arguments diff --git a/paddlespeech/s2t/exps/deepspeech2/model.py b/paddlespeech/s2t/exps/deepspeech2/model.py index e7d5e20f15fdf6066e56fdffc14323deac2bfbb9..049311c78147dd42540f7b915180111149892dcf 100644 --- a/paddlespeech/s2t/exps/deepspeech2/model.py +++ b/paddlespeech/s2t/exps/deepspeech2/model.py @@ -16,7 +16,6 @@ import os import time from collections import defaultdict from contextlib import nullcontext -from typing import Optional import jsonlines import numpy as np @@ -24,7 +23,6 @@ import paddle from paddle import distributed as dist from paddle import inference from paddle.io import DataLoader -from yacs.config import CfgNode from paddlespeech.s2t.frontend.featurizer.text_featurizer import TextFeaturizer from paddlespeech.s2t.io.collator import SpeechCollator diff --git a/paddlespeech/s2t/exps/u2/bin/export.py b/paddlespeech/s2t/exps/u2/bin/export.py index 3907cebdd1f342fac180a1fcb2c9b076b9eb26ae..592b12379be7648377ad3c450f2b608610121fbe 100644 --- a/paddlespeech/s2t/exps/u2/bin/export.py +++ b/paddlespeech/s2t/exps/u2/bin/export.py @@ -13,6 +13,7 @@ # limitations under the License. """Export for U2 model.""" from yacs.config import CfgNode + from paddlespeech.s2t.exps.u2.model import U2Tester as Tester from paddlespeech.s2t.training.cli import default_argument_parser from paddlespeech.s2t.utils.utility import print_arguments diff --git a/paddlespeech/s2t/exps/u2/bin/train.py b/paddlespeech/s2t/exps/u2/bin/train.py index d562278f5fe8cffa24541d2dbf2e52e82f8bff1e..53c223283f180397e69b6a5290a4572e5a76cc41 100644 --- a/paddlespeech/s2t/exps/u2/bin/train.py +++ b/paddlespeech/s2t/exps/u2/bin/train.py @@ -16,8 +16,8 @@ import cProfile import os from paddle import distributed as dist - from yacs.config import CfgNode + from paddlespeech.s2t.exps.u2.model import U2Trainer as Trainer from paddlespeech.s2t.training.cli import default_argument_parser from paddlespeech.s2t.utils.utility import print_arguments diff --git a/paddlespeech/s2t/exps/u2/model.py b/paddlespeech/s2t/exps/u2/model.py index d0cea0316584c67bd17f9527f961d88f801655c5..6ab671ee351c12dd426126017b75637b8abacad5 100644 --- a/paddlespeech/s2t/exps/u2/model.py +++ b/paddlespeech/s2t/exps/u2/model.py @@ -18,13 +18,11 @@ import time from collections import defaultdict from collections import OrderedDict from contextlib import nullcontext -from typing import Optional import jsonlines import numpy as np import paddle from paddle import distributed as dist -from yacs.config import CfgNode from paddlespeech.s2t.frontend.featurizer import TextFeaturizer from paddlespeech.s2t.io.dataloader import BatchDataLoader diff --git a/paddlespeech/s2t/exps/u2_kaldi/model.py b/paddlespeech/s2t/exps/u2_kaldi/model.py index 780c5c08170183ff220f85bbacc76052a0b69a4b..bc995977ada577770612f99d05387ed0bb87d39e 100644 --- a/paddlespeech/s2t/exps/u2_kaldi/model.py +++ b/paddlespeech/s2t/exps/u2_kaldi/model.py @@ -17,13 +17,11 @@ import os import time from collections import defaultdict from contextlib import nullcontext -from typing import Optional import jsonlines import numpy as np import paddle from paddle import distributed as dist -from yacs.config import CfgNode from paddlespeech.s2t.frontend.featurizer import TextFeaturizer from paddlespeech.s2t.frontend.utility import load_dict @@ -42,6 +40,7 @@ from paddlespeech.s2t.utils.utility import UpdateConfig logger = Log(__name__).getlog() + class U2Trainer(Trainer): def __init__(self, config, args): super().__init__(config, args) diff --git a/paddlespeech/s2t/exps/u2_st/bin/export.py b/paddlespeech/s2t/exps/u2_st/bin/export.py index 1bc4e1f3c87b5ac8cca58642a402399944d4cb0e..c641152fe4bd75b5c72617370b02b29cc79f0435 100644 --- a/paddlespeech/s2t/exps/u2_st/bin/export.py +++ b/paddlespeech/s2t/exps/u2_st/bin/export.py @@ -13,6 +13,7 @@ # limitations under the License. """Export for U2 model.""" from yacs.config import CfgNode + from paddlespeech.s2t.exps.u2_st.model import U2STTester as Tester from paddlespeech.s2t.training.cli import default_argument_parser from paddlespeech.s2t.utils.utility import print_arguments diff --git a/paddlespeech/s2t/exps/u2_st/model.py b/paddlespeech/s2t/exps/u2_st/model.py index ca2c2c1daa1aedf5066c9445f203966a2f6c9f7c..b03ca38b6684d0d32e63ba5d5a672870fa5c38ff 100644 --- a/paddlespeech/s2t/exps/u2_st/model.py +++ b/paddlespeech/s2t/exps/u2_st/model.py @@ -18,13 +18,11 @@ import time from collections import defaultdict from collections import OrderedDict from contextlib import nullcontext -from typing import Optional import jsonlines import numpy as np import paddle from paddle import distributed as dist -from yacs.config import CfgNode from paddlespeech.s2t.frontend.featurizer import TextFeaturizer from paddlespeech.s2t.io.dataloader import BatchDataLoader @@ -208,8 +206,7 @@ class U2STTrainer(Trainer): k.split(',')) == 2 else "" msg += "," msg = msg[:-1] # remove the last "," - if (batch_index + 1 - ) % self.config.log_interval == 0: + if (batch_index + 1) % self.config.log_interval == 0: logger.info(msg) except Exception as e: logger.error(e) @@ -260,7 +257,8 @@ class U2STTrainer(Trainer): batch_frames_in=0, batch_frames_out=0, batch_frames_inout=0, - preprocess_conf=config.preprocess_config, # aug will be off when train_mode=False + preprocess_conf=config. + preprocess_config, # aug will be off when train_mode=False n_iter_processes=config.num_workers, subsampling_factor=1, load_aux_output=load_transcript, @@ -281,7 +279,8 @@ class U2STTrainer(Trainer): batch_frames_in=0, batch_frames_out=0, batch_frames_inout=0, - preprocess_conf=config.preprocess_config, # aug will be off when train_mode=False + preprocess_conf=config. + preprocess_config, # aug will be off when train_mode=False n_iter_processes=config.num_workers, subsampling_factor=1, load_aux_output=load_transcript, @@ -290,7 +289,8 @@ class U2STTrainer(Trainer): logger.info("Setup train/valid Dataloader!") else: # test dataset, return raw text - decode_batch_size = config.get('decode',dict()).get('decode_batch_size', 1) + decode_batch_size = config.get('decode', dict()).get( + 'decode_batch_size', 1) self.test_loader = BatchDataLoader( json_file=config.test_manifest, train_mode=False, @@ -305,7 +305,8 @@ class U2STTrainer(Trainer): batch_frames_in=0, batch_frames_out=0, batch_frames_inout=0, - preprocess_conf=config.preprocess_config, # aug will be off when train_mode=False + preprocess_conf=config. + preprocess_config, # aug will be off when train_mode=False n_iter_processes=config.num_workers, subsampling_factor=1, num_encs=1, diff --git a/paddlespeech/s2t/io/collator.py b/paddlespeech/s2t/io/collator.py index 3a14b2d5487b2cc7b93a9743e376e42bbe32acb6..b99fc80c023f72e401726fc347066c5bd569b40a 100644 --- a/paddlespeech/s2t/io/collator.py +++ b/paddlespeech/s2t/io/collator.py @@ -12,10 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. import io -from typing import Optional import numpy as np -from yacs.config import CfgNode from paddlespeech.s2t.frontend.augmentor.augmentation import AugmentationPipeline from paddlespeech.s2t.frontend.featurizer.speech_featurizer import SpeechFeaturizer diff --git a/paddlespeech/s2t/io/dataset.py b/paddlespeech/s2t/io/dataset.py index 9149fb271ba19e90f59732595b28c3273685cf1a..0e94f047bce7ad053ecd566f4a8d8c83a1b10a7c 100644 --- a/paddlespeech/s2t/io/dataset.py +++ b/paddlespeech/s2t/io/dataset.py @@ -13,11 +13,8 @@ # limitations under the License. # Modified from espnet(https://github.com/espnet/espnet) # Modified from wenet(https://github.com/wenet-e2e/wenet) -from typing import Optional - import jsonlines from paddle.io import Dataset -from yacs.config import CfgNode from paddlespeech.s2t.frontend.utility import read_manifest from paddlespeech.s2t.utils.log import Log diff --git a/paddlespeech/s2t/models/ds2/deepspeech2.py b/paddlespeech/s2t/models/ds2/deepspeech2.py index ddc3612d92634861533ade9605eb2afbc8773572..a478ba823f2e37bd72db8d46dcf9a552cb158ea5 100644 --- a/paddlespeech/s2t/models/ds2/deepspeech2.py +++ b/paddlespeech/s2t/models/ds2/deepspeech2.py @@ -12,11 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. """Deepspeech2 ASR Model""" -from typing import Optional - import paddle from paddle import nn -from yacs.config import CfgNode from paddlespeech.s2t.models.ds2.conv import ConvStack from paddlespeech.s2t.models.ds2.rnn import RNNStack @@ -119,6 +116,7 @@ class DeepSpeech2Model(nn.Layer): before softmax) and a ctc cost layer. :rtype: tuple of LayerOutput """ + def __init__(self, feat_size, dict_size, diff --git a/paddlespeech/s2t/models/ds2_online/deepspeech2.py b/paddlespeech/s2t/models/ds2_online/deepspeech2.py index aae77f74868765c2a1b3b762cab183d48b2e1ce3..7d463755ae886c3bf15c418336c84d77cb80c489 100644 --- a/paddlespeech/s2t/models/ds2_online/deepspeech2.py +++ b/paddlespeech/s2t/models/ds2_online/deepspeech2.py @@ -12,12 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. """Deepspeech2 ASR Online Model""" -from typing import Optional - import paddle import paddle.nn.functional as F from paddle import nn -from yacs.config import CfgNode from paddlespeech.s2t.models.ds2_online.conv import Conv2dSubsampling4Online from paddlespeech.s2t.modules.ctc import CTCDecoder @@ -243,6 +240,7 @@ class DeepSpeech2ModelOnline(nn.Layer): before softmax) and a ctc cost layer. :rtype: tuple of LayerOutput """ + def __init__( self, feat_size, diff --git a/paddlespeech/s2t/models/u2/u2.py b/paddlespeech/s2t/models/u2/u2.py index 26e81acf64b3ce79e2a4c5aa09b907c47604f8b3..d920a200c8b620423f9accfc894e42790a160cdb 100644 --- a/paddlespeech/s2t/models/u2/u2.py +++ b/paddlespeech/s2t/models/u2/u2.py @@ -26,7 +26,6 @@ from typing import Tuple import paddle from paddle import jit from paddle import nn -from yacs.config import CfgNode from paddlespeech.s2t.decoders.scorers.ctc import CTCPrefixScorer from paddlespeech.s2t.frontend.utility import IGNORE_ID @@ -59,6 +58,7 @@ logger = Log(__name__).getlog() class U2BaseModel(ASRInterface, nn.Layer): """CTC-Attention hybrid Encoder-Decoder model""" + def __init__(self, vocab_size: int, encoder: TransformerEncoder, diff --git a/paddlespeech/s2t/models/u2_st/u2_st.py b/paddlespeech/s2t/models/u2_st/u2_st.py index 1c5596bac97f1591a471d23e006318aa079bcd4a..2aa0b3479843b322e4cc5381596139e36c9e1fb3 100644 --- a/paddlespeech/s2t/models/u2_st/u2_st.py +++ b/paddlespeech/s2t/models/u2_st/u2_st.py @@ -24,7 +24,6 @@ from typing import Tuple import paddle from paddle import jit from paddle import nn -from yacs.config import CfgNode from paddlespeech.s2t.frontend.utility import IGNORE_ID from paddlespeech.s2t.frontend.utility import load_cmvn @@ -51,6 +50,7 @@ logger = Log(__name__).getlog() class U2STBaseModel(nn.Layer): """CTC-Attention hybrid Encoder-Decoder model""" + def __init__(self, vocab_size: int, encoder: TransformerEncoder,