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

Fix bugs of mt_with_external_memory #282

Merged
merged 5 commits into from
Sep 21, 2017
Merged
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 mt_with_external_memory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
(详情请参考论文\[[1](#参考文献)\])。根据寻址情况,图灵机写入 $M$ 或从 $M$ 读出信息,供其他网络使用。神经图灵机结构示意图,见图3,引自\[[1](#参考文献)\]。

<div align="center">
<img src="image/neural_turing_machine_arch.png"><br/>
<img src="image/neural_turing_machine_arch.png" width="400"><br/>
图3. 神经图灵机结构示意图
</div>

Expand Down Expand Up @@ -440,15 +440,15 @@ python infer.py
或自定义部分参数, 例如:

```bash
python train.py \
python infer.py \
--dict_size 30000 \
--word_vec_dim 512 \
--hidden_size 1024 \
--memory_slot_num 8 \
--use_gpu False \
--trainer_count 1 \
--memory_perturb_stddev 0.1 \
--infer_num_data 10 \
--infer_data_num 10 \
--model_filepath checkpoints/params.latest.tar.gz \
--beam_size 3
```
Expand Down
2 changes: 1 addition & 1 deletion mt_with_external_memory/external_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _interpolation(self, head_name, key_vector, addressing_weight):
boot_layer=self.initial_weight)
interpolated_weight = paddle.layer.interpolation(
name=self.name + "_addressing_weight_" + head_name,
input=[addressing_weight, addressing_weight],
input=[last_addressing_weight, addressing_weight],
weight=paddle.layer.expand(input=gate, expand_as=addressing_weight))
return interpolated_weight

Expand Down
Binary file modified mt_with_external_memory/image/memory_enhanced_decoder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified mt_with_external_memory/image/neural_turing_machine_arch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions mt_with_external_memory/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import distutils.util
import argparse
import gzip
import random

import paddle.v2 as paddle
from external_memory import ExternalMemory
Expand Down Expand Up @@ -118,10 +119,11 @@ def infer():
infer_data = []
random.seed(0) # for keeping consitancy for multiple runs
bounded_memory_perturbation = [[
random.gauss(0, memory_perturb_stddev) for i in xrange(args.hidden_size)
random.gauss(0, args.memory_perturb_stddev)
for i in xrange(args.hidden_size)
] for j in xrange(args.memory_slot_num)]
test_append_reader = reader_append_wrapper(
reader=paddle.dataset.wmt14.test(dict_size),
reader=paddle.dataset.wmt14.test(args.dict_size),
append_tuple=(bounded_memory_perturbation, ))
for i, item in enumerate(test_append_reader()):
if i < args.infer_data_num:
Expand All @@ -134,8 +136,8 @@ def infer():
input=infer_data,
field=['prob', 'id'])

# parse beam result and print
source_dict, target_dict = paddle.dataset.wmt14.get_dict(dict_size)
# parse beam result and print
source_dict, target_dict = paddle.dataset.wmt14.get_dict(args.dict_size)
beam_probs, beam_sentences = parse_beam_search_result(beam_result,
target_dict)
for i in xrange(args.infer_data_num):
Expand All @@ -147,7 +149,7 @@ def infer():


def main():
paddle.init(use_gpu=False, trainer_count=1)
paddle.init(use_gpu=args.use_gpu, trainer_count=args.trainer_count)
infer()


Expand Down