Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
1. Bridge class only has 2 params hidden size of encoder and decoder, but you declared 3 arguments: hidden size of encoder, decoder and activation function.
2. before define KbEncoder, you should judge use_kb since if use_kb is False, vocab_size is None which will cause ValueError.
  • Loading branch information
githwd2016 committed Jun 6, 2019
1 parent 503b481 commit 1c454be
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions modules/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ def __init__(self, src_vocab_size, tgt_vocab_size, src_emb_dim, tgt_emb_dim,
# Default to hidden_size = dec_hidden_size for now.
self.kb_emb_size = self.tgt_emb_dim
self.kb_hidden_size = self.dec_hidden_size
self.kb_encoder = KbEncoder(self.kb_size, self.kb_emb_size, self.kb_hidden_size,
rnn_type='GRU', num_layers=1, batch_first=True,
dropout=0, bidirectional=False)
# Same for kb and celebs for now.
self.celeb_encoder = KbEncoder(self.celeb_vec_size, self.kb_emb_size, self.kb_hidden_size,
rnn_type='GRU', num_layers=1, batch_first=True,
dropout=0, bidirectional=False)
if self.use_kb:
self.kb_encoder = KbEncoder(self.kb_size, self.kb_emb_size, self.kb_hidden_size,
rnn_type='GRU', num_layers=1, batch_first=True,
dropout=0, bidirectional=False)
# Same for kb and celebs for now.
self.celeb_encoder = KbEncoder(self.celeb_vec_size, self.kb_emb_size, self.kb_hidden_size,
rnn_type='GRU', num_layers=1, batch_first=True,
dropout=0, bidirectional=False)

# Initialize encoder
self.encoder = EncoderRNN(self.src_vocab_size, self.src_emb_dim, self.enc_hidden_size,
Expand All @@ -84,7 +85,8 @@ def __init__(self, src_vocab_size, tgt_vocab_size, src_emb_dim, tgt_emb_dim,
self.image_encoder = ImageEncoder(self.image_in_size, self.image_out_size)
# Initialize bridge layer
self.activation_bridge = activation_bridge
self.bridge = BridgeLayer(self.enc_hidden_size, self.dec_hidden_size, self.activation_bridge)
# self.bridge = BridgeLayer(self.enc_hidden_size, self.dec_hidden_size, self.activation_bridge)
self.bridge = BridgeLayer(self.enc_hidden_size, self.dec_hidden_size)
# Initialize context encoder
self.context_input_size = self.image_out_size + enc_hidden_size # image+text
self.context_encoder = ContextRNN(self.context_input_size, self.context_hidden_size,
Expand Down Expand Up @@ -240,13 +242,14 @@ def __init__(self, src_vocab_size, tgt_vocab_size, src_emb_dim, tgt_emb_dim,
# Default to hidden_size = dec_hidden_size for now.
self.kb_emb_size = self.tgt_emb_dim
self.kb_hidden_size = self.dec_hidden_size
self.kb_encoder = KbEncoder(self.kb_size, self.kb_emb_size, self.kb_hidden_size,
rnn_type='GRU', num_layers=1, batch_first=True,
dropout=0, bidirectional=False)
# Same for kb and celebs for now.
self.celeb_encoder = KbEncoder(self.celeb_vec_size, self.kb_emb_size, self.kb_hidden_size,
rnn_type='GRU', num_layers=1, batch_first=True,
dropout=0, bidirectional=False)
if self.use_kb:
self.kb_encoder = KbEncoder(self.kb_size, self.kb_emb_size, self.kb_hidden_size,
rnn_type='GRU', num_layers=1, batch_first=True,
dropout=0, bidirectional=False)
# Same for kb and celebs for now.
self.celeb_encoder = KbEncoder(self.celeb_vec_size, self.kb_emb_size, self.kb_hidden_size,
rnn_type='GRU', num_layers=1, batch_first=True,
dropout=0, bidirectional=False)


# Initialize encoder
Expand All @@ -256,7 +259,8 @@ def __init__(self, src_vocab_size, tgt_vocab_size, src_emb_dim, tgt_emb_dim,
# self.image_encoder = ImageEncoder(self.image_in_size, self.image_out_size)
# Initialize bridge layer
self.activation_bridge = activation_bridge
self.bridge = BridgeLayer(self.enc_hidden_size, self.dec_hidden_size, self.activation_bridge)
# self.bridge = BridgeLayer(self.enc_hidden_size, self.dec_hidden_size, self.activation_bridge)
self.bridge = BridgeLayer(self.enc_hidden_size, self.dec_hidden_size)
# Initialize context encoder
self.context_input_size = enc_hidden_size #self.image_out_size + enc_hidden_size # image+text
self.context_encoder = ContextRNN(self.context_input_size, self.context_hidden_size,
Expand Down

0 comments on commit 1c454be

Please sign in to comment.