import re


def _do_use_weight_decay(param_name, weight_decay_rate, exclude_from_weight_decay):
    """Whether to use L2 weight decay for `param_name`."""
    if not weight_decay_rate:
        return False
    if exclude_from_weight_decay:
        for r in exclude_from_weight_decay:
            if re.search(r, param_name) is not None:
                return False
    return True