convolutional_attention/f1_evaluator.py
def token_precision_recall(predicted_parts, gold_set_parts):
    """
    Get the precision/recall for the given token.

    :param predicted_parts: a list of predicted parts
    :param gold_set_parts: a list of the golden parts
    :return: precision, recall, f1 as floats
    """
    ground = [tok.lower() for tok in gold_set_parts]

    tp = 0
    for subtoken in set(predicted_parts):
        if subtoken == "***" or subtoken is None:
            continue  # Ignore UNKs
        if subtoken.lower() in ground:
            ground.remove(subtoken.lower())
            tp += 1

    assert tp <= len(predicted_parts), (tp, len(predicted_parts))
    if len(predicted_parts) > 0:
       precision = float(tp) / len(predicted_parts)
    else:
       precision = 0

    assert tp <= len(gold_set_parts), (tp, gold_set_parts)
    if len(gold_set_parts) > 0:
       recall = float(tp) / len(gold_set_parts)
    else:
       recall = 0

    if precision + recall > 0:
        f1 = 2 * precision * recall / (precision + recall)
    else:
        f1 = 0.
    return precision, recall, f1

    Get the precision/recall for the given token.

    :param predicted_parts: a list of predicted parts
    :param gold_set_parts: a list of the golden parts
    :return: precision, recall, f1 as floats
    
Get the precision/recall for the given token.
Get the precision / recall for the given token .
def token_precision_recall(predicted_parts, gold_set_parts):
    ground = [tok.lower() for tok in gold_set_parts]
    tp = 0
    for subtoken in set(predicted_parts):
        if subtoken == "***" or subtoken is None:
            continue  
        if subtoken.lower() in ground:
            ground.remove(subtoken.lower())
            tp += 1
    assert tp <= len(predicted_parts), (tp, len(predicted_parts))
    if len(predicted_parts) > 0:
       precision = float(tp) / len(predicted_parts)
    else:
       precision = 0
    assert tp <= len(gold_set_parts), (tp, gold_set_parts)
    if len(gold_set_parts) > 0:
       recall = float(tp) / len(gold_set_parts)
    else:
       recall = 0
    if precision + recall > 0:
        f1 = 2 * precision * recall / (precision + recall)
    else:
        f1 = 0.
    return precision, recall, f1
def token_precision_recall ( predicted_parts , gold_set_parts ) : ground = [ tok . lower ( ) for tok in gold_set_parts ] tp = 0 for subtoken in set ( predicted_parts ) : if subtoken == "***" or subtoken is None : continue if subtoken . lower ( ) in ground : ground . remove ( subtoken . lower ( ) ) tp += 1 assert tp <= len ( predicted_parts ) , ( tp , len ( predicted_parts ) ) if len ( predicted_parts ) > 0 : precision = float ( tp ) / len ( predicted_parts ) else : precision = 0 assert tp <= len ( gold_set_parts ) , ( tp , gold_set_parts ) if len ( gold_set_parts ) > 0 : recall = float ( tp ) / len ( gold_set_parts ) else : recall = 0 if precision + recall > 0 : f1 = 2 * precision * recall / ( precision + recall ) else : f1 = 0. return precision , recall , f1
Get the precision/recall for the given token.
Get the precision / recall for the given token .
"""
    Get the precision/recall for the given token.

    :param predicted_parts: a list of predicted parts
    :param gold_set_parts: a list of the golden parts
    :return: precision, recall, f1 as floats
    """ # Ignore UNKs
precision, recall, f1 as floats
precision recall f1 as floats
predicted_parts
a list of predicted parts
a list of predicted parts
gold_set_parts
a list of the golden parts
a list of the golden parts