Exemple #1
0
def record(seed, use_seed, device, epochs, batch_size, representations,
           metrics):
    """
    Start and record the learning phase of the neural network.
    """
    from user_data import datasets, models
    if not os.path.exists(RECORDS_PATH):
        os.mkdir(RECORDS_PATH)

    if use_seed:
        if seed is None:
            seed = DEFAULT_SEED
        else:
            click.echo(f'Seed set to {seed} for Python, Numpy and PyTorch.\n')
        set_seeds(seed)
    else:
        click.echo('Not using a seed. Results will not be reproducible...\n')

    device = set_device(device)

    click.echo('Loaded models:')
    for model in models.keys():
        click.echo(f'- {model}')
    click.echo('')

    click.echo('Loaded datasets:')
    for ds in datasets:
        click.echo(f'- {ds.name}')
    click.echo('')

    if metrics == 'all':
        metrics = metrics_list.keys()
    else:
        metrics = re.sub(r"[^\w]", ' ', metrics).split()
    #click.echo('Metrics:')
    #for metric in metrics:
    #    click.echo(f'- {metric}')
    #click.echo('')

    if representations == 'all':
        representations = list(projections_list.keys())
    else:
        representations = re.sub(r"[^\w]", ' ', representations).split()
    click.echo('Representations:')
    for representation in representations:
        click.echo(f'- {representation}')
    click.echo('')

    start_record(models, datasets, device, batch_size, representations, epochs,
                 metrics)
#V0 is two level loss straight, no balance
#V1 is the switching loss on 2 loss (top and both level)
#V1.5 is a training on the second level, then finetune with information on first level. Model used will need to be hand picked
#V2 is the iterating version of 3 losses (top low both levels)
#V3 is module learning it's loss weights

sentence_hidden_state_size = 20
paragraph_hidden_state_size = 10
nb_layers = 1
patience = 20
cooldown = 5
batch_size=4
epoch = 70
seed = 420
drop_out = 0.5
set_seeds(seed)
optimizer = "adam"
test_name = "paper_loss_phs{}_shs{}_patience{}_cd{}_{}l_bs{}_op{}_do{}_noupscale_seed{}_test".format(
    paragraph_hidden_state_size, sentence_hidden_state_size, patience, cooldown, nb_layers, batch_size, optimizer,drop_out, seed
)




train_pickled = pickle.load(open("./data/{}/{}/preprocessed_train.pkl".format(aggregation, dataset),'rb'))
valid_pickled = pickle.load(open("./data/{}/{}/preprocessed_valid.pkl".format(aggregation, dataset), 'rb'))
test_pickled = pickle.load(open("./data/{}/{}/preprocessed_test.pkl".format(aggregation, dataset), 'rb'))

# preprocessed_train = [datapoint for _, _, _, _,datapoint in train_pickled]
# preprocessed_valid = [datapoint for _, _, _, _, datapoint in valid_pickled]