for epoch in range(args.epochs):
            train_loss_span = 0
            train_loss_type = 0
            train_loss_degree = 0
            train_loss_pol = 0
            train_loss_cm = 0

            train_batches = 0
            start_time = time.time()

            pbar = ProgressBar(maxval=maxlen_train).start()

            for i, batch in enumerate(
                    iterate_minibatches_((X_train, Y_labels_train),
                                         args.minibatch,
                                         shuffle=True)):

                time.sleep(0.01)
                pbar.update(i + 1)

                inputs, labels = batch

                train_loss_span += train_fn_span(inputs, labels[:, 0:2])
                train_loss_type += train_fn_type(inputs, labels[:, 7:11])
                train_loss_degree += train_fn_degree(inputs, labels[:, 11:15])
                train_loss_pol += train_fn_pol(inputs, labels[:, 15:18])
                train_loss_cm += train_fn_cm(inputs, labels[:, 18:23])

                train_batches += 1
        for epoch in range(args.epochs):
            train_loss_span = 0
            train_loss_dcr = 0
            train_loss_type = 0
            train_loss_degree = 0
            train_loss_pol = 0
            train_loss_cm = 0
            train_loss_ca = 0
            train_loss_per = 0
            train_batches = 0
            start_time = time.time()

            pbar = ProgressBar(maxval=maxlen).start()

            for i, batch in enumerate(iterate_minibatches_((X_train, Y_labels_train), args.minibatch, shuffle=True)):

                time.sleep(0.01)
                pbar.update(i + 1)
     
                inputs, labels= batch

                train_loss_span += train_fn_span(inputs, labels[:,0:2])
                train_loss_dcr += train_fn_dcr(inputs, labels[:,2:6])
                train_loss_type += train_fn_type(inputs, labels[:,6:9])
                train_loss_degree += train_fn_degree(inputs, labels[:,9:12])
                train_loss_pol += train_fn_pol(inputs, labels[:,12:14])
                train_loss_cm += train_fn_cm(inputs, labels[:,14:18])
                train_loss_ca += train_fn_ca(inputs, labels[:,18:21])
                train_loss_per += train_fn_per(inputs, labels[:,21:24])
Esempio n. 3
0
        print("Starting training span model...")
        best_val_acc = 0

        maxlen_train = 0
        for x in range(0, len(X_train) - args.minibatch + 1, args.minibatch):
            maxlen_train += 1

        for epoch in range(args.epochs):
            train_loss = 0
            train_batches = 0
            start_time = time.time()

            pbar = ProgressBar(maxval=maxlen_train).start()

            for i, batch in enumerate(iterate_minibatches_((X_train, Y_labels_train), args.minibatch, shuffle=True)):

                time.sleep(0.01)
                pbar.update(i + 1)

                inputs, labels= batch
                train_loss += train_fn(inputs, labels)
                train_batches += 1

            pbar.finish()
     
            val_loss = 0
            val_acc = 0
            val_batches = 0

    input_var = T.imatrix("inputs")
    target_var = T.fmatrix("targets")

    wordEmbeddings = loadWord2VecMap(os.path.join(data_dir, "word2vec.bin"))
    wordEmbeddings = wordEmbeddings.astype(np.float32)

    train_fn, val_fn = build_network_2dconv(args, input_var, target_var, wordEmbeddings)

    print("Starting training...")
    best_val_acc = 0
    best_val_pearson = 0
    for epoch in range(args.epochs):
        train_err = 0
        train_batches = 0
        start_time = time.time()
        for batch in iterate_minibatches_((X_train, X_mask_train, Y_labels_train), args.minibatch, shuffle=True):

            inputs, _, labels = batch
            train_err += train_fn(inputs, labels)
            train_batches += 1

        val_err = 0
        val_acc = 0
        val_batches = 0
        val_pearson = 0

        for batch in iterate_minibatches_((X_dev, X_mask_dev, Y_labels_dev), len(X_dev), shuffle=False):

            inputs, inputs_mask, labels = batch

            err, acc = val_fn(inputs, labels)
            train_loss_span = 0
            train_loss_dcr = 0
            train_loss_type = 0
            train_loss_degree = 0
            train_loss_pol = 0
            train_loss_cm = 0
            train_loss_ca = 0
            train_loss_per = 0
            train_batches = 0
            start_time = time.time()

            pbar = ProgressBar(maxval=maxlen).start()

            for i, batch in enumerate(
                    iterate_minibatches_((X_train, Y_labels_train),
                                         args.minibatch,
                                         shuffle=True)):

                time.sleep(0.01)
                pbar.update(i + 1)

                inputs, labels = batch

                train_loss_span += train_fn_span(inputs, labels[:, 0:2])
                train_loss_dcr += train_fn_dcr(inputs, labels[:, 2:6])
                train_loss_type += train_fn_type(inputs, labels[:, 6:9])
                train_loss_degree += train_fn_degree(inputs, labels[:, 9:12])
                train_loss_pol += train_fn_pol(inputs, labels[:, 12:14])
                train_loss_cm += train_fn_cm(inputs, labels[:, 14:18])
                train_loss_ca += train_fn_ca(inputs, labels[:, 18:21])
                train_loss_per += train_fn_per(inputs, labels[:, 21:24])