hankcs/HanLP · error · ValueError

Unsupported argument length: {item}

Error message

Unsupported argument length: {item}

What it means

evaluate_dataloader on Word2VecEmbedding always raises NotImplementedError because evaluation with a loss/metric requires a trainable prediction model, which a static embedding is not. The method exists only to satisfy the Component interface.

Source

Thrown at hanlp/common/transform.py:83


class VocabList(list):

    def __init__(self, *fields) -> None:
        super().__init__()
        for each in fields:
            self.append(FieldToIndex(each))

    def append(self, item: Union[str, Tuple[str, Vocab], Tuple[str, str, Vocab], FieldToIndex]) -> None:
        if isinstance(item, str):
            item = FieldToIndex(item)
        elif isinstance(item, (list, tuple)):
            if len(item) == 2:
                item = FieldToIndex(src=item[0], vocab=item[1])
            elif len(item) == 3:
                item = FieldToIndex(src=item[0], dst=item[1], vocab=item[2])
            else:
                raise ValueError(f'Unsupported argument length: {item}')
        elif isinstance(item, FieldToIndex):
            pass
        else:
            raise ValueError(f'Unsupported argument type: {item}')
        super(self).append(item)

    def save_vocab(self, save_dir):
        for each in self:
            each.save_vocab(save_dir, None)

    def load_vocab(self, save_dir):
        for each in self:
            each.load_vocab(save_dir, None)


class VocabDict(SerializableDict):

    def __init__(self, *args, **kwargs) -> None:

View on GitHub (pinned to ddb1299bdd)

Solutions

  1. Evaluate the task component that consumes the embedding, not the embedding itself
  2. Guard calls with isinstance checks in generic eval loops
  3. Subclass to provide a custom evaluation if needed
Defensive patterns

Strategy: type-guard

Validate before calling

if isinstance(model, Word2VecEmbedding):
    raise TypeError('evaluate a task component, not an embedding')

Type guard

def evaluatable(m) -> bool: return not isinstance(m, Word2VecEmbedding)

Try / catch

try:
    model.evaluate_dataloader(data, criterion, metric)
except NotImplementedError as e:
    raise RuntimeError('inference-only component') from e

Prevention

When it happens

Trigger: Calling evaluate_dataloader (or .evaluate()) on a Word2VecEmbedding, e.g. from a generic evaluation harness.

Common situations: Running a benchmark script over a list of models that includes pure embeddings; validating a pipeline whose head was accidentally replaced by an embedding module.

Related errors


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