examples/text_to_knowledge/ernie-ctm/metric.py
def wordtag_hard_acc(list_a: List[Tuple[str, str]],
                     list_b: List[Tuple[str, str]]) -> float:
    """
    Calculate extra metrics of word-tag

    Args:
        list_a: prediction list
        list_b: real list

    Returns:
        acc: the extra accuracy
    """
    p, q = 0, 0
    a_l, b_l = 0, 0
    acc = 0.0
    while q < len(list_b) and p < len(list_a):
        a_r = a_l + len(list_a[p][0]) - 1
        b_r = b_l + len(list_b[q][0]) - 1
        if a_r < b_l:
            p += 1
            a_l = a_r + 1
            continue
        if b_r < a_l:
            q += 1
            b_l = b_r + 1
            continue
        if a_l == b_l and a_r == b_r:
            if list_a[p][-1] == list_b[q][-1]:
                acc += 1.0
            p += 1
            q += 1
            a_l, b_l = a_r + 1, b_r + 1
            continue
        p += 1
    return acc

    Calculate extra metrics of word-tag

    Args:
        list_a: prediction list
        list_b: real list

    Returns:
        acc: the extra accuracy
    
Calculate extra metrics of word-tag
Calculate extra metrics of word - tag
def wordtag_hard_acc(list_a: List[Tuple[str, str]],
                     list_b: List[Tuple[str, str]]) -> float:
    p, q = 0, 0
    a_l, b_l = 0, 0
    acc = 0.0
    while q < len(list_b) and p < len(list_a):
        a_r = a_l + len(list_a[p][0]) - 1
        b_r = b_l + len(list_b[q][0]) - 1
        if a_r < b_l:
            p += 1
            a_l = a_r + 1
            continue
        if b_r < a_l:
            q += 1
            b_l = b_r + 1
            continue
        if a_l == b_l and a_r == b_r:
            if list_a[p][-1] == list_b[q][-1]:
                acc += 1.0
            p += 1
            q += 1
            a_l, b_l = a_r + 1, b_r + 1
            continue
        p += 1
    return acc
def wordtag_hard_acc ( list_a : List [ Tuple [ str , str ] ] , list_b : List [ Tuple [ str , str ] ] ) -> float : p , q = 0 , 0 a_l , b_l = 0 , 0 acc = 0.0 while q < len ( list_b ) and p < len ( list_a ) : a_r = a_l + len ( list_a [ p ] [ 0 ] ) - 1 b_r = b_l + len ( list_b [ q ] [ 0 ] ) - 1 if a_r < b_l : p += 1 a_l = a_r + 1 continue if b_r < a_l : q += 1 b_l = b_r + 1 continue if a_l == b_l and a_r == b_r : if list_a [ p ] [ - 1 ] == list_b [ q ] [ - 1 ] : acc += 1.0 p += 1 q += 1 a_l , b_l = a_r + 1 , b_r + 1 continue p += 1 return acc
Calculate extra metrics of word-tag
Calculate extra metrics of word - tag
"""
    Calculate extra metrics of word-tag

    Args:
        list_a: prediction list
        list_b: real list

    Returns:
        acc: the extra accuracy
    """
the extra accuracy
the extra accuracy
acc
list_a
List[Tuple[str, str]]
None
list_b
List[Tuple[str, str]]
None