train_tuner.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:neural-abstract-anaphora 作者: amarasovic 项目源码 文件源码
def precision_n(test_scores, num_true, n):
    """
    Precision at n measure is the number of instances where the any crowd's answer occur within ranker's firs n choices
    For more details take a look at: http://www.aclweb.org/anthology/D13-1030
    The first num_true_antec[i] dev_scores are predicted scores for true antecedents of the i-th sentence w/ PA

    :param test_scores: \in [batch_size, num of candidates], for every sent w\ PA predicted scores for its candidates
    :param num_true_antec: \in [batch_size], for every sent w\ PA number of true antecedents
    :return: list of size 10
    """
    precisions = []
    for i in range(n):
        precision = 0
        for k, item in enumerate(test_scores):
            ranks = len(item) - rankdata(item, method='ordinal').astype(int)
            precision += min(1, len(set(ranks[:i+1]) & set(range(num_true[k]))))
        precision /= float(len(test_scores))
        precision *= 100
        precisions.append(precision)
    return precisions
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号