Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test and Travis-CI #20

Merged
merged 18 commits into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/nets/e2e_asr_attctc_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ def forward(self, enc_hs_pad, enc_hs_len, dec_z, att_prev, scaling=2.0):
self.enc_h = enc_hs_pad # utt x frame x hdim
self.h_length = self.enc_h.shape[1]
# utt x frame x att_dim
self.pre_compute_enc_h = linear_tensor(self.mlp_enc, self.enc_h)
self.pre_compute_enc_h = torch.tanh(linear_tensor(self.mlp_enc, self.enc_h))

if dec_z is None:
dec_z = Variable(enc_hs_pad.data.new(batch, self.dunits).zero_())
Expand Down Expand Up @@ -469,7 +469,7 @@ def forward(self, enc_hs_pad, enc_hs_len, dec_z, att_prev, scaling=2.0):
self.enc_h = enc_hs_pad # utt x frame x hdim
self.h_length = self.enc_h.shape[1]
# utt x frame x att_dim
self.pre_compute_enc_h = linear_tensor(self.mlp_enc, self.enc_h)
self.pre_compute_enc_h = torch.tanh(linear_tensor(self.mlp_enc, self.enc_h))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tanh op is performed for only AttDot in Chainer.
I think it is not needed for AttLoc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh that is right


if dec_z is None:
dec_z = Variable(enc_hs_pad.data.new(batch, self.dunits).zero_())
Expand Down Expand Up @@ -509,10 +509,11 @@ def forward(self, enc_hs_pad, enc_hs_len, dec_z, att_prev, scaling=2.0):


def th_accuracy(y_all, pad_target, ignore_label):
acc = 0
pad_pred = y_all.data.view(pad_target.size(0), pad_target.size(1), y_all.size(1)).max(2)[1]
mask = pad_target.data != ignore_label
return torch.sum(pad_pred.masked_select(mask) == pad_target.data.masked_select(mask)) / torch.sum(mask)
numerator = torch.sum(pad_pred.masked_select(mask) == pad_target.data.masked_select(mask))
denominator = torch.sum(mask)
return float(numerator) / float(denominator)


# ------------- Decoder Network ----------------------------------------------------------------------------------------
Expand Down Expand Up @@ -601,8 +602,8 @@ def forward(self, hpad, hlen, ys):
for (i, y_hat_), y_true_ in zip(enumerate(y_hat.data.cpu().numpy()), y_true.data.cpu().numpy()):
if i == MAX_DECODER_OUTPUT:
break
idx_hat = np.argmax(y_hat_[y_true_ != -1], axis=1)
idx_true = y_true_[y_true_ != -1]
idx_hat = np.argmax(y_hat_[y_true_ != self.ignore_id], axis=1)
idx_true = y_true_[y_true_ != self.ignore_id]
seq_hat = [self.char_list[int(idx)] for idx in idx_hat]
seq_true = [self.char_list[int(idx)] for idx in idx_true]
seq_hat = "".join(seq_hat)
Expand Down
1 change: 1 addition & 0 deletions test/test_torch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
pytest.importorskip('torch')
import torch
from torch.autograd import Variable
from e2e_asr_attctc_th import pad_list, mask_by_length


Expand Down