Skip to content

Commit

Permalink
black fix
Browse files Browse the repository at this point in the history
  • Loading branch information
roshansh-cmu committed Feb 22, 2022
1 parent 8572a57 commit 23a537e
Show file tree
Hide file tree
Showing 50 changed files with 283 additions and 81 deletions.
4 changes: 2 additions & 2 deletions egs2/mini_librispeech/diar1/local/simulation/make_mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
else:
noise_data = noise_data[:maxlen]
# noise power is scaled according to selected SNR, then mixed
signal_power = np.sum(mixture ** 2) / len(mixture)
noise_power = np.sum(noise_data ** 2) / len(noise_data)
signal_power = np.sum(mixture**2) / len(mixture)
noise_power = np.sum(noise_data**2) / len(noise_data)
scale = math.sqrt(math.pow(10, -noise_snr / 10) * signal_power / noise_power)
mixture += noise_data * scale
# output the wav file and write wav.scp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
else:
noise_data = noise_data[:maxlen]
# noise power is scaled according to selected SNR, then mixed
signal_power = np.sum(mixture ** 2) / len(mixture)
noise_power = np.sum(noise_data ** 2) / len(noise_data)
signal_power = np.sum(mixture**2) / len(mixture)
noise_power = np.sum(noise_data**2) / len(noise_data)
scale = math.sqrt(math.pow(10, -noise_snr / 10) * signal_power / noise_power)
mixture += noise_data * scale
# output the wav file and write wav.scp
Expand Down
2 changes: 1 addition & 1 deletion espnet/asr/asr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def add_gradient_noise(model, iteration, duration=100, eta=1.0, scale_factor=0.5
scale_factor (float) {0.55}: The scale of `sigma`.
"""
interval = (iteration // duration) + 1
sigma = eta / interval ** scale_factor
sigma = eta / interval**scale_factor
for param in model.parameters():
if param.grad is not None:
_shape = param.grad.size()
Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/chainer_backend/e2e_asr_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __init__(self, idim, odim, args, ignore_id=-1, flag_return=True):
self.char_list = args.char_list
self.space = args.sym_space
self.blank = args.sym_blank
self.scale_emb = args.adim ** 0.5
self.scale_emb = args.adim**0.5
self.sos = odim - 1
self.eos = odim - 1
self.subsample = get_subsample(args, mode="asr", arch="transformer")
Expand Down
8 changes: 4 additions & 4 deletions espnet/nets/pytorch_backend/e2e_asr_mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def forward(self, xs_pad, ilens, ys_pad):
hlens[i // self.num_spkrs],
ys_pad[i % self.num_spkrs],
)
for i in range(self.num_spkrs ** 2)
for i in range(self.num_spkrs**2)
],
dim=1,
) # (B, num_spkrs^2)
Expand Down Expand Up @@ -441,13 +441,13 @@ def forward(self, xs_pad, ilens, ys_pad):
editdistance.eval(
hyp_words[ns // self.num_spkrs], ref_words[ns % self.num_spkrs]
)
for ns in range(self.num_spkrs ** 2)
for ns in range(self.num_spkrs**2)
] # h1r1,h1r2,h2r1,h2r2
tmp_char_ed = [
editdistance.eval(
hyp_chars[ns // self.num_spkrs], ref_chars[ns % self.num_spkrs]
)
for ns in range(self.num_spkrs ** 2)
for ns in range(self.num_spkrs**2)
] # h1r1,h1r2,h2r1,h2r2

word_eds.append(self.pit.min_pit_sample(torch.tensor(tmp_word_ed))[0])
Expand Down Expand Up @@ -676,7 +676,7 @@ def calculate_all_attentions(self, xs_pad, ilens, ys_pad):
hlens[i // self.num_spkrs],
ys_pad[i % self.num_spkrs],
)
for i in range(self.num_spkrs ** 2)
for i in range(self.num_spkrs**2)
],
1,
) # (B, num_spkrs^2)
Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/pytorch_backend/e2e_asr_mix_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def forward(self, xs_pad, ilens, ys_pad):
hs_len[i // self.num_spkrs],
ys_pad[i % self.num_spkrs],
)
for i in range(self.num_spkrs ** 2)
for i in range(self.num_spkrs**2)
],
dim=1,
) # (B, num_spkrs^2)
Expand Down
4 changes: 2 additions & 2 deletions espnet/nets/pytorch_backend/e2e_mt_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ def reset_parameters(self, args):
"""Initialize parameters."""
initialize(self, args.transformer_init)
torch.nn.init.normal_(
self.encoder.embed[0].weight, mean=0, std=args.adim ** -0.5
self.encoder.embed[0].weight, mean=0, std=args.adim**-0.5
)
torch.nn.init.constant_(self.encoder.embed[0].weight[self.pad], 0)
torch.nn.init.normal_(
self.decoder.embed[0].weight, mean=0, std=args.adim ** -0.5
self.decoder.embed[0].weight, mean=0, std=args.adim**-0.5
)
torch.nn.init.constant_(self.decoder.embed[0].weight[self.pad], 0)

Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/pytorch_backend/e2e_st_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def reset_parameters(self, args):
initialize(self, args.transformer_init)
if self.mt_weight > 0:
torch.nn.init.normal_(
self.encoder_mt.embed[0].weight, mean=0, std=args.adim ** -0.5
self.encoder_mt.embed[0].weight, mean=0, std=args.adim**-0.5
)
torch.nn.init.constant_(self.encoder_mt.embed[0].weight[self.pad], 0)

Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/pytorch_backend/e2e_tts_tacotron2.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _make_guided_attention_mask(ilen, olen, sigma):
grid_x, grid_y = torch.meshgrid(torch.arange(olen), torch.arange(ilen))
grid_x, grid_y = grid_x.float().to(olen.device), grid_y.float().to(ilen.device)
return 1.0 - torch.exp(
-((grid_y / ilen - grid_x / olen) ** 2) / (2 * (sigma ** 2))
-((grid_y / ilen - grid_x / olen) ** 2) / (2 * (sigma**2))
)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/pytorch_backend/frontends/dnn_beamformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def forward(
psd = (psd.sum(dim=-1) / (C - 1)).transpose(-1, -2)

# Calculate amplitude
psd_feat = (psd.real ** 2 + psd.imag ** 2) ** 0.5
psd_feat = (psd.real**2 + psd.imag**2) ** 0.5

# (B, C, F) -> (B, C, F2)
mlp_psd = self.mlp_psd(psd_feat)
Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/pytorch_backend/frontends/dnn_wpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def forward(

for i in range(self.iterations):
# Calculate power: (..., C, T)
power = enhanced.real ** 2 + enhanced.imag ** 2
power = enhanced.real**2 + enhanced.imag**2
if i == 0 and self.use_dnn_mask:
# mask: (B, F, C, T)
(mask,), _ = self.mask_est(enhanced, ilens)
Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/pytorch_backend/frontends/feature_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def forward(
h = x

# h: ComplexTensor(B, T, F) -> torch.Tensor(B, T, F)
h = h.real ** 2 + h.imag ** 2
h = h.real**2 + h.imag**2

h, _ = self.logmel(h, ilens)
if self.stats_file is not None:
Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/pytorch_backend/frontends/mask_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def forward(
xs = xs.permute(0, 2, 3, 1)

# Calculate amplitude: (B, C, T, F) -> (B, C, T, F)
xs = (xs.real ** 2 + xs.imag ** 2) ** 0.5
xs = (xs.real**2 + xs.imag**2) ** 0.5
# xs: (B, C, T, F) -> xs: (B * C, T, F)
xs = xs.contiguous().view(-1, xs.size(-2), xs.size(-1))
# ilens: (B,) -> ilens_: (B * C)
Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/pytorch_backend/wavenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def __init__(
self.upsampling_factor = upsampling_factor

self.dilations = [
2 ** i for i in range(self.dilation_depth)
2**i for i in range(self.dilation_depth)
] * self.dilation_repeat
self.receptive_field = (self.kernel_size - 1) * sum(self.dilations) + 1

Expand Down
4 changes: 2 additions & 2 deletions espnet/scheduler/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ def _add_arguments(parser: _PrefixParser):
def __init__(self, key, args):
"""Initialize class."""
super().__init__(key, args)
self.normalize = 1 / (self.warmup * self.warmup ** -1.5)
self.normalize = 1 / (self.warmup * self.warmup**-1.5)

def scale(self, step):
"""Scale of lr."""
step += 1 # because step starts from 0
return self.normalize * min(step ** -0.5, step * self.warmup ** -1.5)
return self.normalize * min(step**-0.5, step * self.warmup**-1.5)


@register_scheduler
Expand Down
2 changes: 1 addition & 1 deletion espnet/transform/add_deltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def delta(feat, window):
delta_feat[i:] += -i * feat[:-i]
delta_feat[-i:] += i * feat[-1]
delta_feat[:i] += -i * feat[0]
delta_feat /= 2 * sum(i ** 2 for i in range(1, window + 1))
delta_feat /= 2 * sum(i**2 for i in range(1, window + 1))
return delta_feat


Expand Down
4 changes: 2 additions & 2 deletions espnet/transform/cmvn.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ def __repr__(self):

def __call__(self, x, uttid=None):
# x: [Time, Dim]
square_sums = (x ** 2).sum(axis=0)
square_sums = (x**2).sum(axis=0)
mean = x.mean(axis=0)

if self.norm_means:
x = np.subtract(x, mean)

if self.norm_vars:
var = square_sums / x.shape[0] - mean ** 2
var = square_sums / x.shape[0] - mean**2
std = np.maximum(np.sqrt(var), self.std_floor)
x = np.divide(x, std)

Expand Down
4 changes: 2 additions & 2 deletions espnet/transform/perturb.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def __call__(self, x, uttid=None, train=True):

if self.dbunit:
ratio = 10 ** (ratio / 20)
scale = ratio * numpy.sqrt((x ** 2).mean())
scale = ratio * numpy.sqrt((x**2).mean())

# 2. Get noise
if self.utt2noise is not None:
Expand All @@ -281,7 +281,7 @@ def __call__(self, x, uttid=None, train=True):
# Randomly select the noise source
noise = self.state.choice(list(self.utt2noise.values()))
# Normalize the level
noise /= numpy.sqrt((noise ** 2).mean())
noise /= numpy.sqrt((noise**2).mean())

# Adjust the noise length
diff = abs(len(x) - len(noise))
Expand Down
2 changes: 1 addition & 1 deletion espnet2/asr/frontend/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def forward(

# 4. STFT -> Power spectrum
# h: ComplexTensor(B, T, F) -> torch.Tensor(B, T, F)
input_power = input_stft.real ** 2 + input_stft.imag ** 2
input_power = input_stft.real**2 + input_stft.imag**2

# 5. Feature transform e.g. Stft -> Log-Mel-Fbank
# input_power: (Batch, [Channel,] Length, Freq)
Expand Down
2 changes: 1 addition & 1 deletion espnet2/enh/layers/dnn_wpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def forward(

for i in range(self.iterations):
# Calculate power: (..., C, T)
power = [enh.real ** 2 + enh.imag ** 2 for enh in enhanced]
power = [enh.real**2 + enh.imag**2 for enh in enhanced]
if i == 0 and self.use_dnn_mask:
# mask: (B, F, C, T)
masks, _ = self.mask_est(data, ilens)
Expand Down
2 changes: 1 addition & 1 deletion espnet2/enh/layers/mask_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def forward(

# Calculate amplitude: (B, C, T, F) -> (B, C, T, F)
if is_complex(xs):
xs = (xs.real ** 2 + xs.imag ** 2) ** 0.5
xs = (xs.real**2 + xs.imag**2) ** 0.5
# xs: (B, C, T, F) -> xs: (B * C, T, F)
xs = xs.contiguous().view(-1, xs.size(-2), xs.size(-1))
# ilens: (B,) -> ilens_: (B * C)
Expand Down
2 changes: 1 addition & 1 deletion espnet2/enh/layers/tcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
for r in range(R):
blocks = []
for x in range(X):
dilation = 2 ** x
dilation = 2**x
padding = (P - 1) * dilation if causal else (P - 1) * dilation // 2
blocks += [
TemporalBlock(
Expand Down
2 changes: 1 addition & 1 deletion espnet2/enh/layers/wpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_power(signal, dim=-2) -> torch.Tensor:
Power with shape (F, T)
"""
power = signal.real ** 2 + signal.imag ** 2
power = signal.real**2 + signal.imag**2
power = power.mean(dim=dim)
return power

Expand Down
4 changes: 2 additions & 2 deletions espnet2/enh/loss/criterions/tf_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ def forward(self, ref, inf) -> torch.Tensor:

diff = ref - inf
if is_complex(diff):
mseloss = diff.real ** 2 + diff.imag ** 2
mseloss = diff.real**2 + diff.imag**2
else:
mseloss = diff ** 2
mseloss = diff**2
if ref.dim() == 3:
mseloss = mseloss.mean(dim=[1, 2])
elif ref.dim() == 4:
Expand Down
6 changes: 3 additions & 3 deletions espnet2/enh/loss/criterions/time_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ def forward(
# s_target = <s', s>s / ||s||^2
pair_wise_dot = torch.sum(s_estimate * s_target, dim=1, keepdim=True) # [B, 1]
s_target_energy = (
torch.sum(s_target ** 2, dim=1, keepdim=True) + self.eps
torch.sum(s_target**2, dim=1, keepdim=True) + self.eps
) # [B, 1]
pair_wise_proj = pair_wise_dot * s_target / s_target_energy # [B, T]
# e_noise = s' - s_target
e_noise = s_estimate - pair_wise_proj # [B, T]

# SI-SNR = 10 * log_10(||s_target||^2 / ||e_noise||^2)
pair_wise_si_snr = torch.sum(pair_wise_proj ** 2, dim=1) / (
torch.sum(e_noise ** 2, dim=1) + self.eps
pair_wise_si_snr = torch.sum(pair_wise_proj**2, dim=1) / (
torch.sum(e_noise**2, dim=1) + self.eps
)
pair_wise_si_snr = 10 * torch.log10(pair_wise_si_snr + self.eps) # [B]

Expand Down
2 changes: 1 addition & 1 deletion espnet2/gan_tts/hifigan/hifigan.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(
**nonlinear_activation_params
),
torch.nn.ConvTranspose1d(
channels // (2 ** i),
channels // (2**i),
channels // (2 ** (i + 1)),
upsample_kernel_sizes[i],
upsample_scales[i],
Expand Down
4 changes: 2 additions & 2 deletions espnet2/gan_tts/melgan/melgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(
]
layers += [
torch.nn.ConvTranspose1d(
channels // (2 ** i),
channels // (2**i),
channels // (2 ** (i + 1)),
upsample_scale * 2,
stride=upsample_scale,
Expand All @@ -100,7 +100,7 @@ def __init__(
ResidualStack(
kernel_size=stack_kernel_size,
channels=channels // (2 ** (i + 1)),
dilation=stack_kernel_size ** j,
dilation=stack_kernel_size**j,
bias=bias,
nonlinear_activation=nonlinear_activation,
nonlinear_activation_params=nonlinear_activation_params,
Expand Down
4 changes: 2 additions & 2 deletions espnet2/gan_tts/parallel_wavegan/parallel_wavegan.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _apply_weight_norm(m: torch.nn.Module):

@staticmethod
def _get_receptive_field_size(
layers, stacks, kernel_size, dilation=lambda x: 2 ** x
layers, stacks, kernel_size, dilation=lambda x: 2**x
):
assert layers % stacks == 0
layers_per_cycle = layers // stacks
Expand Down Expand Up @@ -289,7 +289,7 @@ def __init__(
if i == 0:
dilation = 1
else:
dilation = i if dilation_factor == 1 else dilation_factor ** i
dilation = i if dilation_factor == 1 else dilation_factor**i
conv_in_channels = conv_channels
padding = (kernel_size - 1) // 2 * dilation
conv_layer = [
Expand Down
4 changes: 2 additions & 2 deletions espnet2/gan_tts/vits/duration_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def forward(
(F.logsigmoid(z_u) + F.logsigmoid(-z_u)) * x_mask, [1, 2]
)
logq = (
torch.sum(-0.5 * (math.log(2 * math.pi) + (e_q ** 2)) * x_mask, [1, 2])
torch.sum(-0.5 * (math.log(2 * math.pi) + (e_q**2)) * x_mask, [1, 2])
- logdet_tot_q
)

Expand All @@ -169,7 +169,7 @@ def forward(
z, logdet = flow(z, x_mask, g=x, inverse=inverse)
logdet_tot = logdet_tot + logdet
nll = (
torch.sum(0.5 * (math.log(2 * math.pi) + (z ** 2)) * x_mask, [1, 2])
torch.sum(0.5 * (math.log(2 * math.pi) + (z**2)) * x_mask, [1, 2])
- logdet_tot
)
return nll + logq # (B,)
Expand Down
2 changes: 1 addition & 1 deletion espnet2/gan_tts/vits/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __init__(

self.convs = torch.nn.ModuleList()
for i in range(layers):
dilation = kernel_size ** i
dilation = kernel_size**i
padding = (kernel_size * dilation - dilation) // 2
self.convs += [
torch.nn.Sequential(
Expand Down
Loading

0 comments on commit 23a537e

Please sign in to comment.