{"record":{"id":"5c56b6d0ca66a468","repo":"hankcs/HanLP","slug":"unsupported-parameter-type-embed","errorCode":null,"errorMessage":"Unsupported parameter type: {embed}","messagePattern":"Unsupported parameter type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hanlp/layers/embeddings/util.py","lineNumber":110,"sourceCode":"        unk: UNK token.\n        lowercase: Convert words in pretrained embeddings into lowercase.\n        trainable: ``False`` to use static embeddings.\n        init: Indicate which initialization to use for oov tokens.\n        normalize: ``True`` or a method to normalize the embedding matrix.\n\n    Returns:\n        An embedding matrix.\n\n    \"\"\"\n    if isinstance(embed, str):\n        embed = index_word2vec_with_vocab(embed, vocab, extend_vocab, unk, lowercase, init, normalize)\n        embed = nn.Embedding.from_pretrained(embed, freeze=not trainable, padding_idx=vocab.pad_idx)\n        return embed\n    elif isinstance(embed, int):\n        embed = nn.Embedding(len(vocab), embed, padding_idx=vocab.pad_idx)\n        return embed\n    else:\n        raise ValueError(f'Unsupported parameter type: {embed}')\n","sourceCodeStart":92,"sourceCodeEnd":111,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/util.py#L92-L111","documentation":"build_word2vec_with_vocab accepts embed either as a str/tensor-like loadable by nn.Embedding.from_pretrained or as an int dim for a fresh nn.Embedding. Any other type (float, None, dict, module) raises this error. The str path loads a pretrained matrix with padding_idx=vocab.pad_idx and freeze according to trainable.","triggerScenarios":"Passing embed=None (missing config), a float like 300.0, or an nn.Module to build_word2vec_with_vocab / a word2vec embedding config.","commonSituations":"Missing key in a YAML/JSON config; numeric dim parsed as float; trying to inject a custom module where only int or pretrained path are supported.","solutions":["Pass an int (e.g. 300) or a path to pretrained vectors","Coerce numeric config values to int","Check that the config key for embedding dim is present and typed correctly"],"exampleFix":"# before\nembed = build_word2vec_with_vocab(300.0, vocab)  # error\n# after\nembed = build_word2vec_with_vocab(int(300.0), vocab)","handlingStrategy":"type-guard","validationCode":"if isinstance(embed, float): embed = int(embed)\nassert isinstance(embed, (int, str)), f'embed must be int or path, got {type(embed)}'","typeGuard":"def valid_embed_param(embed) -> bool:\n    return isinstance(embed, (int, str)) and not isinstance(embed, bool)","tryCatchPattern":null,"preventionTips":["Default missing config dims explicitly","Validate config types after loading YAML"],"tags":["hanlp","word2vec","embedding","type-validation"],"backgroundTag":"invalid-constructor-argument-type","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}