コード例 #1
0
default_model = os.path.join(os.path.dirname(__file__), "models",
                             "baseline_rnnlm.gz")

if __name__ == '__main__':
    ap = ArgumentParser()
    ap.add_argument("--model", default="")
    ap.add_argument("--small", action="store_true")
    args = ap.parse_args()

    vocab, lmdata = load_data(small=args.small, history_len=5, batch_size=64)
    model = NeuralLM(vocab.size)
    model.stack(
        RNN(hidden_size=100,
            output_type="sequence",
            hidden_activation="sigmoid",
            persistent_state=True,
            batch_size=lmdata.size,
            reset_state_for_input=0), FullOutputLayer(vocab.size))

    if os.path.exists(args.model):
        model.load_params(args.model)

    trainer = SGDTrainer(
        model, {
            "learning_rate": LearningRateAnnealer.learning_rate(1.2),
            "weight_l2": 1e-7
        })
    annealer = LearningRateAnnealer()

    trainer.run(lmdata, controllers=[annealer])
コード例 #2
0
                             "class_based_rnnlm.gz")

if __name__ == '__main__':
    ap = ArgumentParser()
    ap.add_argument("--model", default="")
    ap.add_argument("--small", action="store_true")
    args = ap.parse_args()

    vocab, lmdata = load_data(small=args.small, history_len=5, batch_size=64)
    import pdb
    pdb.set_trace()
    model = NeuralLM(vocab.size)
    model.stack(
        RNN(hidden_size=100,
            output_type="sequence",
            hidden_activation='sigmoid',
            persistent_state=True,
            batch_size=lmdata.size,
            reset_state_for_input=0),
        ClassOutputLayer(output_size=100, class_size=100))

    if os.path.exists(args.model):
        model.load_params(args.model)

    trainer = SGDTrainer(
        model, {
            "learning_rate": LearningRateAnnealer.learning_rate(1.2),
            "weight_l2": 1e-7
        })
    annealer = LearningRateAnnealer()

    trainer.run(lmdata, epoch_controllers=[annealer])
コード例 #3
0
ファイル: rnn_auto_encoder.py プロジェクト: slorr80/deepy
# -*- coding: utf-8 -*-

import os
from deepy.networks import AutoEncoder
from deepy.layers import RNN, Dense
from deepy.trainers import SGDTrainer, LearningRateAnnealer

from util import get_data, VECTOR_SIZE, SEQUENCE_LENGTH

HIDDEN_SIZE = 50

model_path = os.path.join(os.path.dirname(__file__), "models", "rnn1.gz")

if __name__ == '__main__':
    model = AutoEncoder(rep_dim=10, input_dim=VECTOR_SIZE, input_tensor=3)
    model.stack_encoders(
        RNN(hidden_size=HIDDEN_SIZE, input_type="sequence", output_type="one"))
    model.stack_decoders(
        RNN(hidden_size=HIDDEN_SIZE,
            input_type="one",
            output_type="sequence",
            steps=SEQUENCE_LENGTH), Dense(VECTOR_SIZE, 'softmax'))

    trainer = SGDTrainer(model)

    annealer = LearningRateAnnealer(trainer)

    trainer.run(get_data(), controllers=[annealer])

    model.save_params(model_path)
コード例 #4
0
ファイル: char_deep_rnn.py プロジェクト: zhp562176325/deepy
from deepy.layers import RNN, Dense


logging.basicConfig(level=logging.INFO)

resource_dir = os.path.abspath(os.path.dirname(__file__)) + os.sep + "resources"

vocab_path = os.path.join(resource_dir, "ptb.train.txt")
train_path = os.path.join(resource_dir, "ptb.train.txt")
valid_path = os.path.join(resource_dir, "ptb.valid.txt")
vocab = Vocab(char_based=True)
vocab.load(vocab_path, max_size=1000)

model = NeuralLM(input_dim=vocab.size, input_tensor=3)
model.stack(
    RNN(hidden_size=100, output_type="sequence"),
    RNN(hidden_size=100, output_type="sequence"),
    Dense(vocab.size, "softmax"))


if __name__ == '__main__':
    ap = ArgumentParser()
    ap.add_argument("--model", default=os.path.join(os.path.dirname(__file__), "models", "char_rnn_model1.gz"))
    ap.add_argument("--sample", default="")
    args = ap.parse_args()

    if os.path.exists(args.model):
        model.load_params(args.model)

    lmdata = LMDataset(vocab, train_path, valid_path, history_len=30, char_based=True, max_tokens=300)
    batch = SequentialMiniBatches(lmdata, batch_size=20)
コード例 #5
0
# Separate data
valid_size = int(len(data) * 0.15)
train_set = data[valid_size:]
valid_set = data[:valid_size]

dataset = SequentialDataset(train_set, valid=valid_set)
dataset.pad_left(20)
dataset.report()

batch_set = MiniBatches(dataset)

if __name__ == '__main__':
    model = NeuralClassifier(input_dim=26, input_tensor=3)
    model.stack(
        RNN(hidden_size=30,
            input_type="sequence",
            output_type="sequence",
            vector_core=0.1),
        RNN(hidden_size=30,
            input_type="sequence",
            output_type="sequence",
            vector_core=0.3),
        RNN(hidden_size=30,
            input_type="sequence",
            output_type="sequence",
            vector_core=0.6),
        RNN(hidden_size=30,
            input_type="sequence",
            output_type="one",
            vector_core=0.9), Dense(4), Softmax())

    trainer = SGDTrainer(model)
コード例 #6
0
from deepy.trainers import SGDTrainer, LearningRateAnnealer
from deepy.layers import RNN, Dense

logging.basicConfig(level=logging.INFO)

resource_dir = os.path.abspath(
    os.path.dirname(__file__)) + os.sep + "resources"

vocab_path = os.path.join(resource_dir, "ptb.train.txt")
train_path = os.path.join(resource_dir, "ptb.train.txt")
valid_path = os.path.join(resource_dir, "ptb.valid.txt")
vocab = Vocab(char_based=True)
vocab.load(vocab_path, max_size=1000)

model = NeuralLM(input_dim=vocab.size, input_tensor=3)
model.stack(RNN(hidden_size=100, output_type="sequence"),
            RNN(hidden_size=100, output_type="sequence"),
            Dense(vocab.size, "softmax"))

if __name__ == '__main__':
    ap = ArgumentParser()
    ap.add_argument("--model",
                    default=os.path.join(os.path.dirname(__file__), "models",
                                         "char_rnn_model1.gz"))
    ap.add_argument("--sample", default="")
    args = ap.parse_args()

    if os.path.exists(args.model):
        model.load_params(args.model)

    lmdata = LMDataset(vocab,
コード例 #7
0
ファイル: rnn_auto_encoder.py プロジェクト: zuxfoucault/deepy
# -*- coding: utf-8 -*-

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
from deepy.networks import AutoEncoder
from deepy.layers import RNN, Dense
from deepy.trainers import SGDTrainer, LearningRateAnnealer

from util import get_data, VECTOR_SIZE, SEQUENCE_LENGTH

HIDDEN_SIZE = 50

model_path = os.path.join(os.path.dirname(__file__), "models", "rnn1.gz")

if __name__ == '__main__':
    model = AutoEncoder(input_dim=VECTOR_SIZE, input_tensor=3)
    model.stack_encoders(RNN(hidden_size=HIDDEN_SIZE, input_type="sequence", output_type="one"))
    model.stack_decoders(RNN(hidden_size=HIDDEN_SIZE, input_type="one", output_type="sequence", steps=SEQUENCE_LENGTH),
                         Dense(VECTOR_SIZE, 'softmax'))

    trainer = SGDTrainer(model)

    annealer = LearningRateAnnealer(trainer)

    trainer.run(get_data(), controllers=[annealer])

    model.save_params(model_path)