Skip to content

Commit 35e6394

Browse files
voorhsclaude
andcommitted
docs(_bert): explain str-key label2id requirement to prevent regression
A future refactor sees `{str(i): i}` as a no-op coercion and "simplifies" back to `{i: i}`; mypy passes, then BertScorer.fit raises StrictDataclassFieldValidationError at runtime. Comment makes the WHY explicit at the call site, matching the WHY-only comment policy from 14f9576. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 5dfc75d commit 35e6394

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/autointent/modules/scoring/_bert.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def get_implicit_initialization_params(self) -> dict[str, Any]:
130130
def _initialize_model(self) -> Any: # noqa: ANN401
131131
from transformers import AutoModelForSequenceClassification
132132

133+
# huggingface_hub v1 StrictDataclass requires label2id keys to be str
134+
# (and id2label values to be str); int-keyed dicts raise
135+
# StrictDataclassFieldValidationError on from_pretrained in v5.
133136
label2id = {str(i): i for i in range(self._n_classes)}
134137
id2label = {i: str(i) for i in range(self._n_classes)}
135138

0 commit comments

Comments
 (0)