def validate_hparams(hparams):
    """
    Limited number of checks performed on the validity of the hyperparameters.
    The file is generally considered to follow the semantics of the
    mpunet.bin.defaults hyperparameter files.

    Args:
        hparams: A YAMLHParams object
    """
    if hparams['fit'].get('class_weights') and hparams['fit']['loss'] not in (
        'SparseFocalLoss',):
        raise ValueError(
            "Invalid loss function '{}' used with the 'class_weights' parameter"
            .format(hparams['fit']['loss']))
    if hparams['fit']['loss'] == 'WeightedCrossEntropyWithLogits':
        if not bool(hparams['fit']['class_weights']):
            raise ValueError(
                "Must specify 'class_weights' argument with loss'WeightedCrossEntropyWithLogits'."
                )
        if not hparams['build']['out_activation'] == 'linear':
            raise ValueError(
                "Must use out_activation: linear parameter with loss 'WeightedCrossEntropyWithLogits'"
                )
    if not hparams['train_data']['base_dir']:
        raise ValueError('No training data folder specified in parameter file.'
            )
