{"record":{"id":"f1f143472f6152a3","repo":"hankcs/HanLP","slug":"error","errorCode":null,"errorMessage":"error","messagePattern":"error","errorType":"http","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"plugins/hanlp_restful_java/src/main/java/com/hankcs/hanlp/restful/HanLPClient.java","lineNumber":614,"sourceCode":"            StringBuilder response = new StringBuilder();\n            try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getErrorStream(), StandardCharsets.UTF_8)))\n            {\n                String responseLine;\n                while ((responseLine = br.readLine()) != null)\n                {\n                    response.append(responseLine.trim());\n                }\n            }\n            String error = String.format(\"Request failed, status code = %d, error = %s\", code, con.getResponseMessage());\n            try\n            {\n                Map detail = mapper.readValue(response.toString(), Map.class);\n                error = (String) detail.get(\"detail\");\n            }\n            catch (Exception ignored)\n            {\n            }\n            throw new IOException(error);\n        }\n\n        StringBuilder response = new StringBuilder();\n        try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)))\n        {\n            String responseLine;\n            while ((responseLine = br.readLine()) != null)\n            {\n                response.append(responseLine.trim());\n            }\n        }\n        return response.toString();\n    }\n\n}\n","sourceCodeStart":596,"sourceCodeEnd":630,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_restful_java/src/main/java/com/hankcs/hanlp/restful/HanLPClient.java#L596-L630","documentation":"Word2VecEmbedding is a pretrained embedding module, not a trainable model, so all training-related Component methods (build_optimizer, build_criterion, etc.) are explicitly disabled with NotImplementedError('Not supported.'). Calling any training-phase hook on this embedding will always raise. The class only supports inference-time vocab/weight loading and forward embedding lookup.","triggerScenarios":"Calling .fit(), .train(), build_optimizer/build_criterion, or invoking a training loop on a Word2VecEmbedding (or a component configured with it) instead of a trainable HanLP component.","commonSituations":"Copy-pasting a training script written for a trainable component and swapping in a Word2Vec embedding; trying to fine-tune static pretrained vectors; using a meta-component's train path with an embedding-only config.","solutions":["Use a trainable component (e.g. an NER/tagger model) and pass the Word2Vec embedding as its embed module rather than training the embedding itself","If you only need vectors, call the embedding's forward/inference API (or load the .txt/.tbz2 vectors) instead of fit","Subclass Word2VecEmbedding and override build_optimizer etc. if you genuinely need custom training"],"exampleFix":"// before\nemb = Word2VecEmbedding(' sgns ', ...)\nemb.fit(train_data)  # NotImplementedError\n// after\nmodel = hanlp.load(hanlp.pretrained.pos.CTB9_POS_RADICAL_ELECTRA_SMALL)\nmodel.predict(['Hello world'])","handlingStrategy":"type-guard","validationCode":"from hanlp.layers.embeddings.word2vec import Word2VecEmbedding\nif isinstance(model, Word2VecEmbedding):\n    raise TypeError('Embedding modules are inference-only; train a task component instead')","typeGuard":"def is_trainable(component) -> bool:\n    return not isinstance(component, Word2VecEmbedding)","tryCatchPattern":"try:\n    model.fit(data)\nexcept NotImplementedError as e:\n    logging.warning('Component does not support training: %s', e)","preventionTips":["Only call fit/train hooks on task components","Treat embeddings as layers, not models, in configs","Check the component type in generic trainer loops"],"tags":["hanlp","word2vec","embedding","not-implemented","training"],"backgroundTag":"not-implemented-error","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}