diff --git a/examples/other/1xt2x/src_deepspeech2x/models/ds2/deepspeech2.py b/examples/other/1xt2x/src_deepspeech2x/models/ds2/deepspeech2.py index 003b02e2..e25e4030 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 246fb107..2a38fb5c 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 ccb85906..5755a5f1 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 85c2466f..0d0b4f21 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 090b5fab..ee013d79 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 176028ed..707eb9e1 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 e2cb7e2f..a909dd41 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 5e8c0fff..09e8662f 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 e7d5e20f..049311c7 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 3907cebd..592b1237 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 d562278f..53c22328 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 d0cea031..6ab671ee 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 780c5c08..bc995977 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 1bc4e1f3..c641152f 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 ca2c2c1d..b03ca38b 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 3a14b2d5..b99fc80c 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 9149fb27..0e94f047 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 ddc3612d..a478ba82 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 aae77f74..7d463755 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 26e81acf..d920a200 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 1c5596ba..2aa0b347 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,