AI Wiki中文/EN

实体链接:这处Mercury指的是谁?

Entity linking

用别名和上下文排序候选,分清候选缺失与决策不确定。

本页目录直觉理解数学与方法代码实现局限与误解实验与练习研究脉络

同一个提及,可能指向不同实体

“Mercury的轨道很特别”和“Mercury是一种有毒液体”使用同样的拼写。把两处都链接到行星,文字看起来没变,意思却错了。实体链接把上下文中的提及对应到目标知识库的实体ID。找出提及在文本中的位置,是另一项任务。

Hogan等说明了歧义的两个方向:同一实体可以有多个别名,同一个提及也可以指向不同实体。PDF第51页BLINK研究给定提及后的链接,用双编码器召回候选,再用交叉编码器重排。其评测假定知识库中存在正确实体,明确没有处理NIL预测。PDF第2—3页

本文的透明基线使用别名表和实体描述,拟合TF-IDF统计,将上下文相似度与别名频率组合,并允许拒绝决策。拒绝只表示“这个基线不选择”,不等于“现实实体一定不在知识库中”。

同一Mercury提及随上下文选择不同候选,并明确显示候选缺失与证据不足。
同一Mercury提及随上下文选择不同候选,并明确显示候选缺失与证据不足。

把召回、证据和最终决策分开

对提及m,别名表提供候选集合C(m)及正计数n(m,e)。把计数归一化,得到以提及为条件的先验:

p(e∣m)=n(m,e)∑j∈C(m)n(m,j).p(e\mid m)=\frac{n(m,e)}{\sum_{j\in C(m)}n(m,j)}.

这个先验表达表里的频率证据,不代表当前上下文。原创Mercury例子的计数为:行星60、金属30、信使10。没有上下文时,即使句子谈中毒,行星仍会获胜。

用N份实体描述拟合逆文档频率。df(w)是含词w的描述数,tf(w,d)是词在描述或上下文d中的出现次数。这里采用:

idf⁡(w)=1+log⁡N+1df⁡(w)+1,vw(d)=tf⁡(w,d)idf⁡(w).\operatorname{idf}(w)=1+\log\frac{N+1}{\operatorname{df}(w)+1},\qquad v_w(d)=\operatorname{tf}(w,d)\operatorname{idf}(w).

常数用于平滑罕见词。上下文中不在词表里的词不作贡献。将每个非零向量归一化到单位长度后,点积就是余弦相似度;空向量或全部词都未知时,按本例约定把相似度设为零:

c(d,e)={v(d)⊤v(e)∥v(d)∥2∥v(e)∥2∥v(d)∥2∥v(e)∥2>0,0otherwise.c(d,e)=\begin{cases}\dfrac{v(d)^\top v(e)}{\|v(d)\|_2\|v(e)\|_2}&\|v(d)\|_2\|v(e)\|_2>0,\\0&\text{otherwise}.\end{cases}

小型排序器使用明确给出的凸组合,并非学到的BERT分数:

s(e;m,d)=(1−α)c(d,e)+αp(e∣m),α=0.15.s(e;m,d)=(1-\alpha)c(d,e)+\alpha p(e\mid m),\qquad\alpha=0.15.

每份描述有四个不同词。上下文命中其中三个时,余弦为√3/2。于是,行星、金属、信使的对应上下文分数分别约为0.826122、0.781122、0.751122。上下文能战胜更常见的行星别名。换到一般数据,这个评分公式的α仍需经验证集选择。

设e₁、e₂是得分最高的两个候选,τ为绝对阈值,δ为分差阈值。决策规则为:

e^={e1C(m)≠∅, s1≥τ, s1−s2≥δ,abstainotherwise,τ=0.35,δ=0.08.\widehat e=\begin{cases}e_1&C(m)\ne\varnothing,\ s_1\ge\tau,\ s_1-s_2\ge\delta,\\\mathrm{abstain}&\text{otherwise},\end{cases}\qquad \tau=0.35,\quad\delta=0.08.

只有一个候选时,将分差视为无穷,但仍检查绝对阈值。候选为空时单独返回no-candidate原因。分数不是校准概率;证据很少时,即使相对分差大,也不应强迫系统作出选择。

对于只能从候选集选择的重排器,召回给出了硬上限。在正确实体都位于知识库中的评测数据上:

accuracy⁡end-to-end≤recall⁡candidate=1M∑i=1M1[ei∗∈C(mi)].\operatorname{accuracy}_{\rm end\text{-}to\text{-}end}\le\operatorname{recall}_{\rm candidate}=\frac1M\sum_{i=1}^{M}\mathbf1[e_i^*\in C(m_i)].

原因很直接:要输出正确实体,必须先把它召回。但召回率不等于准确率,进入候选的实体仍可能排错或被拒绝。BLINK的双编码器与交叉编码器划分,正是用学习表示处理这两个不同阶段。PDF第3页

让候选失败显露出来

完整程序使用Python3.12标准库。提及已给定,描述和频率均为原创例子。英文词由小型正则表达式切分;中文“水星”只是完整匹配的别名字符串,不表示程序实现了中文分词。

"""Authored alias/TF-IDF linking baseline, not BLINK or a NIL classifier.

Mention spans are given. Threshold abstention does not prove out-of-KB status.
"""
import json
import math
import re
from collections import Counter


def tokens(text):
    return re.findall(r"[a-z]+", text.casefold())


def fit(descriptions):
    if not descriptions:
        raise ValueError("Need entity descriptions")
    counts = {e: Counter(tokens(text)) for e, text in descriptions.items()}
    df = Counter(w for c in counts.values() for w in c)
    idf = {w: math.log((1 + len(counts)) / (1 + d)) + 1 for w, d in df.items()}

    def vector(text_counts):
        v = {w: c * idf[w] for w, c in text_counts.items() if w in idf}
        norm = math.sqrt(sum(x*x for x in v.values()))
        return {w: x/norm for w, x in v.items()} if norm else {}
    return idf, {e: vector(c) for e, c in counts.items()}


def rank(mention, context, aliases, model, prior_weight=0.15):
    if not math.isfinite(prior_weight) or not 0 <= prior_weight <= 1:
        raise ValueError("Prior weight must lie in [0,1]")
    idf, entities = model
    candidates = aliases.get(mention.casefold(), {})
    if not candidates:
        return []
    if any(e not in entities or not math.isfinite(c) or c <= 0 for e, c in candidates.items()):
        raise ValueError("Positive alias counts and known entity descriptions required")
    counts = Counter(tokens(context))
    v = {w: c*idf[w] for w, c in counts.items() if w in idf}
    norm = math.sqrt(sum(x*x for x in v.values()))
    v = {w: x/norm for w, x in v.items()} if norm else {}
    total = sum(candidates.values())
    scores = [(e, (1-prior_weight)*sum(x*entities[e].get(w, 0) for w, x in v.items())
               + prior_weight*c/total) for e, c in candidates.items()]
    return sorted(scores, key=lambda row: (-row[1], row[0]))


def decide(scores, threshold=0.35, margin=0.08):
    if not math.isfinite(threshold) or not math.isfinite(margin) or margin < 0:
        raise ValueError("Finite threshold and nonnegative margin required")
    if not scores:
        return None, "no-candidate"
    ordered = sorted(scores, key=lambda row: (-row[1], row[0]))
    if any(not math.isfinite(s) for _, s in ordered):
        raise ValueError("Scores must be finite")
    gap = ordered[0][1]-ordered[1][1] if len(ordered) > 1 else math.inf
    if ordered[0][1] < threshold or gap < margin:
        return None, "abstain"
    return ordered[0][0], "linked"


def demo():
    descriptions = {"planet": "planet orbit sun space", "metal": "metal liquid element toxic",
                    "messenger": "roman god winged messenger"}
    aliases = {"mercury": {"planet": 60, "metal": 30, "messenger": 10}, "水星": {"planet": 5}}
    model = fit(descriptions)
    contexts = ["orbit planet sun", "toxic liquid metal", "winged roman god", "unknown news"]
    results = []
    for context in contexts:
        scores = rank("Mercury", context, aliases, model)
        entity, reason = decide(scores)
        results.append(dict(context=context, scores=scores, entity=entity, reason=reason))
    truncated = {"mercury": {"planet": 60, "messenger": 10}}
    return dict(results=results, missing_alias=decide(rank("Vulcan", "planet", aliases, model)),
                removed_gold=decide(rank("Mercury", "toxic liquid metal", truncated, model)),
                scope="Synthetic descriptions and counts; thresholds not calibrated probabilities")


if __name__ == "__main__":
    print(json.dumps(demo(), indent=2))

轨道、有毒液体、带翅膀的神三个上下文选中不同实体。“Unknown news”没有命中词表,被拒绝。Vulcan没有别名条目,因此返回no-candidate。把金属从Mercury候选中删掉后,有毒液体的例子只能拒绝,排序器不会创造缺失ID。

对T次词项出现,拟合词表统计的期望时间为O(T),之后做稀疏归一化。若上下文有q个非零词、别名候选有c个,本实现的相似度循环耗时O(cq),排序耗时O(c log c)。大型知识库需要索引召回,不能逐一扫描全部实体。描述和权重模型不变时,已存的实体向量可以复用。

拒绝结果还需要解释

证据不足可能来自陌生表达、别名遗漏、上下文过短、句子歧义,也可能确实没有相应实体。这些情况需要不同修复办法。应分别测候选召回率、链接准确率和决策覆盖率;只在接受的案例上算准确率,可能掩盖大量难题都被拒绝的事实。

别名先验可能过度偏向热门实体,描述可能缺少决定性属性,词汇匹配也可能支持错误词义。局部提及模型还会遗漏整篇文档的一致性。这个基线的价值是把这些机制摊开看,既不复现BLINK训练,也不把阈值包装成已验证的开放集检测器。Hogan关于别名和上下文歧义的讨论提供了更广的整合背景。PDF第51页

改模型之前,先找出错误发生在哪

  1. 识别出了“Mercury”这段文字,就确定实体了吗?答案:没有。提及检测定位文字;链接仍要根据候选和上下文选择标识符。
  2. 余弦为√3/2、行星别名占比为0.6时,行星得分是多少?答案:0.85×√3/2+0.15×0.6≈0.826122,其中频率项贡献0.09。
  3. 一百个库内案例中,正确实体只有八十次进入候选。这个仅从候选中选择的重排器能达到90%端到端准确率吗?答案:不能。不改召回、也不允许候选外输出时,上限是80%。
  4. 系统准确率很高,却拒绝了一半提及,还应报告什么?答案:覆盖率、候选召回率、已接受链接的正确性,以及被拒绝、库内和库外案例的表现。阈值应在合适验证数据上选择,不能看过测试标签才决定。

神经召回改变表示,不改变评测需要交代的事

BLINK分别编码提及上下文和实体描述进行召回,再联合编码候选配对进行重排。本文TF-IDF实现使用不同特征,没有神经训练,但仍要问同样的问题:正确候选被召回了吗,提及边界是给定还是预测的,评测是否包含库外实体?双塔模型进一步讨论可复用编码;知识图谱说明实体ID如何影响后续陈述。

先判断,再看解释

正确实体未进入任何候选,重排器还能选中它吗?

选择一个答案

学习目标

  • 区分提及检测、候选召回、消歧和拒绝决策,计算透明基线。
  • 计算候选召回率给出的上限,分别报告覆盖率和已接受链接准确率。

先修与延伸

查看知识关联图 →

参考文献

  1. Scalable Zero-shot Entity Linking with Dense Entity Retrieval
    Ledell Wu; Fabio Petroni; Martin Josifoski; Sebastian Riedel; Luke Zettlemoyer · 2020
  2. Knowledge Graphs — arXiv v6
    Aidan Hogan; Eva Blomqvist; Michael Cochez; Claudia d’Amato; Gerard de Melo; Claudio Gutierrez; José Emilio Labra Gayo; Sabrina Kirrane; Sebastian Neumaier; Axel Polleres; Roberto Navigli; Axel-Cyrille Ngonga Ngomo; Sabbir M. Rashid; Anisa Rula; Lukas Schmelzeisen; Juan Sequeda; Steffen Staab; Antoine Zimmermann · 2021

版本1 · 编写状态: 已完成记录中的技术复核

查看技术检查记录(AI)

Codex · 2026-09-23 · Single AI author. Scoped reading: Read PDF1 identity and PDF2–3 text: given mentions, candidate retrieval/ranking, independent encoders, in-KB assumption and explicit exclusion of NIL prediction. No BERT training, speed claims or benchmark reproduction. Read PDF1 identity/version date, PDF2,13,25,50–51 text: inclusive definition, schema, interpretation, open/closed world, extraction and entity linking. No full-survey reading, empirical reproduction or diagram reuse. 6 paired equations and four explained exercises. Checked hand TF-IDF cosine, alias priors, context reversal, no-candidate cases, omitted gold entities, thresholds and abstention. Given mentions and English word tokenizer; not BLINK training or a validated NIL classifier.

  • 手算TF-IDF余弦,核别名先验、上下文逆转、无候选、正确实体漏召回、阈值及拒绝;给定提及和英文分词,不冒称BLINK训练或已验证NIL分类器。
  • 每题四张计算SVG,14数值/几何与36响应式组合通过;12张当前选定图实看,其中7张与此前所看字节相同、5张最终图重新实看,TransE箭头修订已保全,完整页面验收另记。

核对的来源位置:

  • Scalable Zero-shot Entity Linking with Dense Entity Retrieval · Read PDF1 identity and PDF2–3 text: given mentions, candidate retrieval/ranking, independent encoders, in-KB assumption and explicit exclusion of NIL prediction. No BERT training, speed claims or benchmark reproduction.
  • Knowledge Graphs — arXiv v6 · Read PDF1 identity/version date, PDF2,13,25,50–51 text: inclusive definition, schema, interpretation, open/closed world, extraction and entity linking. No full-survey reading, empirical reproduction or diagram reuse.

相关主题

没有匹配结果,试试英文名或缩写。

已显示 0 条结果

将整个查询放入双引号,可按短语匹配。