<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def validate(reference_patterns, estimated_patterns):
 """Checks that the input annotations to a metric look like valid pattern lists, and throws helpful errors if not. Parameters reference_patterns : list The reference patterns using the format returned by :func:`mir_eval.io.load_patterns()` estimated_patterns : list The estimated patterns in the same format Returns ------- """

    # Warn if pattern lists are empty
    if _n_onset_midi(reference_patterns) == 0:
        warnings.warn('Reference patterns are empty.')
    if _n_onset_midi(estimated_patterns) == 0:
        warnings.warn('Estimated patterns are empty.')
    for patterns in [reference_patterns, estimated_patterns]:
        for pattern in patterns:
            if len(pattern) <= 0:
                raise ValueError("Each pattern must contain at least one "
                                 "occurrence.")
            for occurrence in pattern:
                for onset_midi in occurrence:
                    if len(onset_midi) != 2:
                        raise ValueError("The (onset, midi) tuple must "
                                         "contain exactly 2 elements.")