diff --git a/README.md b/README.md new file mode 100644 index 0000000..ffd11ef --- /dev/null +++ b/README.md @@ -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. diff --git a/models.py b/models.py index 9d8d015..1329907 100644 --- a/models.py +++ b/models.py @@ -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 @@ -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] @@ -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] diff --git a/net.py b/net.py index 1a1105f..fac0316 100644 --- a/net.py +++ b/net.py @@ -1,4 +1,6 @@ -import tensorflow as tf +import tensorflow.compat.v1 as tf + +tf.disable_v2_behavior() INIT_SCALE = 1.43 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b5760da --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +tensorflow~=2.1.0 +pillow +python-gflags diff --git a/tasks/shapes.py b/tasks/shapes.py index 2b5a427..f18fe00 100644 --- a/tasks/shapes.py +++ b/tasks/shapes.py @@ -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) @@ -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 = []