Giter VIP home page Giter VIP logo

pointer-network-tensorflow's Introduction

Pointer Networks in Tensorflow

TensorFlow implementation of Pointer Networks.

model

Support multithreaded data pipelines to reduce I/O latency.

Requirements

Usage

To train a model:

$ python main.py --task=tsp --max_data_length=20 --hidden_dim=512 # download dataset used in the paper
$ python main.py --task=tsp --max_data_length=10 --hidden_dim=128 # generate dataset itself

To train a model:

$ python main.py
$ tensorboard --logdir=logs --host=0.0.0.0

To test a model:

$ python main.py --is_train=False

Results

Train/Test loss of max_data_length=10 after 24,000 steps:

$ python main.py --task=tsp --max_data_length=10 --hidden_dim=128
$ ...
$ 2017-01-18 17:17:48,054:INFO::
$ 2017-01-18 17:17:48,054:INFO::test loss: 0.00149279157631
$ 2017-01-18 17:17:48,055:INFO::test pred: [1 6 2 5 4 3 0 0 0 0 0]
$ 2017-01-18 17:17:48,057:INFO::test true: [1 6 2 5 4 3 0 0 0 0 0] (True)
$ 2017-01-18 17:17:48,059:INFO::test pred: [1 3 8 4 7 5 2 6 0 0 0]
$ 2017-01-18 17:17:48,059:INFO::test true: [1 3 8 4 7 5 2 6 0 0 0] (True)
$ 2017-01-18 17:17:48,058:INFO::test pred: [ 1  8  3  7  9  5  6  4  2 10  0]
$ 2017-01-18 17:17:48,058:INFO::test true: [ 1  8  3  7  9  5  6  4  2 10  0] (True)

model

Train/Test loss of max_data_length=20 after 16,000 steps:

$ python main.py --task=tsp --max_data_length=20 --hidden_dim=512
$ ...
$ 2017-01-18 17:30:44,738:INFO::
$ 2017-01-18 17:30:44,739:INFO::test loss: 0.0501566007733
$ 2017-01-18 17:30:44,739:INFO::test pred: [ 1  3 16 18  6  2  7  4  5 15 10  8 13 11 17 20 19 14  9 12  0]
$ 2017-01-18 17:30:44,740:INFO::test true: [ 1  3 16 18  6  2  7  4  5 15 10  8 13 11 17 20 19 14  9 12  0] (True)
$ 2017-01-18 17:30:44,741:INFO::test pred: [ 1  4 12  8  2 17 20  3 18 14 16 11 13 15  7 10  9  6 19  5  0]
$ 2017-01-18 17:30:44,741:INFO::test true: [ 1  4 12  8  2 17 20  3 18 14 16 11 13 15  7 10  9  6 19  5  0] (True)
$ 2017-01-18 17:30:44,742:INFO::test pred: [ 1  8 16 20 19 14 18  2  9 12 15 11  3 13  5  6  7  4 17 10  0]
$ 2017-01-18 17:30:44,742:INFO::test true: [ 1  8 16 20 19 14 18  2  9 12 15 11  3 13  5  6  7  4 17 10  0] (True)

model

Author

Taehoon Kim / @carpedm20

pointer-network-tensorflow's People

Contributors

carpedm20 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pointer-network-tensorflow's Issues

function of index_matrix_to_pairs() is different from the comment?

the comment is:[[3,1,2], [2,3,1]] -> [[[0, 3], [1, 1], [2, 2]], [[0, 2], [1, 3], [2, 1]]]

but when I test it, it output this:[[[0 3],[0 1],[0 2]],[[1 2],[1 3],[1 1]]]

this is test code:

with tf.Session():
,,,,,,,print index_matrix_to_pairs(tf.constant([[3,1,2], [2,3,1]])).eval()

has no attribute dynamic_rnn_decoder

File "xxx/project/PycharmProjects/seq2sql/pointer-network/pointer-network-tensorflow/layers.py", line 22, in
dynamic_rnn_decoder = tf.contrib.seq2seq.dynamic_rnn_decoder
AttributeError: 'module' object has no attribute 'dynamic_rnn_decoder'

print tensorflow.version
1.0.0

line 125 of data_loader.py

hi,because in the code, all data has been filled with zeros, then seq_length = tf.shape(inputs)[0] should be the same, I think it should be calculated after removing all zero rows?

can not run in tensorflow 0.12.1

When I run the main.py, getting the following errors:
Traceback (most recent call last):
File "main.py", line 5, in
from trainer import Trainer
File "/Users/peng.huangp/github/pointer-network-tensorflow/trainer.py", line 7, in
from model import Model
File "/Users/peng.huangp/github/pointer-network-tensorflow/model.py", line 4, in
from layers import *
File "/Users/peng.huangp/github/pointer-network-tensorflow/layers.py", line 22, in
dynamic_rnn_decoder = tf.contrib.seq2seq.dynamic_rnn_decoder
AttributeError: 'module' object has no attribute 'dynamic_rnn_decoder'

I check 0.1.2.1 API of tensorflow, and can not find the definition for 'dynamic_rnn_decoder', and it is in the 0.1.0 API

question about model.py

Hi,

I am reading the pointer-network codes. However, I have a question in model.py file. In model.py, line 133-134, you gathered enc_output into dec_inputs. But in the original paper, it seems that the decoder inputs should be from enc_inputs.

133 self.embeded_dec_inputs = tf.stop_gradient(
134 tf.gather_nd(self.enc_outputs, self.idx_pairs))

Could you explain this a little bit?

Best,
Zhe

About the xrange

In layers.py, can the 'xrange' change to 'range'? We want to use Python3.6

A problem in the layers.index_matrix_to_pairs function

Hi,
Thanks for your code sharing.
But I found there are some problems in layers.index_matrix_to_pairs function:
By using the original code, I can't get
[[[0, 3], [1, 1], [2, 2]],
[[0, 2], [1, 3], [2, 1]]]
while inputing [[3,1,2], [2,3,1]].

It works, after I change the code to:

def index_matrix_to_pairs(index_matrix):
# [[3,1,2], [2,3,1]] -> [[[0, 3], [1, 1], [2, 2]],
# [[0, 2], [1, 3], [2, 1]]]
replicated_first_indices = tf.range(tf.shape(index_matrix)[1])
rank = len(index_matrix.get_shape())
if rank == 2:
replicated_first_indices = tf.tile(
tf.expand_dims(replicated_first_indices, dim=0),
[tf.shape(index_matrix)[0], 1]
)
return tf.stack([replicated_first_indices, index_matrix], axis=rank)

I don't know either the given example or the code is wrong.

question about test

with the program , l can train my data, but l can't test my data, It has a RuntimeError: Coordinator stopped with threads still running: Thread-11 Thread-12...can you give me some suggestion about it

Training data is never used

Below is line 40 and line 45 in model.py. The is_training variable is always set to False without changing based on config.

`

self.is_training = tf.placeholder_with_default(
    tf.constant(False, dtype=tf.bool),
    shape=(), name='is_training'
)

self.enc_inputs, self.dec_targets, self.enc_seq_length, self.dec_seq_length, self.mask = 
    smart_cond(
        self.is_training,
        lambda: (inputs['train'], labels['train'], enc_seq_length['train'],
                 dec_seq_length['train'], mask['train']),
        lambda: (inputs['test'], labels['test'], enc_seq_length['test'],
                 dec_seq_length['test'], mask['test'])
    )

`

Import errors with tensorflow version 0.12.1

Hi,

I just cloned your repo and downloaded tensorflow version 0.12.1. I am trying to run your example code. I am getting errors on the imports:

Traceback (most recent call last):
File "main.py", line 5, in
from trainer import Trainer
File ".../pointer-network-tensorflow/trainer.py", line 7, in
from model import Model
File ".../pointer-network-tensorflow/model.py", line 4, in
from layers import *
File ".../pointer-network-tensorflow/layers.py", line 7, in
LSTMCell = rnn.LSTMCell
AttributeError: 'module' object has no attribute 'LSTMCell'.

From looking at the tensorflow docs it seems that LSTMCell is now located at:
tf.nn.rnn_cell.STMCell. I changed the code to read: LSTMCell = tf.nn.rnn_cell.LSTMCell and made a similar change for the next line of layers.py: MultiRNNCell = tf.nn.rnn_cell.MultiRNNCell.

I'm now getting a similar error on the seq2seq line, and can't figure out how to fix it:
Traceback (most recent call last):
File "main.py", line 5, in
from trainer import Trainer
File ".../pointer-network-tensorflow/trainer.py", line 7, in
from model import Model
File ".../pointer-network-tensorflow/model.py", line 4, in
from layers import *
File ".../pointer-network-tensorflow/layers.py", line 9, in
dynamic_rnn_decoder = seq2seq.dynamic_rnn_decoder
AttributeError: 'module' object has no attribute 'dynamic_rnn_decoder'

It seems that tensorflow.contrib.seq2seq exists but does not have a dynamic_rnn_decoder function in version 12.1.0? Can you confirm that this is still working on your version and that you are in fact using tensorflow version 12.1.0.

Thanks!
Maddie

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.