def process_predictions(lengths, target, raw_predicted):
    """
    Removes padded positions from the predicted/observed values and
    calls inverse_transform if available.

    Args:
        lengths: Lengths of the entries in the dataset.
        target: Target feature instance.
        raw_predicted: Raw predicted/observed values.

    Returns:
        List of NumPy arrays: [(length, target_vals), ...].
    """
    if len(raw_predicted.shape) == 1:
        raw_predicted = raw_predicted[..., None]

    predicted = []
    start = 0
    for l in lengths:
        pred = raw_predicted[start:start+l]
        start += l
        if hasattr(target, 'inverse_transform'):
            pred = target.inverse_transform(pred)
        predicted.append(pred)

    return predicted