hankcs/HanLP · info · FutureWarning

iob1_to_bioul has been replaced with 'to_bioul' to allow mor

Error message

iob1_to_bioul has been replaced with 'to_bioul' to allow more encoding options.

What it means

This is a FutureWarning emitted by hanlp's deprecated helper iob1_to_bioul in hanlp/utils/span_util.py. The function still works but has been renamed to to_bioul, which supports more tagging encodings (IOB1, IOB2, BIOUL, etc.). The warning is a migration signal, not a runtime failure.

Source

Thrown at hanlp/utils/span_util.py:560

        elif label[0] == "B":
            start = index
            while label[0] != "E":
                index += 1
                if index >= len(tag_sequence):
                    raise InvalidTagSequence(tag_sequence)
                label = tag_sequence[index]
                if not (label[0] == "I" or label[0] == "E"):
                    raise InvalidTagSequence(tag_sequence)
            spans.append((label.partition("-")[2], (start, index)))
        else:
            if label != "O":
                raise InvalidTagSequence(tag_sequence)
        index += 1
    return [span for span in spans if span[0] not in classes_to_ignore]


def iob1_to_bioul(tag_sequence: List[str]) -> List[str]:
    warnings.warn(
        "iob1_to_bioul has been replaced with 'to_bioul' to allow more encoding options.",
        FutureWarning,
    )
    return to_bioul(tag_sequence)


def to_bioul(tag_sequence: List[str], encoding: str = "IOB1") -> List[str]:
    """
    Given a tag sequence encoded with IOB1 labels, recode to BIOUL.

    In the IOB1 scheme, I is a token inside a span, O is a token outside
    a span and B is the beginning of span immediately following another
    span of the same type.

    In the BIO scheme, I is a token inside a span, O is a token outside
    a span and B is the beginning of a span.

    # Parameters

View on GitHub (pinned to ddb1299bdd)

Solutions

  1. Replace calls iob1_to_bioul(tags) with to_bioul(tags, encoding='iob1') (or the encoding matching your input scheme) from hanlp.utils.span_util.
  2. If you must keep old code temporarily, suppress with warnings.filterwarnings('ignore', category=FutureWarning, module='hanlp.utils.span_util'), then migrate before the function is removed.
  3. Pin/upgrade code against hanlp's current docs and run a project-wide grep for iob1_to_bioul to catch every call site.

Example fix

// before
from hanlp.utils.span_util import iob1_to_bioul
bioul = iob1_to_bioul(tags)

// after
from hanlp.utils.span_util import to_bioul
bioul = to_bioul(tags, encoding='iob1')
Defensive patterns

Strategy: validation

Validate before calling

import warnings, hanlp.utils.span_util as su
if not hasattr(su, 'to_bioul'):
    raise RuntimeError('hanlp too old: to_bioul unavailable; upgrade hanlp')

Type guard

def has_to_bioul(mod) -> bool:
    return hasattr(mod, 'to_bioul') and callable(mod.to_bioul)

Prevention

When it happens

Trigger: Calling hanlp.utils.span_util.iob1_to_bioul(tag_sequence) directly, or using older user code/scripts that imported and invoked this helper after upgrading hanlp to a version where to_bioul was introduced.

Common situations: Upgrading hanlp to a newer release while pipelines or notebooks still call iob1_to_bioul; copying old hanlp examples or tutorials that used the previous API name; downstream NLP tooling that hardcodes the old function name.

Related errors


AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27). Data as JSON: /api/errors/a60198a3b41bd00b. Report an issue: GitHub.