Ejemplo n.º 1
0
    davidson_te = DataSet(os.path.join("data", "davidson.te.csv"),
                          reader=csvreader,
                          formatter=df,
                          name="davidson_test")
    davidson_te.read()

    features = Features(get_feature_functions(mname))
    primary_train_fs, aux_train_fs, dev_fs, test_fs_primary, test_fs_aux = features.load(
        waseem_tr_composite, davidson_tr, waseem_de_composite,
        waseem_te_composite, davidson_te)

    print("Number of features in primary: {0}".format(
        primary_train_fs[0].shape[1]))
    print("Number of features aux (=): {0}".format(aux_train_fs[0].shape[1]))

    model = MTMLP(primary_train_fs[0].shape[1], get_model_shape(), 3, 3)

    if gpu():
        model.cuda()

    if model_exists(mname) and os.getenv("TRAIN").lower() not in [
            "y", "1", "t", "yes"
    ]:
        model.load_state_dict(torch.load("models/{0}.model".format(mname)))
    else:
        train_mt(model, (primary_train_fs, aux_train_fs),
                 50,
                 1e-3,
                 45,
                 dev=dev_fs,
                 lr_schedule=lambda a, b: exp_lr_scheduler(a, b, 0.5, 5))
Ejemplo n.º 2
0
    waseem_te_composite = CompositeDataset(name="waseem_composite_test")
    for dataset in datasets_te:
        dataset.read()
        waseem_te_composite.add(dataset)



    davidson_te = DataSet(os.path.join("data","davidson.te.csv"),reader=csvreader,formatter=df,name="davidson_test")
    davidson_te.read()

    features = Features(get_feature_functions(mname))
    train_fs, dev_fs, test_fs_primary, test_fs_aux = features.load(waseem_tr_composite, waseem_de_composite, waseem_te_composite, davidson_te)

    print("Number of features in primary: {0}".format(train_fs[0].shape[1]))

    model = MLP(train_fs[0].shape[1],get_model_shape(),3)

    if gpu():
        model.cuda()

    if model_exists(mname) and os.getenv("TRAIN").lower() not in ["y","1","t","yes"]:
        model.load_state_dict(torch.load("models/{0}.model".format(mname)))
    else:
        train(model, train_fs, 50, 1e-3, 45, dev=dev_fs,
              lr_schedule=lambda a, b: exp_lr_scheduler(a, b, 0.5, 5))
        torch.save(model.state_dict(), "models/{0}.model".format(mname))


    create_log_dir(mname)
    print_evaluation(model,test_fs_primary, WaseemLabelSchema(),log="logs/{0}/primary.jsonl".format(mname))
    print_evaluation(model,test_fs_aux, WaseemLabelSchema(),log="logs/{0}/aux.jsonl".format(mname))