Ejemplo n.º 1
0
def test_embedding_layer():
    random_state = np.random.RandomState(1999)
    graph = OrderedDict()
    max_index = 100
    proj_dim = 12
    fake_str_int = [[1, 5, 7, 1, 6, 2], [2, 3, 6, 2], [3, 3, 3, 3, 3, 3, 3]]
    minibatch, mask = make_embedding_minibatch(
        fake_str_int, slice(0, 3))
    (emb_slices,), (emb_mask,) = add_embedding_datasets_to_graph(
        [minibatch], [mask], "emb", graph)
    emb = embedding_layer(emb_slices, max_index, proj_dim, graph,
                          'emb', random_state)
    followup_dim = 17
    proj = linear_layer([emb], graph, 'proj', followup_dim,
                        random_state=random_state)
    f = theano.function(emb_slices, [proj], mode="FAST_COMPILE")
    out, = f(*minibatch)
    assert(out.shape[-1] == 17)
    assert(out.shape[-2] == len(fake_str_int))
Ejemplo n.º 2
0
def test_embedding_layer():
    random_state = np.random.RandomState(1999)
    graph = OrderedDict()
    max_index = 100
    proj_dim = 12
    fake_str_int = [[1, 5, 7, 1, 6, 2], [2, 3, 6, 2], [3, 3, 3, 3, 3, 3, 3]]
    minibatch, mask = make_embedding_minibatch(fake_str_int, slice(0, 3))
    (emb_slices, ), (emb_mask, ) = add_embedding_datasets_to_graph([minibatch],
                                                                   [mask],
                                                                   "emb",
                                                                   graph)
    emb = embedding_layer(emb_slices, max_index, proj_dim, graph, 'emb',
                          random_state)
    followup_dim = 17
    proj = linear_layer([emb], graph, 'proj', followup_dim, random_state)
    f = theano.function(emb_slices, [proj], mode="FAST_COMPILE")
    out, = f(*minibatch)
    assert (out.shape[-1] == 17)
    assert (out.shape[-2] == len(fake_str_int))
Ejemplo n.º 3
0
def test_make_embedding_minibatch():
    fake_str_int = [[1, 5, 7, 1, 6, 2], [2, 3, 6, 2], [3, 3, 3, 3, 3, 3, 3]]
    uniform_minibatch, mask = make_embedding_minibatch(
        fake_str_int, slice(0, 2))
Ejemplo n.º 4
0
babi = fetch_babi(task_number=2)
X_story = babi["stories"]
X_query = babi["queries"]
y_answer = babi["target"]
train_indices = babi["train_indices"]
valid_indices = babi["valid_indices"]
vocab_size = babi["vocabulary_size"]

random_state = np.random.RandomState(1999)
graph = OrderedDict()

minibatch_size = 32
n_emb = 50
n_hid = 100
X_story_mb, X_story_mask = make_embedding_minibatch(
    X_story, slice(0, minibatch_size))
X_query_mb, X_query_mask = make_embedding_minibatch(
    X_query, slice(0, minibatch_size))

embedding_datasets = [X_story_mb, X_query_mb]
masks = [X_story_mask, X_query_mask]
r = add_embedding_datasets_to_graph(embedding_datasets, masks, "babi_data",
                                    graph)
(X_story_syms, X_query_syms), (X_story_mask_sym, X_query_mask_sym) = r

y_sym = add_datasets_to_graph([y_answer], ["y"], graph)


l1_story = embedding_layer(X_story_syms, vocab_size, n_emb, graph, 'l1_story',
                           random_state)
masked_story = X_story_mask_sym.dimshuffle(0, 1, 'x') * l1_story
Ejemplo n.º 5
0
babi = fetch_babi(task_number=2)
X_story = babi["stories"]
X_query = babi["queries"]
y_answer = babi["target"]
train_indices = babi["train_indices"]
valid_indices = babi["valid_indices"]
vocab_size = babi["vocabulary_size"]

random_state = np.random.RandomState(1999)
graph = OrderedDict()

minibatch_size = 32
n_emb = 50
n_hid = 100
X_story_mb, X_story_mask = make_embedding_minibatch(
    X_story, slice(0, minibatch_size))
X_query_mb, X_query_mask = make_embedding_minibatch(
    X_query, slice(0, minibatch_size))

embedding_datasets = [X_story_mb, X_query_mb]
masks = [X_story_mask, X_query_mask]
r = add_embedding_datasets_to_graph(embedding_datasets, masks, "babi_data",
                                    graph)
(X_story_syms, X_query_syms), (X_story_mask_sym, X_query_mask_sym) = r

y_sym = add_datasets_to_graph([y_answer], ["y"], graph)


l1_story = embedding_layer(X_story_syms, vocab_size, n_emb, graph, 'l1_story',
                           random_state=random_state)
masked_story = X_story_mask_sym.dimshuffle(0, 1, 'x') * l1_story
Ejemplo n.º 6
0
def test_make_embedding_minibatch():
    fake_str_int = [[1, 5, 7, 1, 6, 2], [2, 3, 6, 2], [3, 3, 3, 3, 3, 3, 3]]
    uniform_minibatch, mask = make_embedding_minibatch(fake_str_int, slice(0, 2))