# Buggy code
def preprocess_for_prediction(
    model_path,
    split,
    dataset_type="generic",
    data_csv=None,
    data_hdf5=None,
    train_set_metadata=None,
    only_predictions=False,
):
    """Preprocesses the dataset to parse it into a format that is usable by the
    Ludwig core
        :param model_path: The input data that is joined with the model
               hyperparameter file to create the model definition file
        :type model_path: Str
        :param dataset_type: Generic
        :type: Str
        :param split: Splits the data into the train and test sets
        :param data_csv: The CSV input data file
        :param data_hdf5: The hdf5 data file if there is no csv data file
        :param train_set_metadata: Train set metadata for the input features
        :param only_predictions: If False does not load output features
        :returns: Dataset, Train set metadata
    """
    model_definition = load_json(
        os.path.join(model_path, MODEL_HYPERPARAMETERS_FILE_NAME)
    )
    preprocessing_params = merge_dict(
        default_preprocessing_parameters, model_definition["preprocessing"]
    )

    # Check if hdf5 and json already exist
    if data_csv is not None:
        data_hdf5_fp = os.path.splitext(data_csv)[0] + ".hdf5"
        if os.path.isfile(data_hdf5_fp):
            logging.info(
                "Found hdf5 with the same filename of the csv, using it instead"
            )
            data_csv = None
            data_hdf5 = data_hdf5_fp

    # Load data
    _, _, build_dataset, _ = get_dataset_fun(dataset_type)
    train_set_metadata = load_metadata(train_set_metadata)
    features = model_definition["input_features"] + (
        [] if only_predictions else model_definition["output_features"]
    )
    if split == "full":
        if data_hdf5 is not None:
            dataset = load_data(
                data_hdf5,
                model_definition["input_features"],
                [] if only_predictions else model_definition["output_features"],
                split_data=False,
                shuffle_training=False,
            )
        else:
            dataset, train_set_metadata = build_dataset(
                data_csv,
                features,
                preprocessing_params,
                train_set_metadata=train_set_metadata,
            )
    else:
        if data_hdf5 is not None:
            training, test, validation = load_data(
                data_hdf5,
                model_definition["input_features"],
                [] if only_predictions else model_definition["output_features"],
                shuffle_training=False,
            )

            if split == "training":
                dataset = training
            elif split == "validation":
                dataset = validation
            else:  # if split == 'test':
                dataset = test
        else:
            dataset, train_set_metadata = build_dataset(
                data_csv,
                features,
                preprocessing_params,
                train_set_metadata=train_set_metadata,
            )

    replace_text_feature_level(
        model_definition["input_features"]
        + ([] if only_predictions else model_definition["output_features"]),
        [dataset],
    )

    dataset = Dataset(
        dataset,
        model_definition["input_features"],
        [] if only_predictions else model_definition["output_features"],
        data_hdf5,
    )

    return dataset, train_set_metadata


# Traceback (ValueError)
Traceback (most recent call last):
File "/home/andrey/.venvs/ludwig-learn/bin/ludwig", line 11, in <module>
sys.exit(main())
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/cli.py", line 86, in main
CLI()
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/cli.py", line 64, in __init__
getattr(self, args.command)()
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/cli.py", line 73, in predict
predict.cli(sys.argv[2:])
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/predict.py", line 379, in cli
full_predict(**vars(args))
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/predict.py", line 104, in full_predict
debug
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/predict.py", line 173, in predict
gpu_fraction=gpu_fraction
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/models/model.py", line 1182, in predict
only_predictions=only_predictions
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/ludwig/models/model.py", line 756, in batch_evaluation
is_training=is_training
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run
run_metadata_ptr)
File "/home/andrey/.venvs/ludwig-learn/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1128, in _run
str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (1,) for Tensor 'image_path/image_path:0', which has shape '(?, 100, 100, 3)'

# Fixed code
def preprocess_for_prediction(
    model_path,
    split,
    dataset_type="generic",
    data_csv=None,
    data_hdf5=None,
    train_set_metadata=None,
    only_predictions=False,
):
    """Preprocesses the dataset to parse it into a format that is usable by the
    Ludwig core
        :param model_path: The input data that is joined with the model
               hyperparameter file to create the model definition file
        :type model_path: Str
        :param dataset_type: Generic
        :type: Str
        :param split: Splits the data into the train and test sets
        :param data_csv: The CSV input data file
        :param data_hdf5: The hdf5 data file if there is no csv data file
        :param train_set_metadata: Train set metadata for the input features
        :param only_predictions: If False does not load output features
        :returns: Dataset, Train set metadata
    """
    model_definition = load_json(
        os.path.join(model_path, MODEL_HYPERPARAMETERS_FILE_NAME)
    )
    preprocessing_params = merge_dict(
        default_preprocessing_parameters, model_definition["preprocessing"]
    )

    # Check if hdf5 and json already exist
    if data_csv is not None:
        data_hdf5_fp = os.path.splitext(data_csv)[0] + ".hdf5"
        if os.path.isfile(data_hdf5_fp):
            logging.info(
                "Found hdf5 with the same filename of the csv, using it instead"
            )
            data_csv = None
            data_hdf5 = data_hdf5_fp

    # Load data
    _, _, build_dataset, _ = get_dataset_fun(dataset_type)
    train_set_metadata = load_metadata(train_set_metadata)
    features = model_definition["input_features"] + (
        [] if only_predictions else model_definition["output_features"]
    )
    if split == "full":
        if data_hdf5 is not None:
            dataset = load_data(
                data_hdf5,
                model_definition["input_features"],
                [] if only_predictions else model_definition["output_features"],
                split_data=False,
                shuffle_training=False,
            )
        else:
            dataset, train_set_metadata = build_dataset(
                data_csv,
                features,
                preprocessing_params,
                train_set_metadata=train_set_metadata,
            )
    else:
        if data_hdf5 is not None:
            training, test, validation = load_data(
                data_hdf5,
                model_definition["input_features"],
                [] if only_predictions else model_definition["output_features"],
                shuffle_training=False,
            )

            if split == "training":
                dataset = training
            elif split == "validation":
                dataset = validation
            else:  # if split == 'test':
                dataset = test
        else:
            dataset, train_set_metadata = build_dataset(
                data_csv,
                features,
                preprocessing_params,
                train_set_metadata=train_set_metadata,
            )

    replace_text_feature_level(
        model_definition["input_features"]
        + ([] if only_predictions else model_definition["output_features"]),
        [dataset],
    )

    dataset = Dataset(
        dataset,
        model_definition["input_features"],
        [] if only_predictions else model_definition["output_features"],
        data_hdf5_fp,
    )

    return dataset, train_set_metadata