{"record":{"id":"ce2d13a33049cc03","repo":"hankcs/HanLP","slug":"unrecognized-label-encoding-self-label-encoding","errorCode":null,"errorMessage":"Unrecognized label encoding {self.label_encoding}","messagePattern":"Unrecognized label encoding (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hanlp/metrics/chunking/conlleval.py","lineNumber":81,"sourceCode":"        self.count = EvalCounts()\n\n    def reset(self):\n        self.count = EvalCounts()\n\n    @property\n    def score(self):\n        return self.result(False, False).fscore\n\n    def reset_state(self):\n        self.count.reset_state()\n\n    def update_state(self, true_seqs: List[str], pred_seqs: List[str]):\n        if self.label_encoding == 'IOBES':\n            count = evaluate_iobes(true_seqs, pred_seqs)\n        elif self.label_encoding in ['IOB2', 'BIO']:\n            count = evaluate_iob2(true_seqs, pred_seqs)\n        else:\n            raise ValueError(f'Unrecognized label encoding {self.label_encoding}')\n        self.count.correct_chunk += count.correct_chunk\n        self.count.correct_tags += count.correct_tags\n        self.count.total_gold += count.total_gold\n        self.count.total_pred += count.total_pred\n        self.count.token_counter += count.token_counter\n        for s, n in zip(self.count.states, count.states):\n            for k, v in n.items():\n                s[k] = s.get(k, 0) + v\n\n    def batch_update_state(self, true_seqs: List[List[str]], pred_seqs: List[List[str]]):\n        for t, p in zip(true_seqs, pred_seqs):\n            self.update_state(t, p)\n\n    def result(self, full=True, verbose=True) -> Union[Tuple[DetailedF1, dict, str], DetailedF1]:\n        if full:\n            out = io.StringIO()\n            overall, by_type = report(self.count, out)\n            text = out.getvalue()","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/metrics/chunking/conlleval.py#L63-L99","documentation":"Raised by CoNNEval.update_state when the metric object was constructed with a label_encoding other than the supported chunk encodings. HanLP's chunking F1 metric only knows how to score sequences in IOBES or IOB2/BIO schemes, so any other string (or a typo like 'BIOES', 'iob2') is rejected before any counting happens.","triggerScenarios":"Creating CoNNEval/Chunking metric with label_encoding not in {'IOBES','IOB2','BIO'} (e.g. 'BIOES', 'IOB1', lowercase 'iobes'), or passing a component's config value straight into the metric, then calling update_state (directly or via batch_update_state) during evaluation.","commonSituations":"Typos in metric config; porting code that used a different tagging scheme name (AllenNLP-style 'BIOES' vs HanLP's 'IOBES'); assuming the metric accepts IOB1/IOB or lowercase encodings.","solutions":["Set label_encoding to one of the supported values: 'IOBES', 'IOB2' or 'BIO' (note 'BIOES' is NOT accepted, the E-first name is 'IOBES').","If your tags use another scheme (e.g. IOB1), convert them to IOB2 or IOBES before calling update_state.","Check for case: the comparison is case-sensitive, so pass uppercase strings."],"exampleFix":"// before\nmetric = CoNNEval(label_encoding='BIOES')\n// after\nmetric = CoNNEval(label_encoding='IOBES')","handlingStrategy":"validation","validationCode":"ALLOWED = {'IOBES', 'IOB2', 'BIO'}\nassert metric.label_encoding in ALLOWED, f'use one of {ALLOWED}'","typeGuard":null,"tryCatchPattern":"try:\n    metric.update_state(gold, pred)\nexcept ValueError as e:\n    if 'Unrecognized label encoding' in str(e):\n        raise  # fix config: only IOBES/IOB2/BIO supported\n    raise","preventionTips":["Centralize the label_encoding constant next to the tag decoder so metric and decoder cannot diverge.","Add a unit test asserting your configured encoding is in {'IOBES','IOB2','BIO'}."],"tags":["config","nlp","chunking","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}