{"record":{"id":"5e1a47c6a430a7ce","repo":"hankcs/HanLP","slug":"unsupported-argument-type-item","errorCode":null,"errorMessage":"Unsupported argument type: {item}","messagePattern":"Unsupported argument type: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hanlp/common/transform.py","lineNumber":87,"sourceCode":"    def __init__(self, *fields) -> None:\n        super().__init__()\n        for each in fields:\n            self.append(FieldToIndex(each))\n\n    def append(self, item: Union[str, Tuple[str, Vocab], Tuple[str, str, Vocab], FieldToIndex]) -> None:\n        if isinstance(item, str):\n            item = FieldToIndex(item)\n        elif isinstance(item, (list, tuple)):\n            if len(item) == 2:\n                item = FieldToIndex(src=item[0], vocab=item[1])\n            elif len(item) == 3:\n                item = FieldToIndex(src=item[0], dst=item[1], vocab=item[2])\n            else:\n                raise ValueError(f'Unsupported argument length: {item}')\n        elif isinstance(item, FieldToIndex):\n            pass\n        else:\n            raise ValueError(f'Unsupported argument type: {item}')\n        super(self).append(item)\n\n    def save_vocab(self, save_dir):\n        for each in self:\n            each.save_vocab(save_dir, None)\n\n    def load_vocab(self, save_dir):\n        for each in self:\n            each.load_vocab(save_dir, None)\n\n\nclass VocabDict(SerializableDict):\n\n    def __init__(self, *args, **kwargs) -> None:\n        \"\"\"A dict holding :class:`hanlp.common.vocab.Vocab` instances. When used as a transform, it transforms the field\n        corresponding to each :class:`hanlp.common.vocab.Vocab` into indices.\n\n        Args:","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/transform.py#L69-L105","documentation":"Feedforward requires the hidden_dims list length to exactly equal num_layers, since each layer consumes one hidden dimension. If you pass, e.g., num_layers=2 with hidden_dims=[100], the config is inconsistent and the constructor raises ValueError.","triggerScenarios":"Constructing Feedforward(input_dim, num_layers, hidden_dims, ...) where len(hidden_dims) != num_layers, or passing a single int where a per-layer list is expected.","commonSituations":"Typos in component configs (e.g. transformer/tagger head configs); refactoring a 1-layer FFN to N layers and forgetting to extend hidden_dims; passing hidden_dims as a scalar instead of a list.","solutions":["Set num_layers = len(hidden_dims) (or extend hidden_dims to match num_layers)","Pass hidden_dims as an explicit list with one entry per layer, e.g. [128, 64] for 2 layers","Validate config programmatically before building the model"],"exampleFix":"# before\nFeedforward(input_dim=300, num_layers=2, hidden_dims=[128])\n# after\nFeedforward(input_dim=300, num_layers=2, hidden_dims=[128, 128])","handlingStrategy":"validation","validationCode":"assert len(hidden_dims) == num_layers, f'hidden_dims {len(hidden_dims)} != num_layers {num_layers}'","typeGuard":null,"tryCatchPattern":"try:\n    ff = Feedforward(input_dim, num_layers, hidden_dims)\nexcept ValueError as e:\n    raise ValueError(f'Invalid Feedforward config: {e}') from e","preventionTips":["Derive num_layers from len(hidden_dims) in configs","Always pass hidden_dims as an explicit list","Lint config dicts before model construction"],"tags":["hanlp","feedforward","config-validation","shape-mismatch"],"backgroundTag":"config-validation-failed","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}