def test_model_get_outputs_rnn(backend_default, data): data_path = load_ptb_test(path=data) data_set = Text(time_steps=50, path=data_path) # weight initialization init = Constant(0.08) # model initialization layers = [ Recurrent(150, init, activation=Logistic()), Affine(len(data_set.vocab), init, bias=init, activation=Rectlin()) ] model = Model(layers=layers) output = model.get_outputs(data_set) assert output.shape == (data_set.ndata, data_set.seq_length, data_set.nclass) # since the init are all constant and model is un-trained: # along the feature dim, the values should be all the same assert np.allclose(output[0, 0], output[0, 0, 0], rtol=0, atol=1e-5) assert np.allclose(output[0, 1], output[0, 1, 0], rtol=0, atol=1e-5) # along the time dim, the values should be increasing: assert np.alltrue(output[0, 2] > output[0, 1]) assert np.alltrue(output[0, 1] > output[0, 0])
def test_model_get_outputs_rnn(backend_default, data): data_path = load_ptb_test(path=data) data_set = Text(time_steps=50, path=data_path) # weight initialization init = Constant(0.08) # model initialization layers = [ Recurrent(150, init, activation=Logistic()), Affine(len(data_set.vocab), init, bias=init, activation=Rectlin()) ] model = Model(layers=layers) output = model.get_outputs(data_set) assert output.shape == ( data_set.ndata, data_set.seq_length, data_set.nclass) # since the init are all constant and model is un-trained: # along the feature dim, the values should be all the same assert np.allclose(output[0, 0], output[0, 0, 0], rtol=0, atol=1e-5) assert np.allclose(output[0, 1], output[0, 1, 0], rtol=0, atol=1e-5) # along the time dim, the values should be increasing: assert np.alltrue(output[0, 2] > output[0, 1]) assert np.alltrue(output[0, 1] > output[0, 0])
def load_ptb_test(path): """ Deprecated, moved to neon.data.dataloaders. """ logger.error('This function has moved, import from neon.data.dataloaders') from neon.data.dataloaders import load_ptb_test # noqa return load_ptb_test(path)
choices=['gru', 'lstm'], help='type of recurrent layer to use (gru or lstm)') args = parser.parse_args(gen_be=False) # hyperparameters from the reference args.batch_size = 20 time_steps = 20 hidden_size = 200 gradient_clip_norm = 5 # setup backend be = gen_backend(**extract_valid_args(args, gen_backend)) # download penn treebank train_path = load_ptb_train(path=args.data_dir) valid_path = load_ptb_test(path=args.data_dir) # define a custom function to parse the input into individual tokens, which for # this data, splits into individual words. This can be passed into the Text # object during dataset creation as seen below. def tokenizer(s): return s.replace('\n', '<eos>').split() # load data and parse on word-level train_set = Text(time_steps, train_path, tokenizer=tokenizer, onehot_input=False) valid_set = Text(time_steps,
parser.add_argument('--rlayer_type', default='lstm', choices=['gru', 'lstm'], help='type of recurrent layer to use (gru or lstm)') args = parser.parse_args(gen_be=False) # hyperparameters from the reference args.batch_size = 20 time_steps = 20 hidden_size = 200 gradient_clip_norm = 5 # setup backend be = gen_backend(**extract_valid_args(args, gen_backend)) # download penn treebank train_path = load_ptb_train(path=args.data_dir) valid_path = load_ptb_test(path=args.data_dir) # define a custom function to parse the input into individual tokens, which for # this data, splits into individual words. This can be passed into the Text # object during dataset creation as seen below. def tokenizer(s): return s.replace('\n', '<eos>').split() # load data and parse on word-level train_set = Text(time_steps, train_path, tokenizer=tokenizer, onehot_input=False) valid_set = Text(time_steps, valid_path, vocab=train_set.vocab, tokenizer=tokenizer, onehot_input=False) # weight initialization init = Uniform(low=-0.1, high=0.1)
def load_ptb_test(path): logger.error('This function has moved, import from neon.data.dataloaders') from neon.data.dataloaders import load_ptb_test # noqa return load_ptb_test(path)