def compute_pos(f, t_gold, addition, t_pred):
    r"""
    Calculate the POS score.

    Arguments:
        f (str): the html file on which the question is based.
        t_gold (int): the gold answer tag id provided by the dataset (the value correspond to the key element_id).
        addition (int): the addition information used for yes/no question provided by the dataset (the value
                        corresponding to the key answer_start).
        t_pred (list[int]): the tag ids of the tags corresponding the each word in the predicted answer.
    Returns:
        float: the POS score.
    """
    h = BeautifulSoup(open(f), "lxml")
    p_gold, e_gold = set(), h.find(tid=t_gold)
    if e_gold is None:
        if len(t_pred) != 1:
            return 0
        else:
            t = t_pred[0]
            e_pred, e_prev = h.find(tid=t), h.find(tid=t-1)
            if (e_pred is not None) or (addition == 1 and e_prev is not None) or\
                    (addition == 0 and e_prev is None):
                return 0
            else:
                return 1
    else:
        p_gold.add(e_gold['tid'])
        for e in e_gold.parents:
            if int(e['tid']) < 2:
                break
            p_gold.add(e['tid'])
        p = None
        for t in t_pred:
            p_pred, e_pred = set(), h.find(tid=t)
            if e_pred is not None:
                p_pred.add(e_pred['tid'])
                if e_pred.name != 'html':
                    for e in e_pred.parents:
                        if int(e['tid']) < 2:
                            break
                        p_pred.add(e['tid'])
            else:
                p_pred.add(str(t))
            if p is None:
                p = p_pred
            else:
                p = p & p_pred
        return len(p_gold & p) / len(p_gold | p)

    Calculate the POS score.

    Arguments:
        f (str): the html file on which the question is based.
        t_gold (int): the gold answer tag id provided by the dataset (the value correspond to the key element_id).
        addition (int): the addition information used for yes/no question provided by the dataset (the value
                        corresponding to the key answer_start).
        t_pred (list[int]): the tag ids of the tags corresponding the each word in the predicted answer.
    Returns:
        float: the POS score.
    
xdoc/fine_tuning/websrc/trainer.py