示例#1
0
from learning_to_learn.environment import Environment
from learning_to_learn.pupils.lstm_for_meta import Lstm, LstmFastBatchGenerator as BatchGenerator
from learning_to_learn.useful_functions import create_vocabulary, get_positions_in_vocabulary

with open('datasets/text8.txt', 'r') as f:
    text = f.read()

valid_size = 500
valid_text = text[:valid_size]
train_text = text[valid_size:]

vocabulary = create_vocabulary(train_text + valid_text)
vocabulary_size = len(vocabulary)

env = Environment(Lstm, BatchGenerator, vocabulary=vocabulary)

cpiv = get_positions_in_vocabulary(vocabulary)

add_feed = [
    {
        'placeholder': 'dropout',
        'value': 0.9
    }  #,
    # {'placeholder': 'sampling_prob',
    #  'value': {'type': 'linear', 'start': 0., 'end': 1., 'interval': 3000}},
    # {'placeholder': 'loss_comp_prob',
    #  'value': {'type': 'linear', 'start': 1., 'end': 0., 'interval': 3000}}
]
valid_add_feed = [  # {'placeholder': 'sampling_prob', 'value': 1.},
    {
示例#2
0
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
with open('../../../datasets/text8.txt', 'r') as f:
    text = f.read()

valid_size = 500
valid_text = text[:valid_size]
train_text = text[valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)

env = Environment(pupil_class=Lstm,
                  meta_optimizer_class=ResNet4Lstm,
                  batch_generator_classes=BatchGenerator,
                  vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_opt_add_feed = [{
    'placeholder': 'dropout',
    'value': .9
}, {
    'placeholder': 'optimizer_dropout_keep_prob',
    'value': .9
}]
opt_inf_add_feed = [{
    'placeholder': 'dropout',
    'value': .9
}, {
    'placeholder': 'optimizer_dropout_keep_prob',
valid_text = text[test_size:test_size + valid_size]
train_text = text[test_size + valid_size:test_size + valid_size + train_size]
# valid_text = text[:valid_size]
# train_text = text[valid_size:]

voc_name = 'razvedopros_voc.txt'
if os.path.isfile(voc_name):
    with open(voc_name, 'r') as f:
        vocabulary = list(f.read())
else:
    vocabulary = create_vocabulary(text)
    with open(voc_name, 'w') as f:
        f.write(''.join(vocabulary))
vocabulary_size = len(vocabulary)

env = Environment(Lstm, BatchGenerator, vocabulary=vocabulary)

cpiv = get_positions_in_vocabulary(vocabulary)

add_feed = [{'placeholder': 'dropout', 'value': 0.9} #,
            # {'placeholder': 'sampling_prob',
            #  'value': {'type': 'linear', 'start': 0., 'end': 1., 'interval': 3000}},
            # {'placeholder': 'loss_comp_prob',
            #  'value': {'type': 'linear', 'start': 1., 'end': 0., 'interval': 3000}}
            ]
valid_add_feed = [# {'placeholder': 'sampling_prob', 'value': 1.},
                  {'placeholder': 'dropout', 'value': 1.}]

add_metrics = ['bpc', 'perplexity', 'accuracy']

# tf.set_random_seed(1)
示例#4
0
        test_text = preprocess_f(test_text)
        train_text = preprocess_f(train_text)
else:
    text = None

# print("(dialog)len(text):", len(text))
# print("(dialog)len(valid_text):", len(valid_text))
# print("(dialog)len(train_text):", len(train_text))
# print("(dialog)len(test_text):", len(test_text))

vocabulary, vocabulary_size = helmo.util.dataset.get_vocab_by_given_path(
    os.path.expanduser(config['voc_path']),
    text,
    create=config['create_vocabulary'])

env = Environment(Rnn, BatchGenerator, vocabulary=vocabulary)

cpiv = get_positions_in_vocabulary(vocabulary)

metrics = ['bpc', 'perplexity', 'accuracy']

# tf.set_random_seed(1)

rnn_map = dict(
    module_name='char_enc_dec',
    num_nodes=args.num_nodes,
    input_idx=None,
    output_idx=None,
)
kwargs_for_model_building = dict(
    rnn_type=config['rnn_type'],
示例#5
0
dname = os.path.dirname(abspath)
os.chdir(dname)
dataset_path = os.path.join(*(['..'] * ROOT_HEIGHT +
                              ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

valid_size = 1000
valid_text = text[:valid_size]
train_text = text[valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)

env = Environment(pupil_class=Lstm,
                  batch_generator_classes=BatchGenerator,
                  vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [{'placeholder': 'dropout', 'value': .9}]
valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]

dataset_name = 'valid'
evaluation = dict(save_path=save_path,
                  result_types=['perplexity', 'loss', 'bpc', 'accuracy'],
                  datasets=[(valid_text, dataset_name)],
                  batch_gen_class=BatchGenerator,
                  batch_kwargs={'vocabulary': vocabulary},
                  batch_size=1,
                  additional_feed_dict=[{
                      'placeholder': 'dropout',
示例#6
0
dataset_path = os.path.join(*(['..'] * ROOT_HEIGHT +
                              ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

valid_size = 10000

valid_text = text[:valid_size]
train_text = text[valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)
print(vocabulary_size)

env = Environment(pupil_class=Lstm,
                  batch_generator_classes=BatchGenerator,
                  vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [{'placeholder': 'dropout', 'value': .9}]
valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]

dataset_name = 'valid'

tf.set_random_seed(1)
BATCH_SIZE = 32
NUM_UNROLLINGS = 10
env.build_pupil(batch_size=BATCH_SIZE,
                num_layers=1,
                num_nodes=[100],
                num_output_layers=1,
示例#7
0
conf_file = sys.argv[1]
save_path = os.path.join(conf_file.split('.')[0], '%s')

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
with open(conf_file, 'r') as f:
    lines = remove_empty_strings_from_list(f.read().split('\n'))
opt = lines[0]
num_runs = int(lines[1])
hps = dict()
for line in lines[2:]:
    spl = line.split()
    hps[spl[0]] = float(convert(spl[1], 'float'))

env = Environment(Mlp, CifarBatchGenerator)

train_add_feed = [{'placeholder': 'dropout', 'value': .9}]
if 'momentum' in hps:
    train_add_feed.append({
        'placeholder': 'momentum',
        'value': hps['momentum']
    })
valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]

add_metrics = ['bpc', 'perplexity', 'accuracy']
VALID_SIZE = 1000

BATCH_SIZE = 32
env.build_pupil(batch_size=BATCH_SIZE,
                num_layers=2,
示例#8
0
base = parameter_set_file_name.split('.')[0]
opt = base
save_path = os.path.join(base, 'evaluation')
confs, _ = compose_hp_confs(parameter_set_file_name,
                            os.path.join(save_path, 'valid.txt'),
                            chop_last_experiment=chop_last_experiment,
                            model='pupil')
confs.reverse()  # start with small configs
print("confs:", confs)

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
data_dir = os.path.join(*(['..'] * ROOT_HEIGHT + ['datasets', 'mnist']))

env = Environment(Mlp, CifarBatchGenerator)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [{'placeholder': 'dropout', 'value': .9}]
if base in ['nesterov', 'momentum']:
    train_add_feed.append({'placeholder': 'momentum', 'value': 0.98})
valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]
VALID_SIZE = 1000

dataset_name = 'valid'
RESTORE_PATH = '../cifar10_max_train/adagrad/0/checkpoints/best'
evaluation = dict(
    save_path=save_path,
    result_types=['perplexity', 'loss', 'bpc', 'accuracy'],
    datasets=[('validation', 'valid')],
    batch_gen_class=CifarBatchGenerator,
示例#9
0
else:
    base = float(base)
names = lines[3].split()
types = lines[4].split()
optimizer_varying = dict()
for name, type_, line in zip(names, types, lines[5:]):
    optimizer_varying[name] = [convert(v, type_) for v in line.split()]

optimizer_varying['num_lstm_nodes'] = [
    [nn] * optimizer_varying['num_lstm_layers'][0] for nn in optimizer_varying['num_lstm_nodes']]

data_dir = os.path.join(*(['..']*ROOT_HEIGHT + ['datasets', 'mnist']))

env = Environment(
    pupil_class=MlpForMeta,
    meta_optimizer_class=L2L,
    batch_generator_classes=MnistBatchGenerator,
)

add_metrics = ['bpc', 'perplexity', 'accuracy']
NUM_EXERCISES = 1
NUM_UNROLLINGS = 1
OPT_INF_RESTORE_PUPIL_PATHS = [
    ('COLD', None)
]
PUPIL_RESTORE_PATHS = [
    None
]
BATCH_SIZE = 2
pupil_build = dict(
    batch_size=BATCH_SIZE,
示例#10
0
BATCH_SIZE = 32
NUM_UNROLLINGS = 10
RESULTS_COLLECT_INTERVAL = 1
NUM_TRAIN_ITERATIONS = 10
LEARNING_RATE = 1.
INIT_PARAMETER = 3.
valid_size = 500
train_size = BATCH_SIZE * NUM_UNROLLINGS
vocabulary, train_text, valid_text, _ = load_text_dataset(
    'text8.txt', train_size, valid_size, None)
vocabulary_size = len(vocabulary)
print(vocabulary_size)

env = Environment(pupil_class=Lstm,
                  batch_generator_classes=BatchGenerator,
                  vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [{'placeholder': 'dropout', 'value': 1.}]
valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]

dataset_name = 'valid'

tf.set_random_seed(1)

env.build_pupil(batch_size=BATCH_SIZE,
                num_layers=1,
                num_nodes=[100],
                num_output_layers=1,
                num_output_nodes=[],
示例#11
0
with open(dataset_path, 'r') as f:
    text = f.read()


valid_size = 2000
test_size = 100000
test_text = text[:test_size]
valid_text = text[test_size:valid_size+test_size]
train_text = text[valid_size+test_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)
print(vocabulary_size)

env = Environment(
    pupil_class=Lstm,
    batch_generator_classes=BatchGenerator,
    vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [
    {'placeholder': 'dropout', 'value': .9}
]
if 'momentum' in hps:
    train_add_feed.append(
        {'placeholder': 'momentum', 'value': hps['momentum']}
    )
valid_add_feed = [
    {'placeholder': 'dropout', 'value': 1.}
]

dataset_name = 'valid'
示例#12
0
os.chdir(dname)
dataset_path = os.path.join(*(['..']*ROOT_HEIGHT + ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

test_size = 100000
valid_size = 2000
test_text = text[:test_size]
valid_text = text[test_size:test_size+valid_size]
train_text = text[test_size+valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)

env = Environment(
    pupil_class=Lstm,
    batch_generator_classes=BatchGenerator,
    vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [
    {'placeholder': 'dropout', 'value': .9}
]

if base in ['nesterov', 'momentum']:
    train_add_feed.append(
        {'placeholder': 'momentum', 'value': 0.97}
    )
valid_add_feed = [
    {'placeholder': 'dropout', 'value': 1.}
]
示例#13
0
dataset_path = os.path.join(*(['..'] * ROOT_HEIGHT +
                              ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

test_size = 100000
valid_size = 2000
test_text = text[:test_size]
valid_text = text[test_size:test_size + valid_size]
train_text = text[test_size + valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)

env = Environment(pupil_class=Lstm,
                  batch_generator_classes=BatchGenerator,
                  vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [{'placeholder': 'dropout', 'value': .9}]

if base in ['nesterov', 'momentum']:
    train_add_feed.append({'placeholder': 'momentum', 'value': 0.97})
valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]

dataset_name = 'valid'
RESTORE_PATH = '../text8_max_train/adam/2/checkpoints/best'
evaluation = dict(save_path=save_path,
                  result_types=['perplexity', 'loss', 'bpc', 'accuracy'],
                  datasets=[(valid_text, dataset_name)],
                  batch_gen_class=BatchGenerator,
from learning_to_learn.environment import Environment
from learning_to_learn.pupils.lstm_for_meta import Lstm, LstmFastBatchGenerator as BatchGenerator


voc_name = 'dost_voc.txt'
# voc_name = 'text8_voc.txt'
with open(voc_name, 'r') as f:
    vocabulary = list(f.read())

vocabulary_size = len(vocabulary)

env = Environment(Lstm, BatchGenerator, vocabulary=vocabulary)

valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]

env.build_pupil(
    num_layers=2,
    num_nodes=[1500, 1500],
    num_output_layers=1,
    num_output_nodes=[],
    vocabulary_size=vocabulary_size,
    embedding_size=500,
    num_gpus=1,
    regime='inference',
    going_to_limit_memory=True,
)


# env.build_pupil(
#     num_layers=1,
#     num_nodes=[100],
示例#15
0
    config_path, dir_with_confs, results_directory_rel_to_repo_root)
results_file_name = os.path.join(save_path, 'test.txt')
confs, _ = compose_hp_confs(
    config_path, results_file_name, chop_last_experiment=False, model='pupil')
confs.reverse()  # start with small configs
print("confs:", confs)

text = helmo.util.dataset.get_text(config['dataset']['path'])
test_size = int(config['dataset']['test_size'])
valid_size = int(config['dataset']['valid_size'])
train_size = len(text) - test_size - valid_size
test_text, valid_text, train_text = helmo.util.dataset.split_text(text, test_size, valid_size, train_size)

vocabulary, vocabulary_size = helmo.util.dataset.get_vocab(config['dataset']['vocab_path'], text)

env = Environment(Net, BatchGenerator, vocabulary=vocabulary)

cpiv = get_positions_in_vocabulary(vocabulary)

evaluation = config['evaluation'].copy()
evaluation['save_path'] = save_path
evaluation['datasets'] = [(test_text, 'test')]
evaluation['batch_gen_class'] = BatchGenerator
evaluation['batch_kwargs']['vocabulary'] = vocabulary
if 'additional_feed_dict' not in evaluation:
    evaluation['additional_feed_dict'] = []
kwargs_for_building = config["build"].copy()
kwargs_for_building['voc_size'] = vocabulary_size
launch_kwargs = config['launch'].copy()
launch_kwargs['train_dataset_text'] = train_text
launch_kwargs['vocabulary'] = vocabulary
示例#16
0
with open(dataset_path, 'r') as f:
    text = f.read()


valid_size = 10000

valid_text = text[:valid_size]
train_text = text[valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)
print(vocabulary_size)

env = Environment(
    pupil_class=Lstm,
    meta_optimizer_class=Empty,
    batch_generator_classes=BatchGenerator,
    vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']

BATCH_SIZE = 32
NUM_UNROLLINGS = 10
env.build_pupil(
    batch_size=BATCH_SIZE,
    num_layers=1,
    num_nodes=[100],
    num_output_layers=1,
    num_output_nodes=[],
    vocabulary_size=vocabulary_size,
    embedding_size=150,
示例#17
0
    optimizer_varying[name] = [convert(v, type_) for v in line.split()]

dataset_path = os.path.join(*(['..'] * ROOT_HEIGHT +
                              ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

train_text = text

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)
print(vocabulary_size)

env = Environment(
    pupil_class=Lstm,
    meta_optimizer_class=ResNet4Lstm,
    batch_generator_classes=BatchGenerator,
    vocabulary=vocabulary,
)

add_metrics = ['bpc', 'perplexity', 'accuracy']
NUM_EXERCISES = 10
NUM_UNROLLINGS = 10
OPT_INF_RESTORE_PUPIL_PATHS = [('COLD', None)]
PUPIL_RESTORE_PATHS = [None]
BATCH_SIZE = 32
pupil_build = dict(batch_size=BATCH_SIZE,
                   num_layers=1,
                   num_nodes=[100],
                   num_output_layers=1,
                   num_output_nodes=[],
                   vocabulary_size=vocabulary_size,
示例#18
0
dname = os.path.dirname(abspath)
os.chdir(dname)
dataset_path = os.path.join(*(['..'] * ROOT_HEIGHT +
                              ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

valid_size = 10000
valid_text = text[:valid_size]
train_text = text[valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)

env = Environment(pupil_class=Lstm,
                  meta_optimizer_class=ChiNoise,
                  batch_generator_classes=BatchGenerator,
                  vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [{'placeholder': 'dropout', 'value': .9}]
valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]

dataset_name = 'valid'
evaluation = dict(save_path=save_path,
                  result_types=['perplexity', 'loss', 'bpc', 'accuracy'],
                  datasets=[(valid_text, dataset_name)],
                  batch_gen_class=BatchGenerator,
                  batch_kwargs={'vocabulary': vocabulary},
                  batch_size=1,
                  additional_feed_dict=[{
                      'placeholder': 'dropout',
示例#19
0
base = parameter_set_file_name.split('.')[0]
save_path = base + '/evaluation'
confs, _ = compose_hp_confs(parameter_set_file_name,
                            save_path,
                            chop_last_experiment=False)
confs.reverse()  # start with small configs
print("confs:", confs)

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
data_dir = os.path.join(*(['..'] * ROOT_HEIGHT + ['datasets', 'mnist']))

env = Environment(
    pupil_class=Mlp,
    meta_optimizer_class=ResNet4Mlp,
    batch_generator_classes=MnistBatchGenerator,
)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_opt_add_feed = [{
    'placeholder': 'dropout',
    'value': .9
}, {
    'placeholder': 'optimizer_dropout_keep_prob',
    'value': .9
}]
opt_inf_add_feed = [{
    'placeholder': 'dropout',
    'value': .9
}, {
示例#20
0
文件: resrnn.py 项目: deepmipt/h-elmo
from helmo.nets.resrnn import Rnn, LmFastBatchGenerator as BatchGenerator


dataset_file_name = 'enwiki1G.txt'
text = helmo.util.dataset.get_text(dataset_file_name)

test_size, valid_size = int(6.4e6), int(6.4e5)
train_size = len(text) - test_size - valid_size
test_text, valid_text, train_text = helmo.util.dataset.split_text(text, test_size, valid_size, train_size)


voc_file_name = 'enwiki1G_voc.txt'
vocabulary, vocabulary_size = helmo.util.dataset.get_vocab(voc_file_name, text)

env = Environment(Rnn, BatchGenerator, vocabulary=vocabulary)

metrics = ['bpc', 'perplexity', 'accuracy']

# tf.set_random_seed(1)

NUM_UNROLLINGS = 200
BATCH_SIZE = 32

rnn_map = dict(
    module_name='char_enc_dec',
    num_nodes=[100, 100],
    input_idx=None,
    output_idx=None,
    # derived_branches=[
    #     dict(
示例#21
0
import os
from pathlib import Path
file = Path(__file__).resolve()
parent, root = file.parent, file.parents[ROOT_HEIGHT]
sys.path.append(str(root))
try:
    sys.path.remove(str(parent))
except ValueError:  # Already removed
    pass
from learning_to_learn.environment import Environment
from learning_to_learn.pupils.mlp_for_meta import MlpForMeta as Mlp
from learning_to_learn.image_batch_gens import MnistBatchGenerator

data_dir = os.path.join(*(['..'] * ROOT_HEIGHT + ['datasets', 'mnist']))

env = Environment(Mlp, MnistBatchGenerator)

add_feed = [
    {
        'placeholder': 'dropout',
        'value': 0.9
    }  #,
    # {'placeholder': 'sampling_prob',
    #  'value': {'type': 'linear', 'start': 0., 'end': 1., 'interval': 3000}},
    # {'placeholder': 'loss_comp_prob',
    #  'value': {'type': 'linear', 'start': 1., 'end': 0., 'interval': 3000}}
]
valid_add_feed = [  # {'placeholder': 'sampling_prob', 'value': 1.},
    {
        'placeholder': 'dropout',
        'value': 1.
示例#22
0
                              ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

valid_size = 2000
test_size = 100000

valid_text = text[test_size:test_size + valid_size]
train_text = text[test_size + valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)
print(vocabulary_size)

env = Environment(pupil_class=Lstm,
                  batch_generator_classes=BatchGenerator,
                  vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [{'placeholder': 'dropout', 'value': .9}]
valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]

dataset_name = 'valid'

tf.set_random_seed(1)
BATCH_SIZE = 32
NUM_UNROLLINGS = 10
env.build_pupil(
    batch_size=BATCH_SIZE,
    num_layers=1,
    num_nodes=[100],
示例#23
0
save_path = os.path.join(parameter_set_file_name.split('.')[0], 'evaluation')
confs, _ = compose_hp_confs(
    parameter_set_file_name,
    os.path.join(save_path, 'valid.txt'),
    chop_last_experiment=chop_last_experiment,
    model='pupil'
)
confs.reverse()  # start with small configs
print("confs:", confs)

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
data_dir = os.path.join(*(['..']*ROOT_HEIGHT + ['datasets', 'mnist']))

env = Environment(Mlp, CifarBatchGenerator)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_add_feed = [
    {'placeholder': 'dropout', 'value': .9}
]
valid_add_feed = [
    {'placeholder': 'dropout', 'value': 1.}
]
VALID_SIZE = 1000

dataset_name = 'valid'
evaluation = dict(
    save_path=save_path,
    result_types=['perplexity', 'loss', 'bpc', 'accuracy'],
    datasets=[
示例#24
0
confs, _ = compose_hp_confs(parameter_set_file_name,
                            os.path.join(save_path, 'valid.txt'),
                            chop_last_experiment=chop_last_experiment,
                            model='pupil')
confs.reverse()  # start with small configs
print("confs:", confs)

abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)

VALID_SIZE = 1000

env = Environment(
    pupil_class=Mlp,
    meta_optimizer_class=ChiTerm,
    batch_generator_classes=CifarBatchGenerator,
)

add_metrics = ['bpc', 'perplexity', 'accuracy']

valid_add_feed = [{'placeholder': 'dropout', 'value': 1.}]

dataset_name = 'valid'
evaluation = dict(save_path=save_path,
                  result_types=['perplexity', 'loss', 'bpc', 'accuracy'],
                  datasets=[('validation', 'valid')],
                  batch_gen_class=CifarBatchGenerator,
                  batch_kwargs=dict(valid_size=VALID_SIZE),
                  batch_size=1,
                  additional_feed_dict=[{
示例#25
0
    ('tests', 'testres') if args.test else ('experiments', 'expres')

save_path = helmo.util.path_help.get_save_path_from_config_path(
    config_path, dir_with_confs, results_directory_rel_to_repo_root)

metrics, _, finished_launches = helmo.util.results.load_tt_results(
    save_path, config['test']['result_types'])

test_datasets, _, _ = helmo.util.dataset.get_datasets_using_config(config['dataset'])

vocabulary, vocabulary_size = helmo.util.dataset.get_vocab(
    config['dataset']['vocab_path'],
    helmo.util.dataset.get_text(config['dataset']['path']),
)

env = Environment(Net, BatchGenerator, vocabulary=vocabulary)

cpiv = get_positions_in_vocabulary(vocabulary)

kwargs_for_building = config["graph"]
kwargs_for_building['voc_size'] = vocabulary_size

test_kwargs = config['test']
test_kwargs['vocabulary'] = vocabulary
test_kwargs['validation_datasets'] = test_datasets


def compose_restore_paths(rp_conf):
    result = []
    for path in rp_conf['paths']:
        if 'prefix' in rp_conf:
示例#26
0
from learning_to_learn.environment import Environment
from learning_to_learn.pupils.lstm_for_meta import Lstm, LstmFastBatchGenerator as BatchGenerator
from learning_to_learn.useful_functions import create_vocabulary, get_positions_in_vocabulary

with open('datasets/text8.txt', 'r') as f:
    text = f.read()

valid_size = 500
valid_text = text[:valid_size]
train_text = text[valid_size:]

vocabulary = create_vocabulary(train_text + valid_text)
vocabulary_size = len(vocabulary)

env = Environment(Lstm, BatchGenerator, vocabulary=vocabulary)

cpiv = get_positions_in_vocabulary(vocabulary)

add_feed = [
    {
        'placeholder': 'dropout',
        'value': 0.9
    }  #,
    # {'placeholder': 'sampling_prob',
    #  'value': {'type': 'linear', 'start': 0., 'end': 1., 'interval': 3000}},
    # {'placeholder': 'loss_comp_prob',
    #  'value': {'type': 'linear', 'start': 1., 'end': 0., 'interval': 3000}}
]
valid_add_feed = [  # {'placeholder': 'sampling_prob', 'value': 1.},
    {
示例#27
0
dataset_path = os.path.join(*(['..']*ROOT_HEIGHT + ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

valid_size = 2000
test_size = 100000
test_text = text[:test_size]
valid_text = text[test_size:valid_size+test_size]
train_text = text[valid_size+test_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)

env = Environment(
    pupil_class=Lstm,
    meta_optimizer_class=L2L,
    batch_generator_classes=BatchGenerator,
    vocabulary=vocabulary
)

add_metrics = ['bpc', 'perplexity', 'accuracy']
train_opt_add_feed = [
    {'placeholder': 'dropout', 'value': .9},
    {'placeholder': 'optimizer_dropout_keep_prob', 'value': .9}
]
opt_inf_add_feed = [
    {'placeholder': 'dropout', 'value': .9},
    {'placeholder': 'optimizer_dropout_keep_prob', 'value': 1.}
]
valid_add_feed = [
    {'placeholder': 'dropout', 'value': 1.},
    {'placeholder': 'optimizer_dropout_keep_prob', 'value': 1.}
示例#28
0
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)

conf_file = sys.argv[1]
save_path = os.path.join(conf_file.split('.')[0], 'results')

with open(conf_file, 'r') as f:
    lines = f.read().split('\n')
restore_path = lines[0]

data_dir = os.path.join(*(['..'] * ROOT_HEIGHT + ['datasets', 'mnist']))

env = Environment(
    pupil_class=Mlp,
    meta_optimizer_class=ChiTerm,
    batch_generator_classes=MnistBatchGenerator,
)

add_metrics = ['bpc', 'perplexity', 'accuracy']

BATCH_SIZE = 32
env.build_pupil(
    batch_size=BATCH_SIZE,
    num_layers=2,
    num_hidden_nodes=[1000],
    input_shape=[784],
    num_classes=10,
    init_parameter=3.,
    additional_metrics=add_metrics,
    regime='training_with_meta_optimizer',
示例#29
0
dataset_path = os.path.join(*(['..'] * ROOT_HEIGHT +
                              ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

valid_size = 500

valid_text = text[:valid_size]
train_text = text[valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)
print(vocabulary_size)
tf.set_random_seed(1)
env = Environment(pupil_class=Lstm,
                  meta_optimizer_class=ResNet4Lstm,
                  batch_generator_classes=BatchGenerator,
                  vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
NUM_EXERCISES = 10
NUM_UNROLLINGS = 4
OPT_INF_NAME = 'COLD'
OPT_INF_RESTORE_PUPIL_PATHS = [(OPT_INF_NAME, None)]

env.build_pupil(batch_size=32,
                num_layers=1,
                num_nodes=[100],
                num_output_layers=1,
                num_output_nodes=[],
                vocabulary_size=vocabulary_size,
                embedding_size=150,
示例#30
0
dataset_path = os.path.join(*(['..'] * ROOT_HEIGHT +
                              ['datasets', 'text8.txt']))
with open(dataset_path, 'r') as f:
    text = f.read()

valid_size = 500

valid_text = text[:valid_size]
train_text = text[valid_size:]

vocabulary = create_vocabulary(text)
vocabulary_size = len(vocabulary)
print(vocabulary_size)

env = Environment(pupil_class=Lstm,
                  meta_optimizer_class=ArtDer,
                  batch_generator_classes=BatchGenerator,
                  vocabulary=vocabulary)

add_metrics = ['bpc', 'perplexity', 'accuracy']
tmpl = os.path.join(*['..'] * ROOT_HEIGHT +
                    [restore_path, 'checkpoints', '%s'])

BATCH_SIZE = 32
NUM_UNROLLINGS = 10
env.build_pupil(
    batch_size=BATCH_SIZE,
    num_layers=1,
    num_nodes=[100],
    num_output_layers=1,
    num_output_nodes=[],
    vocabulary_size=vocabulary_size,