Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Failing test case for initial state dependency #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions tests/test_TFNetworkRecLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,56 @@ def test_nativelstm2_initial_state_keep_epoch():
_check_train_simple_network({
"output": {"class": "rec", "unit": "nativelstm2", "loss": "mse", "initial_state": "keep_over_epoch"}})

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing newline here.

def test_lstmblock_initial_state_dependency():
beam_size = 2
network = {
"data_embed": {"class": "linear", "activation": None, "with_bias": False, "n_out": 6},
"lstm0_fw" : { "class": "rec", "unit": "nativelstm2", "n_out" : 5, "direction": 1, "from": ["data_embed"] },

"encoder_state": {"class": "get_last_hidden_state", "from": ["lstm0_fw"], 'key': 'c', "n_out": 5},

"output": {"class": "rec", "from": [], "unit": {
'output': {'class': 'choice', 'target': 'classes', 'beam_size': beam_size, 'from': ["output_prob"],
"initial_output": 0},
"end": {"class": "compare", "from": ["output"], "value": 0},
'orth_embed': {'class': 'linear', 'activation': None, "with_bias": False, 'from': ['prev:output'], "n_out": 6},

"s": {"class": "rnn_cell", "unit": "LSTMBlock", "from": ["orth_embed"], "initial_state": {"c": "base:encoder_state", "h": 0}, "n_out": 5}, # h_t

"output_prob": {"class": "softmax", "from": ["s"], "target": "classes", "loss": "ce"}
}, "target": "classes", "max_seq_len": 7},
}

from GeneratingDataset import DummyDataset
seq_len = 5
n_data_dim = 2
n_classes_dim = 3
train_data = DummyDataset(input_dim=n_data_dim, output_dim=n_classes_dim, num_seqs=4, seq_len=seq_len)
train_data.init_seq_order(epoch=1)
cv_data = DummyDataset(input_dim=n_data_dim, output_dim=n_classes_dim, num_seqs=2, seq_len=seq_len)
cv_data.init_seq_order(epoch=1)

config = Config()
config.update({
"model": "/tmp/model",
"num_outputs": n_classes_dim,
"num_inputs": n_data_dim,
"network": network,
"start_epoch": 1,
"num_epochs": 2,
"batch_size": 10,
"nadam": True,
"learning_rate": 0.01,
"debug_add_check_numerics_ops": True
})

from tests.test_TFEngine import _cleanup_old_models
from TFEngine import Engine
_cleanup_old_models(config)
engine = Engine(config=config)
engine.init_train_from_config(config=config, train_data=train_data, dev_data=cv_data, eval_data=None)
engine.train()
engine.search(cv_data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add empty newline line.


def test_slow_TensorArray():
"""
Expand Down