8000 resolving padding issue by rainyrainyguo · Pull Request #18 · jakezhaojb/ARAE · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

resolving padding issue #18

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 sen 8000 d you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lang/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def forward(self, indices, lengths, noise, encode_only=False):

def encode(self, indices, lengths, noise):
embeddings = self.embedding(indices)
packed_embeddings = pack_padded_sequence(input=embeddings,
packed_embeddings = pack_padded_sequence(embeddings,
lengths=lengths,
batch_first=True)

Expand All @@ -195,7 +195,7 @@ def encode(self, indices, lengths, noise):
hidden = hidden / torch.norm(hidden, p=2, dim=1, keepdim=True)

if noise and self.noise_r > 0:
gauss_noise = torch.normal(means=torch.zeros(hidden.size()),
gauss_noise = torch.normal(mean=torch.zeros(hidden.size()),
std=self.noise_r)
hidden = hidden + Variable(gauss_noise.cuda())

Expand All @@ -213,7 +213,7 @@ def decode(self, hidden, batch_size, maxlen, indices=None, lengths=None):

embeddings = self.embedding_decoder(indices)
augmented_embeddings = torch.cat([embeddings, all_hidden], 2)
packed_embeddings = pack_padded_sequence(input=augmented_embeddings,
packed_embeddings = pack_padded_sequence(augmented_embeddings,
lengths=lengths,
batch_first=True)

Expand Down
12 changes: 6 additions & 6 deletions yelp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def forward(self, whichdecoder, indices, lengths, noise=False, encode_only=False

def encode(self, indices, lengths, noise):
embeddings = self.embedding(indices)
packed_embeddings = pack_padded_sequence(input=embeddings,
packed_embeddings = pack_padded_sequence(embeddings,
lengths=lengths,
batch_first=True)

Expand All @@ -175,7 +175,7 @@ def encode(self, indices, lengths, noise):
# hidden = torch.div(hidden, norms.unsqueeze(1).expand_as(hidden))

if noise and self.noise_r > 0:
gauss_noise = torch.normal(means=torch.zeros(hidden.size()),
gauss_noise = torch.normal(mean=torch.zeros(hidden.size()),
std=self.noise_r)
hidden = hidden + to_gpu(self.gpu, Variable(gauss_noise))

Expand All @@ -197,7 +197,7 @@ def decode(self, whichdecoder, hidden, batch_size, maxlen, indices=None, lengths
embeddings = self.embedding_decoder2(indices)

augmented_embeddings = torch.cat([embeddings, all_hidden], 2)
packed_embeddings = pack_padded_sequence(input=augmented_embeddings,
packed_embeddings = pack_padded_sequence(augmented_embeddings,
lengths=lengths,
batch_first=True)

Expand Down Expand Up @@ -443,7 +443,7 @@ def forward(self, indices, lengths, noise, encode_only=False):

def encode(self, indices, lengths, noise):
embeddings = self.embedding(indices)
packed_embeddings = pack_padded_sequence(input=embeddings,
packed_embeddings = pack_padded_sequence(embeddings,
lengths=lengths,
batch_first=True)

Expand All @@ -463,7 +463,7 @@ def encode(self, indices, lengths, noise):
# hidden = torch.div(hidden, norms.unsqueeze(1).expand_as(hidden))

if noise and self.noise_r > 0:
gauss_noise = torch.normal(means=torch.zeros(hidden.size()),
gauss_noise = torch.normal(mean=torch.zeros(hidden.size()),
std=self.noise_r)
hidden = hidden + to_gpu(self.gpu, Variable(gauss_noise))

Expand All @@ -481,7 +481,7 @@ def decode(self, hidden, batch_size, maxlen, indices=None, lengths=None):

embeddings = self.embedding_decoder(indices)
augmented_embeddings = torch.cat([embeddings, all_hidden], 2)
packed_embeddings = pack_padded_sequence(input=augmented_embeddings,
packed_embeddings = pack_padded_sequence(augmented_embeddings,
46C0 lengths=lengths,
batch_first=True)

Expand Down
0