Label Studio Pairwise 标签详解:实现文本、图像与时间序列的对象对比标注

发布时间:2026/9/12 14:32:10
Label Studio Pairwise 标签详解:实现文本、图像与时间序列的对象对比标注 Label Studio Pairwise 标签详解实现文本、图像与时间序列的对象对比标注【免费下载链接】label-studioLabel Studio is a multi-type data labeling and annotation tool with standardized output format项目地址: https://gitcode.com/GitHub_Trending/la/label-studioPairwise 是 Label Studio 中用于两两对比并二选一的控制型标签Control Tag适用于文本摘要质量评估、RLHF 偏好收集、广告文案对比、图像质量评估等需要标注员在 A/B 两个对象中做出选择的任务。读完本文你将掌握 Pairwise 的完整配置参数、标注结果的存储格式、与 Choices 标签的适用场景差异以及它在 Label Studio 前后端编辑器源码与数据统计 API中的底层实现原理。Pairwise 是什么从文档定义看核心语义在 docs/source/tags/pairwise.md 中官方对 Pairwise 的定义是ThePairwisetag is used to compare two different objects and select one item from the list. If you want annotators to compare two objects and determine whether they are similar or not, use theChoicestag.即Pairwise 用于比较两个不同的对象并从二者中选中其一。文档还特别划定了场景边界——如果任务是判断两个对象是否相似/相同应当改用 Choices 标签而不是 Pairwise。这一区分在语义上对应了两种经典标注范式Pairwise / 相对比较Relative Comparison产出哪个更好的偏好结论是偏好学习、排序学习的基础数据形态Choices / 绝对分类Absolute Classification产出相似/不相似好/坏的独立类别结论。Pairwise 官方声明支持的底层数据类型配合toName引用包括audio、image、HTML、paragraphs、text、time series、video覆盖了 Label Studio 中绝大多数对象型Object标签。配置参数全解析Pairwise 标签的参数定义在 docs/source/includes/tags/pairwise.md 中给出其完整参数表如下ParamTypeDescriptionnamestringName of the element标签自身名称作为标注结果中from_name使用toNamestringComma-separated names of the elements you want to compare待对比对象的名称逗号分隔必须恰好为两个[selectionStyle]stringStyle for the selection选中态样式可选在上述文档参数表之外从编辑器源码 web/libs/editor/src/tags/control/Pairwise.js 的 JSDoc 中可以补充确认以下两个可选参数params标注ParamTypeDescription[leftClass]stringClass name of the left object左侧对象的类名用于自定义选中态样式[rightClass]stringClass name of the right object右侧对象的类名这些参数在源码中被映射为 MST 模型属性Pairwise.jsconst TagAttrs types.model({ toname: types.maybeNull(types.string), selectionstyle: types.maybeNull(types.string), leftclass: types.maybeNull(types.string), rightclass: types.maybeNull(types.string), });参数语义与底层行为toName必须恰为两个名称源码在afterCreate()钩子中做了强校验——若names.length ! 2或两个名称相同会直接弹出错误提示 Incorrect toName parameter on Pairwise, must be two names separated by a comma: name1,name2Pairwise.js。toName按逗号切分后第 1 个元素即左对象、第 2 个即右对象分别对应源码中的left与right视图Pairwise.js。selectionStyle的兼容策略当提供了selectionStyle时编辑器会通过Tree.cssConverter将其转换为内联 style用于选中态高亮兼容旧行为未提供时则使用 Tailwind 语义化类bg-primary-background border border-primary-border-subtle rounded-sm来标记选中态Pairwise.js。也就是说在现代版本中你通常可以不写selectionStyle让编辑器自动使用主题语义色。交互绑定annotationAttached()中会把selectLeft/selectRight分别绑定到左、右对象的onClick上点击对象即完成选择再次点击同一侧则取消选择切换回nonePairwise.js。基础示例文本摘要两两对比文档给出的第一个示例是从两段文本摘要中选出更准确的一个这是 Pairwise 最典型的应用View Header valueSelect the more accurate summary/ Pairwise namepairwise leftClasstext1 rightClasstext2 toNametxt-1,txt-2/Pairwise Text nametxt-1 valueText 1 / Text nametxt-2 valueText 2 / /View配置要点Pairwise本身不渲染任何可见 UI源码中HtxPairwise返回nullPairwise.js它只是一个控制逻辑真正被点击的是toName指向的两个对象leftClass/rightClass用于在选中时给左/右对象追加类名实现高亮反馈两个Text对象各自声明name与toName中的txt-1, txt-2一一对应。进阶示例用 View 自由布局对比区域文档第二个示例展示了如何用View标签自定义左右对比区域的排版这在处理长文本、图像或时间序列等富对象时非常实用View Pairwise namepw toNametxt-1,txt-2/Pairwise View styledisplay: flex; View stylemargin-right: 1em;Text nametxt-1 value$text1 //View ViewText nametxt-2 value$text2 //View /View /View这里value$text1/value$text2表明数据来自任务的 JSON 字段即任务数据形如{text1: ..., text2: ...}而不是示例一中的硬编码文本。仓库内置的交互示例 web/libs/editor/src/examples/pairwise/config.xml 与 web/libs/editor/src/examples/pairwise/tasks.json 正是这种模式[ { data: { text1: In a little while you will have forgotten everything; in a little while everything will have forgotten you., text2: Death remembered should be like a mirror, Who tells us lifes but breath, to trust it error. } } ]你可以在本地启动 Label Studio 后用该配置导入上述任务数据直接体验 Pairwise 交互。标注结果的存储格式Pairwise 的选择结果以标准 Label Studio 标注格式result保存。仓库示例 web/libs/editor/src/examples/pairwise/annotations/1.json 给出了完整的标注样本{ annotations: [ { id: 1001, lead_time: 15.053, result: [ { from_name: pw, id: Dx_aB91ISN, to_name: txt-2, type: pairwise, value: { selected: right } } ] } ], data: { text1: ..., text2: ... } }关键字段说明type: pairwise结果类型标识value.selected取值限定为枚举left、right、none三者之一源码 Pairwise.js 中selected: types.maybeNull(types.enumeration([left, right, none]))from_name指向Pairwise标签的nameto_name指向被对比对象的name当selected none即标注员再次点击取消了选择时源码会调用result.area.removeResult(result)将该条结果从标注中移除Pairwise.js因此持久化到后端的有效结果通常只会是left或right。仓库自带的官方模板 label_studio/annotation_templates/ranking-and-scoring/pairwise-classification/config.xml 也在注释中内嵌了同样的 JSON 结果示例selected: left可作为模板开发时的参考。后端如何统计 Pairwise 结果Pairwise 的结果在后端参与任务分布统计Distribution。在 label_studio/tasks/api.py 中result_type pairwise的分支把selected值归入labels分布字典elif result_type pairwise: selected value.get(selected) if selected: if selected not in distributions[from_name][labels]: distributions[from_name][labels][selected] 0 distributions[from_name][labels][selected] 1即统计接口会把left/right作为两个类别计数标注多少次选择左侧、多少次选择右侧直接呈现在项目的标注分布视图中。对应地后端测试 label_studio/tasks/tests/test_api.py 中的test_distribution_with_pairwise用例覆盖了该统计逻辑。另外在 label_studio/projects/models.py 中pairwise与relation一起被列入了特殊结果类型集合说明它在项目级模型校验/处理流程中享有独立分支而非普通标签结果。与 Choices 的分工什么场景该用哪个官方文档在定义 Pairwise 时专门给出了对比指引实际选型可参考下表任务目标推荐标签输出语义在 A、B 两个对象中选出更优者偏好/排序Pairwisevalue.selected: left/right判断 A、B 是否相似 / 是否属于某类Choicesvalue.choices: [...]例如在 label_studio/annotation_templates/ranking-and-scoring/pairwise-classification/config.yml 中该模板被归类到 ranking-and-scoring 场景而 label_studio/annotation_templates/generative-ai/human-feedback-collection/config.yml 中则把 pairwise comparison 明确列为 RLHF人类反馈强化学习、奖励建模、偏好学习等场景的关键词——这体现了 Pairwise 在生成式 AI 数据管线中的典型价值。实战速查完整可复制配置下面是一份开箱即用的文本偏好对比配置对应官方模板 pairwise-classification/config.xmlView HeaderSelect one of two items/Header Pairwise namepw toNametext1,text2 / Text nametext1 value$text1 / Text nametext2 value$text2 / /View配套任务数据[ {data: {text1: Look at this! Its a brand new product, text2: Look at this! Its an awesome piece of sh*t}} ]将图像对比场景迁移到 Pairwise 也非常直接把Text换成两个ImagetoName指向两个图像对象的name即可时间序列、音频、视频等数据类型同理只要对象标签的name出现在toName中即可参与对比。总结Pairwise 是 Label Studio 中实现两两对比、二选一标注的最小且完整的控制标签配置上只需name 恰好两个对象名的toName可选selectionStyle/leftClass/rightClass控制选中态样式交互上点击左/右对象即产生选择、再次点击取消数据上以type: pairwisevalue.selected: left|right的标准格式落地并参与后端分布统计。结合本文给出的参数表、示例配置、结果 JSON 与源码定位Pairwise.js、tasks/api.py你可以快速为偏好学习、RLHF 数据收集、质量评估等任务搭建对比标注界面。【免费下载链接】label-studioLabel Studio is a multi-type data labeling and annotation tool with standardized output format项目地址: https://gitcode.com/GitHub_Trending/la/label-studio创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考