Coder Social home page Coder Social logo

fold's Introduction

TensorFlow Fold

TensorFlow Fold is a library for creating TensorFlow models that consume structured data, where the structure of the computation graph depends on the structure of the input data. For example, this model implements TreeLSTMs for sentiment analysis on parse trees of arbitrary shape/size/depth.

Fold implements dynamic batching. Batches of arbitrarily shaped computation graphs are transformed to produce a static computation graph. This graph has the same structure regardless of what input it receives, and can be executed efficiently by TensorFlow.

animation

This animation shows a recursive neural network run with dynamic batching. Operations of the same type appearing at the same depth in the computation graph (indicated by color in the animiation) are batched together regardless of whether or not they appear in the same parse tree. The Embed operation converts words to vector representations. The fully connected (FC) operation combines word vectors to form vector representations of phrases. The output of the network is a vector representation of an entire sentence. Although only a single parse tree of a sentence is shown, the same network can run, and batch together operations, over multiple parse trees of arbitrary shapes and sizes. The TensorFlow concat, while_loop, and gather ops are created once, prior to variable initialization, by Loom, the low-level API for TensorFlow Fold.

If you'd like to contribute to TensorFlow Fold, please review the contribution guidelines.

TensorFlow Fold is not an official Google product.

fold's People

Contributors

afshinm avatar akimach avatar biogeek avatar delesley avatar mherreshoff avatar oychang 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  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

fold's Issues

Windows support

Are there plans for windows support in the works?

PyTorch is currently working on a windows port but there aren't any well supported DCG libraries out right now (to my knowledge) that support windows.

I'm really looking forward to trying this out!

Sequence of labels

Hi suppose I have an RNN where at each time step I have labels for the output, in this case how might I use fold to set up the computation graph. I am aware that we can get the last output state of the RNN using td.RNN, but is there a way to accomplish what I described?

Docker build

Is a docker build available? Since I only have an OsX machine on hand, it would really help my development process.

Inverse of td.Zip()?

td.Zip() takes a tuple of sequences and converts it to a sequence of tuples.

Is there a straightforward way to do the inverse of td.Zip()?

i.e. Take a sequence of tuples and converts it to a tuple of sequences.

Request for Sequence Concatenation

What the title says - I would love to be able to pad a sequence of tensors with some zero tensors of equivalent shape. This would help with building 'look-behind' input for an RNN, where the first few inputs to the RNN need to have some input representing 'the sequence hasn't started yet'.

I would be happy to help in writing this, if someone could give me a few pointers.

Thanks

TensorFlow for Python 3.3

Trying to get the follow to work:
pip3 install https://storage.googleapis.com/tensorflow_fold/tensorflow_fold-0.0.1-py3-none-linux_x86_64.whl, but seems like there's not support for TensorFlow in Python 3.3. Also there's a typo in the setup. The Python 3.3 instructions says pip, but it should be pip3`. Anyways, can't get this working for Python 3.3 since there doesn't seem to be support for TF in Python3.3.

How to concatenate sequences?

td.Concat only concatenates a tuple of tensors. But the output of td.Map is sequence. How can I concatenate it?

A_block = (td.Map(td.Scalar('int32') >> td.Function(td.Embedding(10, 4))) >> td.Reduce(td.Concat() >> td.Function(td.FC(4))))
result = td.Map(A_block) >> td.Concat()

TypeError: bad input type SequenceType for <td.Concat concat_dim=0 flatten=False>, expected TupleType

I tried to use td.Reduce(td.Concat()). But it will raise error, if I do not add td.FC(4).
result = td.Map(A_block) >> td.Reduce(td.Concat() >> td.FC(4))

How to concatenate a sequence and don't reduce to shape(4,) ? Thank you very much.

Stacking a sequence of vectors into a 2D tensor

Is there a way to do this? For example:

If the output of my block is SequenceType(TensorType((5,), 'float32')), is there a straightforward way to stack the sequence of vectors into a Tensor of shape (N,5) where N is the length of the sequence?

Thanks

1D Convolution with ScopedLayer

I'm trying to figure out how to use td.ScopedLayer() with tf.conv1d(). What am I doing wrong?

def conv1d_layer(x):
  return td.ScopedLayer(tf.nn.conv1d(x, tf.zeros([3, 1, 1]), stride=2, padding="VALID"))

test_seq = [[x for x in xrange(0,randint(1,10))] for v in xrange(randint(3,5))]

print((td.Map(td.Map(td.Scalar())) >> conv1d_layer).eval(test_seq))

Getting the following error:

Traceback (most recent call last):
  File "test.py", line 109, in 
    print((td.Map(td.Map(td.Scalar())) >> conv1d_layer).eval(test_seq))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow_fold/blocks/blocks.py", line 156, in __rshift__
    return Pipe(self, rhs)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow_fold/blocks/blocks.py", line 997, in Pipe
    return _pipe([convert_to_block(b) for b in blocks],
  File "/usr/local/lib/python2.7/dist-packages/tensorflow_fold/blocks/blocks.py", line 2036, in convert_to_block
    raise TypeError('%s cannot be converted to a block' % str(block_like))
TypeError: < function conv1d_layer at 0x7fc5e6c28320 > cannot be converted to a block

How to use td.Map with lambda

Assum that a is a sequence of number, b is a number and c is a number too.
How can I use Map and lambda to get a sequence of number [a1+b+c, a2+b+c, ... , an+b+c]
I think Map(Function(lambda x,y,z: x+y+x)) is not work?

Request for a simple and complete CNN example

Seems like a few people including myself are looking to understand how to use Fold for convolution. I've been bashing my head against this for a while now but haven't been able to figure it out and haven't received any satisfactory responses. Could one of the collaborators please provide a simple and complete example of how to handle arbitrary shaped data - both sequences and graphs/images - with a 1d convolution and 2d convolution? This would be incredibly beneficial for everyone and would really demonstrate the use of Fold. Thanks.

seg fault trying starter ipython notebook in ipython - linux

I just tried some of the notebook and I got a segfault. Here is what my session looks like, this is from ipython in a conda environment, will describe the environment below:

(ana-1.2.7-gpu) : ~ $ ipython
Python 2.7.12 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:42:40) 
Type "copyright", "credits" or "license" for more information.

IPython 5.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import random
   ...: import tensorflow as tf
   ...: sess = tf.InteractiveSession()
   ...: import tensorflow_fold as td
   ...: 
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: 
name: Tesla P100-PCIE-16GB
major: 6 minor: 0 memoryClockRate (GHz) 1.3285
pciBusID 0000:02:00.0
Total memory: 15.89GiB
Free memory: 15.61GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:02:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Tesla P100-PCIE-16GB, pci bus id: 0000:02:00.0)
In [2]: scalar_block = td.Scalar()
   ...: vector3_block = td.Vector(3)
   ...: 
   ...: 

In [3]: def block_info(block):
   ...:     print("%s: %s -> %s" % (block, block.input_type, block.output_type))
   ...:     
   ...: block_info(scalar_block)
   ...: block_info(vector3_block)
   ...: 
<td.Scalar dtype='float32'>: PyObjectType() -> TensorType((), 'float32')
<td.Vector dtype='float32' size=3>: PyObjectType() -> TensorType((3,), 'float32')

In [4]: scalar_block.eval(234)
Segmentation fault (core dumped)

I'm on red hat 7 - linux, working from a anaconda environment. I have

cudnn 5.1
tensorflow-gpu 1.0.1

which were done as proper conda packages, I made the packages myself -- I did not build tensorflow with bazel, use wrap the output of pip in a conda package.

Then I did a pip install to get tensorflow-fold 0.0.1, being to lazy to make a proper conda package out of it since I wanted to quickly try it.

Maybe it is some weird issue with the construction of the environment, but thought I'd mention it in case you haven't tested this combo - ipython/tensorflow-gpu/tensorflold

How to build from the source

Hi, I'm new player of bazel, I just know how to add submodule to tensorflow,
but for tensorflow_fold, I want to build it from its source, how to do it?

If you have time, please show me the way. Thanks

Convolution over sequence

Hi,

I'm trying to convolve a filter over a sequence block type and I'm not sure what the cannonical methodology is.

Thanks

Is it possible to store the output at every node of a tree-structured neural network?

Hi,
I'm trying to implement the attention mechanism on tree-structured neural networks, such as TreeLSTM or TreeGRU. Since we want to attend to the most informative nodes in the tree, we need to store the output (usually the hidden state) at each node first. I know that in Tensorflow, the dynamic_rnn function could return all the outputs besides the final state. Is it possible to achieve this in Tensorflow-Fold?
Thanks!

segmentation fault(core dumped) when eval()

Hi,

I installed tensorflow (python 2.7 GPU support) on Ubuntu 16.04 and the examples in the tensorflow tutorial seem to work well. I then install tensorflow_fold, it can be loaded successfully. But when the code goes to scalar_block.eval(42) in the quick.ipynb, i get the message segmentation fault(core dumped).

Hope for help! Thanks in advance.

`abc@518G1N:~$ su
Password:
root@518G1N:/home/abc# virtualenv TFenv
Running virtualenv with interpreter /usr/bin/python2
New python executable in /home/abc/TFenv/bin/python2
Also creating executable in /home/abc/TFenv/bin/python
Installing setuptools, pkg_resources, pip, wheel...done.
root@518G1N:/home/abc# source TFenv/bin/activate
(TFenv) root@518G1N:/home/abc# pip install --upgrade tensorflow-gpu
Collecting tensorflow-gpu
Using cached tensorflow_gpu-1.0.1-cp27-cp27mu-manylinux1_x86_64.whl
Collecting mock>=2.0.0 (from tensorflow-gpu)
Using cached mock-2.0.0-py2.py3-none-any.whl
Collecting numpy>=1.11.0 (from tensorflow-gpu)
Using cached numpy-1.12.0-cp27-cp27mu-manylinux1_x86_64.whl
Collecting protobuf>=3.1.0 (from tensorflow-gpu)
Using cached protobuf-3.2.0-cp27-cp27mu-manylinux1_x86_64.whl
Requirement already up-to-date: wheel in ./TFenv/lib/python2.7/site-packages (from tensorflow-gpu)
Requirement already up-to-date: six>=1.10.0 in ./TFenv/lib/python2.7/site-packages (from tensorflow-gpu)
Collecting funcsigs>=1; python_version < "3.3" (from mock>=2.0.0->tensorflow-gpu)
Using cached funcsigs-1.0.2-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock>=2.0.0->tensorflow-gpu)
Using cached pbr-2.0.0-py2.py3-none-any.whl
Requirement already up-to-date: setuptools in ./TFenv/lib/python2.7/site-packages (from protobuf>=3.1.0->tensorflow-gpu)
Requirement already up-to-date: appdirs>=1.4.0 in ./TFenv/lib/python2.7/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu)
Requirement already up-to-date: packaging>=16.8 in ./TFenv/lib/python2.7/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-gpu)
Requirement already up-to-date: pyparsing in ./TFenv/lib/python2.7/site-packages (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow-gpu)
Installing collected packages: funcsigs, pbr, mock, numpy, protobuf, tensorflow-gpu
Successfully installed funcsigs-1.0.2 mock-2.0.0 numpy-1.12.0 pbr-2.0.0 protobuf-3.2.0 tensorflow-gpu-1.0.1
(TFenv) root@518G1N:/home/abc# python /home/abc/TensorFlow1.0/fully_connected_feed.py
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting /tmp/tensorflow/mnist/input_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting /tmp/tensorflow/mnist/input_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting /tmp/tensorflow/mnist/input_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting /tmp/tensorflow/mnist/input_data/t10k-labels-idx1-ubyte.gz
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties:
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.8475
pciBusID 0000:03:00.0
Total memory: 7.92GiB
Free memory: 7.81GiB
W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x438d980
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 1 with properties:
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.8475
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 7.81GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 1
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: Y Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 1: Y Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:03:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
Step 0: loss = 2.34 (1.024 sec)
Step 100: loss = 2.13 (0.002 sec)
Step 200: loss = 1.93 (0.002 sec)
Step 300: loss = 1.55 (0.001 sec)
Step 400: loss = 1.35 (0.002 sec)
Step 500: loss = 0.92 (0.002 sec)
Step 600: loss = 0.73 (0.001 sec)
Step 700: loss = 0.71 (0.001 sec)
Step 800: loss = 0.68 (0.002 sec)
Step 900: loss = 0.80 (0.001 sec)
Training Data Eval:
Num examples: 55000 Num correct: 47536 Precision @ 1: 0.8643
Validation Data Eval:
Num examples: 5000 Num correct: 4345 Precision @ 1: 0.8690
Test Data Eval:
Num examples: 10000 Num correct: 8718 Precision @ 1: 0.8718
Step 1000: loss = 0.46 (0.002 sec)
Step 1100: loss = 0.56 (0.057 sec)
Step 1200: loss = 0.50 (0.002 sec)
Step 1300: loss = 0.41 (0.001 sec)
Step 1400: loss = 0.38 (0.001 sec)
Step 1500: loss = 0.41 (0.002 sec)
Step 1600: loss = 0.27 (0.002 sec)
Step 1700: loss = 0.38 (0.002 sec)
Step 1800: loss = 0.26 (0.001 sec)
Step 1900: loss = 0.39 (0.001 sec)
Training Data Eval:
Num examples: 55000 Num correct: 49240 Precision @ 1: 0.8953
Validation Data Eval:
Num examples: 5000 Num correct: 4516 Precision @ 1: 0.9032
Test Data Eval:
Num examples: 10000 Num correct: 9009 Precision @ 1: 0.9009
(TFenv) root@518G1N:/home/abc# pip install https://storage.googleapis.com/tensorflow_fold/tensorflow_fold-0.0.1-cp27-none-linux_x86_64.whl
Collecting tensorflow-fold==0.0.1 from https://storage.googleapis.com/tensorflow_fold/tensorflow_fold-0.0.1-cp27-none-linux_x86_64.whl
Using cached https://storage.googleapis.com/tensorflow_fold/tensorflow_fold-0.0.1-cp27-none-linux_x86_64.whl
Requirement already satisfied: mock>=2.0.0 in ./TFenv/lib/python2.7/site-packages (from tensorflow-fold==0.0.1)
Requirement already satisfied: numpy>=1.11.0 in ./TFenv/lib/python2.7/site-packages (from tensorflow-fold==0.0.1)
Collecting nltk>=3.0.0 (from tensorflow-fold==0.0.1)
Requirement already satisfied: protobuf>=3.1.0 in ./TFenv/lib/python2.7/site-packages (from tensorflow-fold==0.0.1)
Requirement already satisfied: wheel in ./TFenv/lib/python2.7/site-packages (from tensorflow-fold==0.0.1)
Requirement already satisfied: six>=1.10.0 in ./TFenv/lib/python2.7/site-packages (from tensorflow-fold==0.0.1)
Requirement already satisfied: funcsigs>=1; python_version < "3.3" in ./TFenv/lib/python2.7/site-packages (from mock>=2.0.0->tensorflow-fold==0.0.1)
Requirement already satisfied: pbr>=0.11 in ./TFenv/lib/python2.7/site-packages (from mock>=2.0.0->tensorflow-fold==0.0.1)
Requirement already satisfied: setuptools in ./TFenv/lib/python2.7/site-packages (from protobuf>=3.1.0->tensorflow-fold==0.0.1)
Requirement already satisfied: appdirs>=1.4.0 in ./TFenv/lib/python2.7/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-fold==0.0.1)
Requirement already satisfied: packaging>=16.8 in ./TFenv/lib/python2.7/site-packages (from setuptools->protobuf>=3.1.0->tensorflow-fold==0.0.1)
Requirement already satisfied: pyparsing in ./TFenv/lib/python2.7/site-packages (from packaging>=16.8->setuptools->protobuf>=3.1.0->tensorflow-fold==0.0.1)
Installing collected packages: nltk, tensorflow-fold
Successfully installed nltk-3.2.2 tensorflow-fold-0.0.1
(TFenv) root@518G1N:/home/abc# python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow as tf
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
sess = tf.InteractiveSession()
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties:
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.8475
pciBusID 0000:03:00.0
Total memory: 7.92GiB
Free memory: 7.81GiB
W tensorflow/stream_executor/cuda/cuda_driver.cc:590] creating context when one is currently active; existing: 0x2176c40
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 1 with properties:
name: GeForce GTX 1080
major: 6 minor: 1 memoryClockRate (GHz) 1.8475
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 7.81GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 1
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: Y Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 1: Y Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:03:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
import tensorflow_fold as td
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:03:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
scalar_block = td.Scalar()
vector3_block = td.Vector(3)
def block_info(block):
... print("%s: %s -> %s" % (block, block.input_type, block.output_type))
...
...
block_info(scalar_block)
<td.Scalar dtype='float32'>: PyObjectType() -> TensorType((), 'float32')
block_info(vector3_block)
<td.Vector dtype='float32' size=3>: PyObjectType() -> TensorType((3,), 'float32')
print scalar_block.eval(42)
Segmentation fault (core dumped)
(TFenv) root@518G1N:/home/abc#
(TFenv) root@518G1N:/home/abc#
(TFenv) root@518G1N:/home/abc# cat /proc/version
Linux version 4.4.0-66-generic (buildd@lgw01-28) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #87-Ubuntu SMP Fri Mar 3 15:29:05 UTC 2017
(TFenv) root@518G1N:/home/abc# nvidia-smi
Fri Mar 10 11:50:33 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 375.26 Driver Version: 375.26 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 1080 Off | 0000:01:00.0 Off | N/A |
| 65% 49C P0 43W / 200W | 0MiB / 8113MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
| 1 GeForce GTX 1080 Off | 0000:03:00.0 Off | N/A |
| 0% 47C P0 39W / 200W | 0MiB / 8113MiB | 2% Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
(TFenv) root@518G1N:/home/abc# python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

import tensorflow as tf
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
print tf.version
1.0.1
print tf.path
['/home/abc/TFenv/local/lib/python2.7/site-packages/tensorflow']

`

Not a supported wheel on this platform

I'm trying to install the pip package for Fold according to the instructions, but I'm getting an error saying that it's not supported. I'm running this in Virtualenv on OSX El Capitan version 10.11.3.
(python3_env) dhcp-wifi-8021x-155-41-72-88:~ ch3njust1n$ sudo -H pip install https://storage.googleapis.com/tensorflow_fold/tensorflow_fold-0.0.1-py3-none-linux_x86_64.whl

tensorflow_fold-0.0.1-py3-none-linux_x86_64.whl is not a supported wheel on this platform.

Is combination of two types of Neural Net (recursive NN & CNN) model available in tensorflow/fold?

Since the fold library receives a tree structured data as an input(of RNN), I find it hard to feed another input when I tried to use two inputs for two models.

What do I want to do?

I want to train two models, say Recursive NN and CNN, to classify the sentiment of a sentence.

What is the input format?

First input format for Recursive NN is a binary parsed tree, made from the stanford coreNLP, labels suggest (1 to 5) sentiment. I made up this example to classify the sentiment of the sentence.

ex1)

(4 (3 You) (3 (3 (3 can) (2 (5 trust) (4 stackoverflow))) (3 .)))

Second input would be just a sentence(same sentence with no parsing), for CNN.

ex2) You can trust stackoverflow.

Why is it challenging?

Sentiment example classify sentiment using recursive NN. And it seems that using CNN alone in the fold library is plausible.

def tokenize(s):
  label, phrase = s[1:-1].split(None, 1)
  return label, sexpr.sexpr_tokenize(phrase)

In the linked example, tokenize function(above) is the first function to receive inputs after feed process. I think I can concatenate the two inputs and pass it to the feed, then separate them later.

The problem is, the input for recursive NN model is tied to the model, which is computed node by node. A parent node computes its state vector using the state vectors of its two children(as the input is the binary tree). Following code snippet is taken from the linked example.

embed_subtree = td.ForwardDeclaration(name='embed_subtree')
...
def logits_and_state():
  ...
  pair2vec = (embed_subtree(), embed_subtree())
...
embed_subtree.resolve_to(embed_tree(logits_and_state(), is_root=False))
...

Since CNN requires the full sentence as its input, how can I feed the full sentence to the CNN module?

Actually, I posted this question to the stackoverflow first. I thought the stackoverflow was a better place to post application questions. Well.. I hope that the contributors of the fold library feel interested to this question.

Whether a word2vec block could be used twice

I define a block as below:
word2vec = Function(Embedding(100,100,name="word2vec"))
In rnn model , I use it to map the words in sentence to tensors.However , I also need to use it to map the labels to tensors in the same vector space.I got the error "word2vec is already a child of <td.Pipe>".Is there any way the use it twice?

Is it possible to do conditional branching during evaluation?

Hi, first of all, thanks for sharing this library. It's really awesome.

I was trying to implement Hierachical Multiscale Recurrent Neural Network, where the network will need to decide which path to take depending on the boundary gate from the previous time step and that of the lower layer.

At first, I thought this library is perfect fit for the task, but after reading the examples and the source code for loom and weaver, I get the impression that you would need to decide the structure of the graph for each input prior to evaluation, so weaver can figure out a efficient way to batch the inputs at each depth.

Which means weaver can't do much in the case of HMRNN, where the path each input take will depend on the intermediate values during evaluation. Is this understanding correct? Or is there a good way to implement this in Fold efficiently?

C++ integration of models built with Fold

I have seen that Fold is partially implemented in C++, but I'm not sure exactly what parts are. I am using TensorFlow to build and train models, "freeze" them into a self-contained GraphDef and export them to run in a C++ application. Currently I only need the C++ side of TensorFlow to run it. If I build a model with Fold, would I be able to export it in the same way and run it in C++? Or would I also need to include the C++ part of Flow into my application? Or maybe the best route would be to take the trained weights and put them into a simple TensorFlow model for exporting?

How to use images as input

Replace each input word with a different image on that cute animation on the first page. Replace 'embed' with a tf.nn.conv2d. That's what I want to try. Can it be done?

I tried to td.Function(tf.nn.conv2d) but it expects more arguments...

Implementation of seq2seq model (how?)

Hello, I am looking to use tf-fold for a seq2seq VAE.

I can see how the encoder might be implemented (with RNN), but I am struggling to find how you might go about producing a sequence from an RNN decoder, i.e. computing a value, then using the new hidden state to compute the next etc..

Could broadcast help here? Something like a scan function seems more appropriate.

from example in doc (my brain bug or tff bug ?)

Hello all,

I try to do this:

import tensorflow as tf
import tensorflow_fold as td

# Create RNN cells using the TensorFlow RNN library
char_cell = td.ScopedLayer(tf.contrib.rnn.BasicLSTMCell(num_units=16), 'char_cell')
word_cell = td.ScopedLayer(tf.contrib.rnn.BasicLSTMCell(num_units=32), 'word_cell')

# character LSTM converts a string to a word vector
char_lstm = (td.InputTransform(lambda s: [ord(c) for c in s]) >>
             td.Map(td.Scalar('int32') >>
                    td.Function(td.Embedding(128, 8))) >>
             td.RNN(char_cell))
# word LSTM converts a sequence of word vectors to a sentence vector.
# word_lstm = td.Map(char_lstm >> td.GetItem(1)) >> td.RNN(word_cell)

# ---------------------------------------------------------------------

sess = tf.InteractiveSession()

(
    td.Map(char_lstm >> td.GetItem(1)) >>
    td.RNN(word_cell)
).eval(["bon","ben"])

and i get:

(...)
/opt/conda/envs/python2/lib/python2.7/site-packages/tensorflow/contrib/rnn/python/ops/core_rnn_cell_impl.pyc in _linear(args, output_size, bias, bias_start, scope)
    729   # Calculate the total size of arguments on dimension 1.
    730   total_arg_size = 0
--> 731   shapes = [a.get_shape() for a in args]
    732   for shape in shapes:
    733     if shape.ndims != 2:

AttributeError: 'tuple' object has no attribute 'get_shape'

Type errors when using td.Compiler.init_loom() or eval()

Hi,

I kept getting the following message when using td.Compiler.init_loom() or eval():

"TypeError: Expected int32, got list containing Tensors of type '_Message' instead"

The error message came up even when I followed the simple examples in the Quick Start Notebook, like:
"scalar_block = td.Scalar()
scalar_block.eval(42)"

My Tensorflow version is 0.12.1. I was wondering if you had any idea about how to fix this?

Thanks a lot for your attention and time!

Sequence filter block

I absolutely love this library, but I've come across a problem that I can't seem to solve:

Is it possible to do filtering over sequences?
Something like this:
X = td.Map(td.Scalar()) >> td.Filter(lambda x: x < 3.)
X.eval([1,2,4,8]) => [1., 2.]
where td.Filter returns another sequence.

Could you do it with Fold and OneOf? What then would the base case be?

Is the repo compatible with TensorFlow 1.0.0 ?

Hi, I recently upgraded my tensorflow to 1.0.0 and tried to install tensorflow fold with tensorflow 1.0.0 (rather than 1.0.0rc0), but got some error with bazel when installing from source.

Installing from source

I've tried to install this tensorflow fold from source following https://github.com/tensorflow/fold/blob/master/tensorflow_fold/g3doc/sources.md, and everything works well. However, when I tried to replace the tensorflow submodule with the master tensorflow (rather than 1.0.0rc0) and run bazel build --config=opt //tensorflow_fold/util:build_pip_package, I got the following error:

ERROR: Failed to load Skylark extension '@io_bazel_rules_closure//closure:defs.bzl'.
It usually happens when the repository is not defined prior to being used.
Maybe repository 'io_bazel_rules_closure' was defined later in your WORKSPACE file?
ERROR: cycles detected during target parsing.
INFO: Elapsed time: 2.703s

So it seems that the bazel setup of fold is not compatible with tensorflow 1.0.0. It there a way to fix it?

Installing from binary

I also tried to install from binary following https://github.com/tensorflow/fold/blob/master/tensorflow_fold/g3doc/setup.md, but installed tensorflow 1.0.0 (instead of 1.0.0rc0) by pip install tensorflow-gpu.

After installation, I found that python -c 'import tensorflow_fold' works, and that my code can run. But I'm still worried that is the provided binary in the setup.md compatible with tensorflow 1.0.0, since (I assume) it was compiled against tensorflow 1.0.0rc0).

So is the provided fold binary tensorflow_fold-0.0.1-py3-none-linux_x86_64.whl compatible with tensorflow 1.0.0 binary? Or is there a way to build fold against tensorflow 1.0.0? Thanks in advance!

Is python3.4 supported?

[X@X ~]$ pip3.4 install --user --upgrade https://storage.googleapis.com/tensorflow_fold/tensorflow_fold-0.0.1-py3-none-linux_x86_64.whl
tensorflow_fold-0.0.1-py3-none-linux_x86_64.whl is not a supported wheel on this platform.
Storing debug log for failure in ~/.pip/pip.log
[X@X ~]$ uname -a
Linux X 4.1.13-100.fc21.x86_64 #1 SMP Tue Nov 10 13:13:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

AdaGradOptimizer on GPU

Hello,
When I executed the same code posted on the The sentiment notebook, following error message is displayed.

InvalidArgumentError: Cannot assign a device to node 'Adagrad/update_word_embedding/weights/Unique': Could not satisfy explicit device specification '' because the node was colocated with a group of nodes that required incompatible device '/job:localhost/replica:0/task:0/GPU:0' Colocation Debug Info: Colocation group had the following types and devices: SparseApplyAdagrad: CPU UnsortedSegmentSum: GPU CPU StridedSlice: GPU CPU Shape: GPU CPU Unique: GPU CPU VariableV2: GPU CPU Const: GPU CPU [[Node: Adagrad/update_word_embedding/weights/Unique = Unique[T=DT_INT32, _class=["loc:@word_embedding/weights"], out_idx=DT_INT32](gradients/while/Function_19/word_embedding_1/Gather/Enter_grad/b_acc_6)]]

If I change sess = tf.InteractiveSession() to following code,

config = tf.ConfigProto(allow_soft_placement = True)
sess = tf.InteractiveSession(config = config)

then, following error occurs

InvalidArgumentError: AttrValue must not have reference type value of float_ref for attr 'tensor_type' ; NodeDef: word_embedding/weights/Adagrad/_47 = _Recv[_start_time=0, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_2263_word_embedding/weights/Adagrad", tensor_type=DT_FLOAT_REF, _device="/job:localhost/replica:0/task:0/cpu:0"](^Adagrad/learning_rate/_49, ^Adagrad/update_word_embedding/weights/UnsortedSegmentSum, ^Adagrad/update_word_embedding/weights/Unique); Op<name=_Recv; signature= -> tensor:tensor_type; attr=tensor_type:type; attr=tensor_name:string; attr=send_device:string; attr=send_device_incarnation:int; attr=recv_device:string; attr=client_terminated:bool,default=false; is_stateful=true> [[Node: word_embedding/weights/Adagrad/_47 = _Recv[_start_time=0, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_2263_word_embedding/weights/Adagrad", tensor_type=DT_FLOAT_REF, _device="/job:localhost/replica:0/task:0/cpu:0"](^Adagrad/learning_rate/_49, ^Adagrad/update_word_embedding/weights/UnsortedSegmentSum, ^Adagrad/update_word_embedding/weights/Unique)]]

I found that when I change the adagrad to GradientDescentOptimizer or AdamOptimizer, the code works, but the accuracy of the model is inferior than the adagrad version. I found that Adagrad is not working on gpu <AdaGradOptimizer on GPU (Making word2vec tutorial runnable on GPU)> any help, please?

Generic tensorflow code do not suffer this problem... so I guess this is related to the fold library?

TF placeholder access from within TD block

Hello,

I am trying to build a network with some static inputs and a dynamic part using these values. Here an example:

import numpy as np
import tensorflow as tf
import tensorflow_fold as td

y = tf.placeholder(dtype=tf.float32, shape=(None,))

def fixed_plus(x):
    return tf.add(x=x, y=y)

compiler = td.Compiler.create(td.Tensor(()) >> td.Function(tf_fn=fixed_plus))

with tf.Session() as session:
    feed_dict = compiler.build_feed_dict(np.ones(shape=(10,)))
    feed_dict[y] = np.arange(10)
    print(session.run(fetches=compiler.output_tensors, feed_dict=feed_dict))

I get the following exception message in the line that creates the compiler:

InvalidArgumentError (see above for traceback): Incompatible shapes: [0] vs. [10]
         [[Node: while/Function_1/Add = Add[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](while/Function_1/arg_0/Gather, while/Function_1/Add/Enter)]]

Is there a way to do this, or is it necessary to feed all input used within a block in compiler.build_feed_dict? I have seen example code with a dropout value given as external placeholder, so I assume there should be a way?

Many thanks in advance!

Horrible tensorboard graph:

Hi,

I'm trying to scope certain components of my tensorflow fold model, and I after rending it in tensorboard, it seems that its ignoring the scope in which I construct different blocks. See this http://i.imgur.com/Vtf9OhP.png

The associated source code which generates this graph is:

with tf.variable_scope("context_free_discriminator"):
	with tf.variable_scope("embedding"):
	    pre_process =  (td.InputTransform(lambda tokens: [tokeToVec(s, word2vec, indim) for s in tokens]) 
	                    >> td.Map(td.Vector(indim)))
	    
	    word_cell = td.ScopedLayer(tf.contrib.rnn.BasicLSTMCell(num_units=300), 'word_cell')
	    stacked_cell =  td.ScopedLayer(tf.contrib.rnn.BasicLSTMCell(num_units=100), 'stacked_cell')

	    # word lstm convers word sequence into an lstm.
	    word_lstm = (pre_process >> td.RNN(word_cell))
	    hierarchical_lstm = (word_lstm 
	                         >> td.GetItem(0) #hidden states
	                         >> td.RNN(stacked_cell))
	    embedding =  (hierarchical_lstm  
	                                      >> td.GetItem(1) # Final state (out, hidden)
	                                      >> td.GetItem(0) # Final output state.
	                                      >>  td.FC(outdim))

	with tf.variable_scope("model"):
	    logit_output_block = (embedding_block 
	              >> td.FC(428)
	              >> td.FC(328)
	              >> td.FC(num_mocs, activation=None))
	    compiler = td.Compiler.create(logit_output_block)
	    logit_tensor = compiler.output_tensors

	with tf.variable_scope("training"):
	    _desired = tf.placeholder(tf.int32)
	    _desired_onehot = tf.one_hot(_desired, num_mocs)
	    loss = cross_entropy = tf.reduce_mean(
	        tf.nn.softmax_cross_entropy_with_logits(labels=_desired, logits=logit_tensor))

	    train_op = tf.train.AdamOptimizer(learning_rate).minimize(cross_entropy)

Implementation of a classifier based on recursive trees

Hi,

Thank you very much for sharing this wonderful tool!

I tried to implement a classifier based on recursive trees. In general, I defined a recursive block that turns a tree into a predicted label, and then used a record block to pair the prediction from the recursive block with the correct label (y_). The record block was then compiled and a cross-entropy loss was calculated based on the output (y and y_) of the compiler. However, when I connected the loss to an optimizer, I got the following message:

../gradients_impl.py:92: UserWarning: Converting sparse IndexedSlices to a dense Tensor of unknown shape. This may consume a large amount of memory.
"Converting sparse IndexedSlices to a dense Tensor of unknown shape. "

The code was then stopped when it tried to process the result from compiler.build_loom_input.

Segmentation fault (core dumped)

I was wondering if it had something to do with the way that I paired the output of the recursive block and the correct label, or any other mistakes in defining the model? (The computation graph shows that the 'outputgather' node sends a tensor with unknown shape (?, 39) (39 is the dimension of y and y_) to the 'gradient' node).

My code is as follows:

    # Define the recursive block of 'process tree'
    expr_fwd = td.ForwardDeclaration(td.PyObjectType(), td.TensorType([word_dim,]))
    word_embedding_layer = td.Embedding(len(word_embedding_model) + 1, word_dim, initializer = we_values, trainable = False)
    leaf_case = td.InputTransform(lambda node: we_keys.get(node['w'].lower(), 0), name = 'leaf_input_transform') >> td.Scalar('int32') >> td.Function(word_embedding_layer, name = 'leaf_Function')
    dep_embedding_layer = td.Embedding(len(dep_dict), param['dep_dim'], name = 'dep_embedding_layer')
    get_dep_embedding = (td.InputTransform(lambda d_label: dep_dict.get(d_label), name = 'dep_input_transform') >> td.Scalar('int32') >> td.Function(dep_embedding_layer, name = 'dep_embedding'))
    fclayer = td.FC(word_dim, name = 'process_tree_FC')
    non_leaf_case = (td.Record({'child': expr_fwd(), 'me': expr_fwd(), 'd': get_dep_embedding}, name = 'non-leaf_record') >> td.Concat() >> td.Function(fclayer, name = 'non_leaf_function'))
    process_tree = td.OneOf(lambda node: node['is_leaf'], {True : leaf_case, False: non_leaf_case}, name = 'process_tree_one_of')
    expr_fwd.resolve_to(process_tree)

    # Define the block which pairs the label ('y_') with the prediction from the recursive tree
    fcplayer_hidden = td.FC(len(y_classes))
    block = td.Record({'x': process_tree >> td.Function(fcplayer_hidden), 'y_': td.Vector(len(y_classes), name = 'label_vector')}, name = 'my_block')

    # Compile the block
    compiler = td.Compiler.create(block)
    (y, y_) = compiler.output_tensors
    with tf.name_scope('cross_entropy') as scope:
      cross_entropy = tf.nn.softmax_cross_entropy_with_logits(logits = y, labels = y_)
    train_step = tf.train.AdamOptimizer(0.5).minimize(cross_entropy)

Thank you very much for your attention!

Two models with tied inputs

Thank you for making available this great library.

I was playing with the sentiment analysis example and wanted to see if I can make two TreeLSTMs (with different parameters) with shared input. What I'm trying to do is something like the following (failed attempt)

with tf.variable_scope("sen1"):
model1 = embed_tree(logits_and_state(), is_root=True)
with tf.variable_scope("sen2"):
model2 = embed_tree(logits_and_state(), is_root=True)
compiler = td.Compiler.create((model1, model2))
sent1, sent2 = compiler.output_tensors

Basically I'm trying to create two TreeLSTM's, getting the two encoded representations and implementing a loss on top.

Perhaps this isn't the right way to do variable scoping. I'm also not sure how to tie the inputs.

Any help would be greatly appreciated!

Zero-sized batch causes operations like conv2d to crash (on GPU)

TensorFold fold seems to often generate zero-sized batch (an input batch with batch-size zero) in backward pass. Since many TensorFlow operations do not support using zero-sized batch, this behavior can cause crash on some operations, like conv2d_backward on GPU.

Below is an example to illustrate the conv2d crash (on GPU). Conditioning on "use_conv" key, the network dynamically decide whether to use conv2d on each instance. The session-run crash on backward (gradient) pass of conv2d using cudnn, causing a CUDNN_STATUS_BAD_PARAM error.

After debugging the code, I found that the conv2d backward pass crashes due to zero-sized batch (i.e. an input batch with batch-size zero) generated by fold. This issue is related to tensorflow/tensorflow#5772

import numpy as np
import tensorflow as tf
import tensorflow_fold as td

def conv_layer(input, scope):
    with tf.device("/gpu:0"), tf.variable_scope(scope):
        filter = tf.get_variable("filter", shape=[3, 3, 3, 3])
    return tf.nn.conv2d(input, filter, strides=[1, 1, 1, 1],
                        padding="SAME")

# Conditioned on "use_conv" key, decide whether to run convolution.
block = td.OneOf(td.GetItem("use_conv"),
                 [(True, td.GetItem("input") >> td.Tensor(shape=[10, 10, 3]) >> td.ScopedLayer(conv_layer)),
                  (False, td.GetItem("input") >> td.Tensor(shape=[10, 10, 3]) >> td.Identity())])

compiler = td.Compiler.create(block)
output = compiler.output_tensors[0]

# Some arbitrary optimization that involves conv2d backward
loss = tf.reduce_sum(output)
solver = tf.train.AdamOptimizer()
train_step = solver.minimize(loss)

sess = tf.Session()
sess.run(tf.global_variables_initializer())
data_1 = {"use_conv": True, "input": np.ones((10, 10, 3))}
data_2 = {"use_conv": False, "input": np.ones((10, 10, 3))}
# Crash on GPU with the following error.
# F tensorflow/stream_executor/cuda/cuda_dnn.cc:456]
#   could not set cudnn tensor descriptor: CUDNN_STATUS_BAD_PARAM
sess.run(train_step, feed_dict=compiler.build_feed_dict([data_1, data_2]))

My questions are:

  1. Why would tensorflow fold generate some zero-sized batch on backward pass on the data above?
  2. Is there any workaround to avoid putting some-zero batch in backward pass?

Thanks in advance!

OS X support.

I understand that you're not in a situation that enables you to provide support for mac. However, could we keep this issue open to keep track of the situation?

TFFold does not install on Tensorflow 1.0

TFFold does not install on Tensorflow 1.0 instead it needs the rc0 mentioned here. I have TF 1.0 and it did not install. It said it is not supported for the environment.

How to use sequence of tuples

I can find anything in the API for handling sequences of tuples. After executing the block below, I want to be able to manipulate each tuple. For example, input_block outputs:
[([array(1.0, dtype=float32), array(2.0, dtype=float32), array(4.0, dtype=float32)], array(0.0, dtype=float32)),...] and I'm trying to figure out how to take the firs tuple and create several td.Vector(3)s with 0.0 in the second index like so [1.0, 0.0, 2,0], [2.0, 0.0, 4.0], [1.0,0.0,4.0]. How can you achieve this with Fold?

# tree input
test_input = [
	{'node':0, 'neighbors':[1,2,4]},
	{'node':1, 'neighbors':[6,3,0]},
	{'node':2, 'neighbors':[0]},
	{'node':3, 'neighbors':[1,5]},
	{'node':4, 'neighbors':[0]},
	{'node':5, 'neighbors':[3]},
	{'node':6, 'neighbors':[1]}
]
input_block = td.Map(td.Record({'node':td.Scalar(), 'neighbors':td.Map(td.Scalar())}))
print input_block.eval(test_input)

Fold confusing ndarray and TensorType?

In the code below, I'm taking in a list, converting it to an ndarray, and then feeding it to a td.Tensor block. When I do this, Fold tells me that the variable x I'm passing to the td.Tensor is a Fold TensorType object, but x is really a numpy ndarray.
TypeError: Type mismatch between input type TensorType((1, 5, 1), 'float32') and expected input type PyObjectType() in <td.Tensor dtype='float32' shape=(1, 5, 1)>.

def list_to_tensor(x, name='input_layer'):
	list_to_tensor = td.Composition()
	with list_to_tensor.scope():
		sh  = [1,len(x),1]
		x   = np.array(x, dtype=np.float32).reshape(sh)
		tn  = td.Tensor(sh).reads(x)
	return tn
input_layer = td.InputTransform(list_to_tensor)
features3 = [x for x in range(5)]
p = input_layer.eval(features3)
print p
print type(p)

When I only return x without passing it to td.Tensor, I can clearly see that it's a numpy ndarray:

def list_to_tensor(x, name='input_layer'):
	list_to_tensor = td.Composition()
	with list_to_tensor.scope():
		sh  = [1,len(x),1]
		x   = np.array(x, dtype=np.float32).reshape(sh)
		print ("type(x): ",type(x))
		tn  = td.Tensor(sh)
	return (x, tn)

This outputs fine:

(array([[[ 0.],
        [ 1.],
        [ 2.],
        [ 3.],
        [ 4.]]], dtype=float32), <td.Tensor dtype='float32' shape=(1, 5, 1)>)

Why is it telling me that in the first scenario that x is a Fold TensorType?

Calculating Softmax over a sequence of scalars

As the title suggests, I cannot find a way of doing this. There does not seem to be a way of currying a divide function with the sum of a sequence, and then mapping that back over the sequence.

Any help would be great - but I fear I will have to retreat to vanilla TF and use padded input sequences (the horror!).

Composition `scope` Example fails to run

The example:

c = td.Composition()
with c.scope():
  x = td.Vector(3).reads(c.input)
  x_squared = td.Function(tf.mul).reads(x, x)
  ten = td.FromTensor(10 * np.ones(3, dtype='float32'))
  ten_x = td.Function(tf.mul).reads(ten, x)
  c.output.reads(td.Function(tf.add).reads(x_squared, ten_x)

does not run properly with modern tensorflow - the tf.muls need to be changed to multiply

On top of that:
when run with the name change, it throws an error:

Traceback (most recent call last):
  File "tf_fold_playground.py", line 133, in <module>
    c.output.reads(td.Function(tf.add)).reads(x_squared, ten_x)
  File "/usr/local/lib/python3.6/site-packages/tensorflow_fold/blocks/blocks.py", line 151, in reads
    _COMPOSITION_CONTEXT.current.connect(other, self)
  File "/usr/local/lib/python3.6/site-packages/tensorflow_fold/blocks/blocks.py", line 874, in connect
    raise ValueError('input of block is already connected: %s' % (b,))
ValueError: input of block is already connected: <td.Composition.output>

using python3.6 ubuntu 16.04

fold not loading after installation

I installed fold using pip as recommended by the instructions, however when I try to import it I get an error. Any suggestions on how to fix this issue:

Traceback (most recent call last): File "<string>", line 1, in <module> File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow_fold/__init__.py", line 22, in <module> from tensorflow_fold.blocks.block_compiler import * File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow_fold/blocks/block_compiler.py", line 28, in <module> from tensorflow_fold.blocks import loom_ops File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow_fold/blocks/loom_ops.py", line 19, in <module> import tensorflow_fold.blocks.result_types as tdt File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow_fold/blocks/result_types.py", line 27, in <module> from tensorflow_fold.public import loom File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow_fold/public/loom.py", line 17, in <module> from tensorflow_fold.loom.loom import * File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow_fold/loom/__init__.py", line 17, in <module> from tensorflow_fold.loom.loom import * File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow_fold/loom/loom.py", line 36, in <module> from tensorflow_fold.loom import deserializing_weaver_op File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow_fold/loom/deserializing_weaver_op.py", line 34, in <module> tf.resource_loader.get_data_files_path(), '_deserializing_weaver_op.so')) File "/home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow/python/framework/load_library.py", line 64, in load_op_library None, None, error_msg, error_code) tensorflow.python.framework.errors_impl.NotFoundError: /home/ubuntu/anaconda2/lib/python2.7/site-packages/tensorflow_fold/loom/_deserializing_weaver_op.so: undefined symbol: _ZN10tensorflow6tensor5SplitERKNS_6TensorERKNS_3gtl10ArraySliceIxEE

What is the most appropriate way to add additional features to each node in a tree-like input?

Suppose I have a certain input like below
Fold is a nice library.
,which can be converted like below.
(4 (3 Fold) (3 (3 (3 is) (3 (3 a) (3 (5 nice) (3 library)))) (3 .)))

The binary tree format string can be an input for the sentiment model. I tried to find a way for assigning additional features for each node in a tree. And by changing the label of each node, (for example, (3 Fold) => (3/NP Fold)) I could transfer additional features to the model. But it seems a bit clumsy way for me.

Is there any other way to add additional features to each node?

multiple compilers

This is my model:

mid = (td.Map(td.Tensor((24,10)) >>
                td.ScopedLayer(convLayer) >>
                td.Function(lambda x: tf.reshape(x,[-1,64*(10-2)]))) >>
         td.Fold(td.Concat() >>
                 td.Function(td.FC(128)), td.FromTensor(tf.zeros(128))))
model = ( mid  >>  td.Function(td.FC(1)))

(The ScopedLayer(convLayer) part is related to solved issue #14 )

I trained it using model: compiler = td.Compiler.create((model, td.Scalar())), and it works. However, now I want the result of mid for a set of values. I can do encod.eval(X[i]) for every piece of data, but that is painfully slow. However, if I try to create a new compiler:

newComp=td.Compiler.create((mid,))
Y=sess.run(mid,newComp.build_feed_dict(X))

I get: TypeError: block <td.Pipe> is already a child of <td.Pipe>

How can I solve this? eval on each entry will take a bit over 4 hours ...

Protobuf message size limit

When processing batches of trees of few thousand nodes, session.run fails with the following message:

[libprotobuf ERROR external/protobuf/src/google/protobuf/io/coded_stream.cc:208] A protocol message
was rejected because it was too big (more than 67108864 bytes). To increase the limit (or to disa
ble these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.
h.
W tensorflow/core/framework/op_kernel.cc:993] Internal: Failed to deserialize WeaverMessage: Weaver
Message couldn't be parsed.

It could probably be solved by linking newer version of tensorflow repository:
tensorflow/tensorflow#7301

Example For Arbitrary Tree Structure Input

Hi There, love the project!

I am looking to use fold in some of my future experiments in my masters project. It would be great to have an example which shows how a network would be trained on tree-like input. All the examples at the moment show at most a tree of depth one (the sentence lstm). I would be planning to use it to train a VAE on a parse-tree of code, where the nodes of the tree are the string contents of that node.

I would be happy to help make a simple one over the weekend if someone can point me in the right direction.

Thanks!

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.