Skip to content

Commit

Permalink
Update by following reviewer's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
xinghai-sun committed Sep 12, 2017
1 parent 69b4bda commit 5510dad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 1 addition & 5 deletions mt_with_external_memory/external_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ def __init__(self,
self.readonly = readonly
self.enable_interpolation = enable_interpolation
self.external_memory = paddle.layer.memory(
name=self.name,
size=self.mem_slot_size,
is_seq=True,
boot_layer=boot_layer)
name=self.name, size=self.mem_slot_size, boot_layer=boot_layer)
# prepare a constant (zero) intializer for addressing weights
self.zero_addressing_init = paddle.layer.slope_intercept(
input=paddle.layer.fc(input=boot_layer, size=1),
Expand Down Expand Up @@ -114,7 +111,6 @@ def _interpolation(self, head_name, key_vector, addressing_weight):
last_addressing_weight = paddle.layer.memory(
name=self.name + "_addressing_weight_" + head_name,
size=1,
is_seq=True,
boot_layer=self.zero_addressing_init)
interpolated_weight = paddle.layer.interpolation(
name=self.name + "_addressing_weight_" + head_name,
Expand Down
5 changes: 3 additions & 2 deletions mt_with_external_memory/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import argparse
import gzip
import paddle.v2 as paddle

from external_memory import ExternalMemory
from model import *
from data_utils import *
from model import memory_enhanced_seq2seq
from data_utils import reader_append_wrapper

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
Expand Down
2 changes: 1 addition & 1 deletion mt_with_external_memory/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def recurrent_decoder_step(cur_embedding):
input=decoder_result, label=target)
return cost
else:
target_embeddings = paddle.layer.GeneratedInputV2(
target_embeddings = paddle.layer.GeneratedInput(
size=dict_size,
embedding_name="_decoder_word_embedding",
embedding_size=word_vec_dim)
Expand Down
17 changes: 10 additions & 7 deletions mt_with_external_memory/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import gzip
import distutils.util
import random

import paddle.v2 as paddle
from external_memory import ExternalMemory
from model import *
from data_utils import *
from model import memory_enhanced_seq2seq
from data_utils import reader_append_wrapper

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
Expand Down Expand Up @@ -65,6 +66,12 @@ def train():
"""
For training.
"""
# create optimizer
optimizer = paddle.optimizer.Adam(
learning_rate=5e-5,
gradient_clipping_threshold=5,
regularization=paddle.optimizer.L2Regularization(rate=8e-4))

# create network config
source_words = paddle.layer.data(
name="source_words",
Expand All @@ -85,12 +92,8 @@ def train():
is_generating=False,
beam_size=None)

# create parameters and optimizer
# create parameters and trainer
parameters = paddle.parameters.create(cost)
optimizer = paddle.optimizer.Adam(
learning_rate=5e-5,
gradient_clipping_threshold=5,
regularization=paddle.optimizer.L2Regularization(rate=8e-4))
trainer = paddle.trainer.SGD(
cost=cost, parameters=parameters, update_equation=optimizer)

Expand Down

0 comments on commit 5510dad

Please sign in to comment.