def page_level_constraint(vertical, target_website,
                          lines, sub_output_dir):
    """Takes the top highest prediction for empty field by ranking raw scores."""
    """
    In this step, we make sure every node has a prediction
    """

    tags = constants.ATTRIBUTES_PLUS_NONE[vertical]

    site_field_truth_exist = dict()
    page_field_max = dict()
    page_field_pred_count = dict()
    for line in lines:
        items = line.split("\t")
        assert len(items) >= 5, items
        html_path = items[0]
        truth = items[3]
        pred = items[4]
        if pred != "none":
            if pred not in page_field_pred_count:
                page_field_pred_count[pred] = 0
            page_field_pred_count[pred] += 1
            continue
        raw_scores = [float(x) for x in items[5].split(",")]
        assert len(raw_scores) == len(tags)
        site_field_truth_exist[truth] = True
        for index, score in enumerate(raw_scores):
            if html_path not in page_field_max:
                page_field_max[html_path] = {}
            if tags[index] not in page_field_max[
                html_path] or score >= page_field_max[html_path][tags[index]]:
                page_field_max[html_path][tags[index]] = score
    print(page_field_pred_count, file=sys.stderr)
    voted_lines = []
    for line in lines:
        items = line.split("\t")
        assert len(items) >= 5, items
        html_path = items[0]
        raw_scores = [float(x) for x in items[5].split(",")]
        pred = items[4]
        for index, tag in enumerate(tags):
            if tag in site_field_truth_exist and tag not in page_field_pred_count:
                if pred != "none":
                    continue
                if raw_scores[index] >= page_field_max[html_path][tags[index]] - (1e-3):
                    items[4] = tag
        voted_lines.append("\t".join(items))

    return site_level_voting(
        vertical, target_website, sub_output_dir, voted_lines)
Takes the top highest prediction for empty field by ranking raw scores.
markuplm/examples/fine_tuning/run_swde/eval_utils.py