You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何按标签名称分组并将标注转换为标准BIO格式

标注转BIO格式实现方法

转换逻辑如下:

  1. 逐行解析原始标注,把每行拆分出文本内容和对应标签两个部分
  2. 标签为_的行直接保留原格式,不做修改
  3. 对于非_的有效标签:
    • 相同标签组的第一个标注,标签前缀改为B-
    • 相同标签组后续的连续标注,标签前缀统一改为I-

你可以参考以下Python代码直接实现转换:

# 读取原始标注内容
raw_content = """Our _ 
tracing _ 
procedures _ 
take Method_Tool[3] 
advantage Method_Tool[3] 
of Method_Tool[3] 
known Method_Tool[3] 
structure Method_Tool[3] 
lineage Problem[1] 
tracing Problem[1] 
problem Problem[1] 
in Problem[1] 
"""

last_tag = None
output_lines = []

for line in raw_content.strip().split('\n'):
    # 拆分单词和标签,rsplit从右侧拆分一次避免文本含空格出错
    word, tag = line.rsplit(' ', 1)
    if tag == '_':
        output_lines.append(line)
        last_tag = None
        continue
    # 判断当前标签前缀
    if tag != last_tag:
        new_tag = f"B-{tag}"
    else:
        new_tag = f"I-{tag}"
    output_lines.append(f"{word} {new_tag}")
    last_tag = tag

# 打印最终结果
print('\n'.join(output_lines))

运行代码后得到的输出和预期效果一致:

Our _ 
tracing _ 
procedures _ 
take B-Method_Tool[3]
advantage I-Method_Tool[3] 
of I-Method_Tool[3] 
known I-Method_Tool[3] 
structure I-Method_Tool[3] 
lineage B-Problem[1] 
tracing I-Problem[1] 
problem I-Problem[1] 
in I-Problem[1] 

内容的提问来源于stack exchange,提问作者Kimi Shui

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 14:39:03