Skip to content

Commit

Permalink
🚀 Reformat code and fix minor bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
nglehuy committed Dec 9, 2020
1 parent 96da1e2 commit 295b132
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[flake8]
ignore = E402,E701,E702,E704,E251
ignore = E402,E701,E702,E704,E251,W503,W504,C901
max-line-length = 127

[pep8]
ignore = E402,E701,E702,E704,E251
ignore = E402,E701,E702,E704,E251,W503,W504,C901
max-line-length = 127
indent-size = 4
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

setuptools.setup(
name="TensorFlowASR",
version="0.4.0",
version="0.4.1",
author="Huy Le Nguyen",
author_email="[email protected]",
description="Almost State-of-the-art Automatic Speech Recognition using Tensorflow 2",
Expand Down
26 changes: 13 additions & 13 deletions tensorflow_asr/augmentations/spec_augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def mask(self, data: np.ndarray) -> np.ndarray:

class FreqMaskingAugmenter(SpectrogramAugmenter):
def __init__(self,
mask_factor=27,
name="FreqMaskingAugmenter",
mask_factor: float = 27,
name: str = "FreqMaskingAugmenter",
verbose=0):
super(FreqMaskingAugmenter, self).__init__(
action=Action.SUBSTITUTE, zone=(0.2, 0.8), name=name, device="cpu", verbose=verbose,
Expand All @@ -63,9 +63,9 @@ def substitute(self, data):

class FreqMasking(SpectrogramAugmenter):
def __init__(self,
num_masks=1,
mask_factor=27,
name="FreqMasking",
num_masks: int = 1,
mask_factor: float = 27,
name: str = "FreqMasking",
verbose=0):
super(FreqMasking, self).__init__(
action=Action.SUBSTITUTE, zone=(0.2, 0.8), name=name, device="cpu", verbose=verbose,
Expand All @@ -79,7 +79,7 @@ def substitute(self, data):


class TimeMaskingModel(Spectrogram):
def __init__(self, mask_factor: int = 100, p_upperbound: float = 1.0):
def __init__(self, mask_factor: float = 100, p_upperbound: float = 1.0):
"""
Args:
time_mask_param: parameter W of time masking
Expand Down Expand Up @@ -110,9 +110,9 @@ def mask(self, data: np.ndarray) -> np.ndarray:

class TimeMaskingAugmenter(SpectrogramAugmenter):
def __init__(self,
mask_factor=100,
p_upperbound=1,
name="TimeMaskingAugmenter",
mask_factor: float = 100,
p_upperbound: float = 1,
name: str = "TimeMaskingAugmenter",
verbose=0):
super(TimeMaskingAugmenter, self).__init__(
action=Action.SUBSTITUTE, zone=(0.2, 0.8), name=name, device="cpu", verbose=verbose,
Expand All @@ -125,10 +125,10 @@ def substitute(self, data):

class TimeMasking(SpectrogramAugmenter):
def __init__(self,
num_masks=1,
mask_factor=100,
p_upperbound=1,
name="TimeMasking",
num_masks: int = 1,
mask_factor: float = 100,
p_upperbound: float = 1,
name: str = "TimeMasking",
verbose=0):
super(TimeMasking, self).__init__(
action=Action.SUBSTITUTE, zone=(0.2, 0.8), name=name, device="cpu", verbose=verbose,
Expand Down
4 changes: 2 additions & 2 deletions tensorflow_asr/featurizers/gammatone.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ def erb_space(

def make_erb_filters(fs, centre_freqs, width=1.0):
"""
This function computes the filter coefficients for a bank of
This function computes the filter coefficients for a bank of
Gammatone filters. These filters were defined by Patterson and Holdworth for
simulating the cochlea.
simulating the cochlea.
The result is returned as a :class:`ERBCoeffArray`. Each row of the
filter arrays contains the coefficients for four second order filters. The
Expand Down
6 changes: 4 additions & 2 deletions tensorflow_asr/models/ctc.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def recognize(self, signals):

def extract_fn(signal): return self.speech_featurizer.tf_extract(signal)

features = tf.map_fn(extract_fn, signals, fn_output_signature=tf.TensorSpec(self.speech_featurizer.shape, dtype=tf.float32))
features = tf.map_fn(extract_fn, signals,
fn_output_signature=tf.TensorSpec(self.speech_featurizer.shape, dtype=tf.float32))
logits = self(features, training=False)
probs = tf.nn.softmax(logits)

Expand Down Expand Up @@ -88,7 +89,8 @@ def recognize_beam(self, signals, lm=False):

def extract_fn(signal): return self.speech_featurizer.tf_extract(signal)

features = tf.map_fn(extract_fn, signals, fn_output_signature=tf.TensorSpec(self.speech_featurizer.shape, dtype=tf.float32))
features = tf.map_fn(extract_fn, signals,
fn_output_signature=tf.TensorSpec(self.speech_featurizer.shape, dtype=tf.float32))
logits = self(features, training=False)
probs = tf.nn.softmax(logits)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_conformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import tensorflow as tf

from tensorflow_asr.models.conformer import Conformer
from tensorflow_asr.models.transducer import Transducer
from tensorflow_asr.models.layers.subsampling import Conv2dSubsampling
# from tensorflow_asr.models.transducer import Transducer
# from tensorflow_asr.models.layers.subsampling import Conv2dSubsampling
from tensorflow_asr.featurizers.text_featurizers import CharFeaturizer
from tensorflow_asr.featurizers.speech_featurizers import TFSpeechFeaturizer, read_raw_audio

Expand Down
2 changes: 1 addition & 1 deletion tests/test_ctc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from ctc_decoders import Scorer
from tensorflow_asr.models.ctc import CtcModel
from tensorflow_asr.featurizers.text_featurizers import CharFeaturizer
from tensorflow_asr.featurizers.speech_featurizers import TFSpeechFeaturizer, read_raw_audio
from tensorflow_asr.featurizers.speech_featurizers import TFSpeechFeaturizer
from tensorflow_asr.utils.utils import bytes_to_string, merge_two_last_dims

decoder_config = {
Expand Down
1 change: 0 additions & 1 deletion tests/test_subword.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import tensorflow as tf

from tensorflow_asr.featurizers.text_featurizers import SubwordFeaturizer
from tensorflow_asr.featurizers.speech_featurizers import read_raw_audio

parser = argparse.ArgumentParser(prog="test subword")

Expand Down

0 comments on commit 295b132

Please sign in to comment.