def _validate_target(target, output_shape):
    """
    Check whether ``target``, 
    an integer index into the model's output
    is valid for the given ``output_shape``.
    """
    if isinstance(target, int):
        output_nodes = output_shape[1:][0]
        if not 0 <= target < output_nodes:
            raise ValueError(
                'Prediction target index is outside the required range [0, {}). '
                , 'Got {}'.format(output_nodes, target))
    else:
        raise TypeError('Prediction target must be int. Got: {}'.format(target)
            )
