Skip to content
Open
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# L3

To use:
- download the data from http://nlp.stanford.edu/data/muj/shapeworld_4k.tar.gz, and untar inside `data` folder, to create `data/shapeworld` folder
- use python 2, e.g.
```
virtualenv -p python2 .venv
source .venv/bin/activate
```
- install requirements.txt, e.g.
```
pip install -r requirements.txt
```
- choose a command-line from `exp` folder, eg `cls_hint` is for L3
- `ex` is Meta, `gold` is ground-truth descriptions, `hint` is L^3, `joint` is Meta+Joint, `sim` is another baseline that didn't make it into the paper, and `vis` is just visualization.
- For the other two experiments, evaluation is done in a different script from training; those have the `_eval` suffix.
8 changes: 5 additions & 3 deletions models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import gflags
import numpy as np
import sys
import tensorflow as tf
import os
import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()

FLAGS = gflags.FLAGS

Expand Down Expand Up @@ -41,7 +43,7 @@ def _set_flags():
def _encode(name, t_input, t_len, t_vecs, t_init=None):
multi = len(t_input.get_shape()) == 3
assert multi or len(t_input.get_shape()) == 2
cell = tf.contrib.rnn.GRUCell(N_HIDDEN)
cell = tf.compat.v1.nn.rnn_cell.GRUCell(N_HIDDEN)
if multi:
t_shape = tf.shape(t_input)
t_n_batch, t_n_multi, t_n_toks = t_shape[0], t_shape[1], t_shape[2]
Expand Down Expand Up @@ -108,7 +110,7 @@ def __init__(self, name, t_init, t_target, t_last, t_last_hidden, t_vecs):
multi = len(t_init.get_shape()) == 3

assert multi or len(t_init.get_shape()) == 2
cell = tf.contrib.rnn.GRUCell(N_HIDDEN)
cell = tf.compat.v1.nn.rnn_cell.GRUCell(N_HIDDEN)
if multi:
t_shape = tf.shape(t_target)
t_n_batch, t_n_multi, t_n_toks = t_shape[0], t_shape[1], t_shape[2]
Expand Down
4 changes: 3 additions & 1 deletion net.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import tensorflow as tf
import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()

INIT_SCALE = 1.43

Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tensorflow~=2.1.0
pillow
python-gflags
10 changes: 5 additions & 5 deletions tasks/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def __init__(self):

data = {}
for fold in ("train", "val", "test", "val_same", "test_same"):
examples = np.load(os.path.join(sw_path, fold, "examples.npy"))
inputs = np.load(os.path.join(sw_path, fold, "inputs.npy"))
labels = np.load(os.path.join(sw_path, fold, "labels.npy"))
examples = np.load(os.path.join(sw_path, fold, "examples.npz"))['arr_0']
inputs = np.load(os.path.join(sw_path, fold, "inputs.npz"))['arr_0']
labels = np.load(os.path.join(sw_path, fold, "labels.npz"))['arr_0']

with open(os.path.join(sw_path, fold, "hints.json")) as hint_f:
hints = json.load(hint_f)
Expand Down Expand Up @@ -82,8 +82,8 @@ def __init__(self):
# i_feat = self.feature_index[tuple(feature)]
# if i_feat is not None:
# inp_features[i_datum, i_feat] = 1
ex_features = np.load(os.path.join(sw_path, fold, "examples.feats.npy"))
inp_features = np.load(os.path.join(sw_path, fold, "inputs.feats.npy"))
ex_features = np.load(os.path.join(sw_path, fold, "examples.feats.npz"))['arr_0']
inp_features = np.load(os.path.join(sw_path, fold, "inputs.feats.npz"))['arr_0']

fold_data = []

Expand Down