Exemplo n.º 1
0
if __name__ == "__main__":
    # parse the command line arguments
    parser = argparse.ArgumentParser()
    parser.set_defaults(epochs=200)
    parser.add_argument('--data',
                        help='prepared data CSV file path',
                        type=validate_existing_filepath)
    parser.add_argument('--model',
                        help='path to the trained model file',
                        type=validate_existing_filepath)
    parser.add_argument(
        '--print_stats',
        action='store_true',
        default=False,
        help='print evaluation stats for the model predictions - if '
        'your data has tagging')
    parser.add_argument('--output',
                        help='path to location for inference output file',
                        type=validate_parent_exists)
    args = parser.parse_args()
    data_path = absolute_path(args.data)
    model_path = absolute_path(args.model)
    print_stats = args.print_stats
    output_path = absolute_path(args.output)
    data_set = NpSemanticSegData(data_path)
    results = classify_collocation(data_set.test_set, model_path, args.epochs)
    if print_stats and (data_set.is_y_labels is not None):
        y_labels = data_set.test_set_y
        print_evaluation(y_labels, results)
    write_results(results, output_path)
Exemplo n.º 2
0
            writer.writerow([result])
    print("Results of inference saved in {0}".format(output))


if __name__ == "__main__":
    # parse the command line arguments
    parser = NeonArgparser()
    parser.set_defaults(epochs=200)
    parser.add_argument('--data', help='prepared data CSV file path',
                        type=validate_existing_filepath)
    parser.add_argument('--model', help='path to the trained model file',
                        type=validate_existing_filepath)
    parser.add_argument('--print_stats', action='store_true', default=False,
                        help='print evaluation stats for the model predictions - if '
                        'your data has tagging')
    parser.add_argument('--output', help='path to location for inference output file',
                        type=validate_parent_exists)
    args = parser.parse_args()
    data_path = absolute_path(args.data)
    model_path = absolute_path(args.model)
    print_stats = args.print_stats
    output_path = absolute_path(args.output)
    # generate backend
    be = gen_backend(batch_size=10)
    data_set = NpSemanticSegData(data_path, train_to_test_ratio=1)
    results = classify_collocation(data_set, model_path, args.epochs, args.callback_args)
    if print_stats and (data_set.is_y_labels is not None):
        y_labels = extract_y_labels(data_path)
        print_evaluation(y_labels, results.argmax(1))
    write_results(results.argmax(1), output_path)
Exemplo n.º 3
0
    model.save(model_file_path)
    # set evaluation error rates
    error_rate, test_accuracy_rate, precision_recall_rate = model.eval(dataset.test_set)
    neon_logger.display('Misclassification error = %.1f%%' %
                        (error_rate * 100))
    neon_logger.display('Test accuracy rate = %.1f%%' %
                        (test_accuracy_rate * 100))
    neon_logger.display('precision rate = %s!!' %
                        (str(precision_recall_rate[0])))
    neon_logger.display('recall rate = %s!!' %
                        (str(precision_recall_rate[1])))


if __name__ == "__main__":
    # parse the command line arguments
    parser = NeonArgparser()
    parser.set_defaults(epochs=200)
    parser.add_argument('--data', type=validate_existing_filepath,
                        help='Path to the CSV file where the prepared dataset is saved')
    parser.add_argument('--model_path', type=validate_parent_exists,
                        help='Path to save the model')
    args = parser.parse_args()
    data_path = absolute_path(args.data)
    model_path = absolute_path(args.model_path)
    # generate backend
    be = gen_backend(batch_size=64)
    # load data sets from file
    data_set = NpSemanticSegData(data_path, train_to_test_ratio=0.8)
    # train the mlp classifier
    train_mlp_classifier(data_set, model_path, args.epochs, args.callback_args)
Exemplo n.º 4
0
    input_dim = dataset.train_set_x.shape[1]
    model.build(input_dim)
    # run fit
    model.fit(dataset.train_set)
    # save model params
    model.save(model_file_path)
    # set evaluation error rates
    loss, binary_accuracy, precision, recall, f1 = model.eval(dataset.test_set)
    print('loss = %.1f%%' % (loss))
    print('Test binary_accuracy rate = %.1f%%' % (binary_accuracy * 100))
    print('Test precision rate = %.1f%%' % (precision * 100))
    print('Test recall rate = %.1f%%' % (recall * 100))
    print('Test f1 rate = %.1f%%' % (f1 * 100))


if __name__ == "__main__":
    # parse the command line arguments
    parser = argparse.ArgumentParser()
    parser.set_defaults(epochs=200)
    parser.add_argument('--data', type=validate_existing_filepath,
                        help='Path to the CSV file where the prepared dataset is saved')
    parser.add_argument('--model_path', type=validate_parent_exists,
                        help='Path to save the model')
    args = parser.parse_args()
    data_path = absolute_path(args.data)
    model_path = absolute_path(args.model_path)
    # load data sets from file
    data_set = NpSemanticSegData(data_path, train_to_test_ratio=0.8)
    # train the mlp classifier
    train_mlp_classifier(data_set, model_path, args.epochs)
Exemplo n.º 5
0
            writer.writerow(result_row)


def preprocess_tratz_2011(folder_path):
    """
    Pre-process tratz_2011 dataset

    Args:
        folder_path (str): path to the unzipped tratz_2011 dataset
    """
    files = ['tratz2011_coarse_grained_random/train.tsv', 'tratz2011_coarse_grained_random/'
                                                          'val.tsv']
    dicts = [tratz2011_train_labeled_dict, tratz2011_val_labeled_dict]
    # 1. get abs path
    if not os.path.isabs(folder_path):
        # handle case using default value\relative paths
        folder_path = os.path.join(os.path.dirname(__file__), folder_path)
    # 2. add the location of the train file in the folder
    for file, dic in zip(files, dicts):
        file_full_path = os.path.join(folder_path, file)
        read_from_tratz_2011(file_full_path, dic)


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Pre-process Tratz 2011 data from tsv to csv')
    parser.add_argument('--data', type=validate_existing_directory,
                        help='path the Tratz_2011_dataset folder local path')
    args = parser.parse_args()
    data_path = absolute_path(args.data)
    preprocess_tratz_2011(data_path)