Skip to main content

Fixed: "BertForTokenClassification LOAD REPORT from: dslim/bert-base-NER"

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

A named entity recognition (NER) pipeline with dslim/bert-base-NER printed BertForTokenClassification LOAD REPORT from: dslim/bert-base-NER, with two weights marked UNEXPECTED, before finding the right names. The two weights belong to a part the model doesn't have on purpose, so the report is harmless. logging.set_verbosity_error() hides it once you know that.

What I Was Doing​

I was finding the names of people, organizations and places in a sentence, with a token-classification (NER) pipeline in Transformers 5.26.0, on Python 3.14:

ner.py
from transformers import pipeline

ner = pipeline(
"ner",
model="dslim/bert-base-NER",
revision="d1a3e8f13f8c3566299d95fcfc9a8d2382a9affc",
aggregation_strategy="simple",
)

print(ner("Grace Hopper joined the United States Navy in New York."))
Terminal
uv run python ner.py

What I Expected​

The names in the sentence, each with its type and score, and nothing else.

What I Got​

Output
Loading weights: 100%|██████████████████████████████████████████| 199/199 [00:00<00:00, 5603.07it/s]
[transformers] BertForTokenClassification LOAD REPORT from: dslim/bert-base-NER
Key | Status | Details
-------------------------+------------+--------
bert.pooler.dense.bias | UNEXPECTED |
bert.pooler.dense.weight | UNEXPECTED |

Notes:
- UNEXPECTED: can be ignored when loading from different task/architecture; not ok if you expect identical arch.
[{'entity_group': 'PER', 'score': np.float32(0.99951303), 'word': 'Grace Hopper', 'start': 0, 'end': 12}, {'entity_group': 'ORG', 'score': np.float32(0.98393327), 'word': 'United States Navy', 'start': 24, 'end': 42}, {'entity_group': 'LOC', 'score': np.float32(0.99934256), 'word': 'New York', 'start': 46, 'end': 54}]

The terminal after uv run python ner.py: the weights loading, then BertForTokenClassification LOAD REPORT from: dslim/bert-base-NER, a table listing bert.pooler.dense.bias and bert.pooler.dense.weight as UNEXPECTED, a note that UNEXPECTED can be ignored when loading from a different task or architecture, and the three entities found: Grace Hopper as PER, United States Navy as ORG and New York as LOC.

The entities are right: Grace Hopper is a person (PER), the United States Navy an organization (ORG) and New York a place (LOC). The report came first, with two weights the loader didn't expect.

What I Checked​

What the report means. The report's own note says: "UNEXPECTED: can be ignored when loading from different task/architecture; not ok if you expect identical arch." An unexpected weight is one that's in the model's file on the Hub but has no place in the model that loads it.

Whether the weights are in the file. I listed the weights in the model's model.safetensors whose names contain pooler:

Output
['bert.pooler.dense.bias', 'bert.pooler.dense.weight']

They are: the file holds a pooler, a small layer named bert.pooler.dense.

Whether the model has a pooler. In transformers/models/bert/modeling_bert.py, the token-classification model builds its BERT body without one:

transformers/models/bert/modeling_bert.py (excerpt, 5.26.0)
class BertForTokenClassification(BertPreTrainedModel):
def __init__(self, config: BertConfig):
super().__init__(config)
self.num_labels = config.num_labels

self.bert = BertModel(config, add_pooling_layer=False)

and BertModel sets self.pooler = BertPooler(config) if add_pooling_layer else None. The pooler turns the first token's vector into one vector for the whole text ("We "pool" the model by simply taking the hidden state corresponding to the first token", says its code), and BertForSequenceClassification, which classifies whole texts, builds its BERT body with one. Token classification labels every token instead, so it has no use for it. Printing the pipeline's pooler confirmed it:

pooler.py
from transformers import pipeline

ner = pipeline(
"ner",
model="dslim/bert-base-NER",
revision="d1a3e8f13f8c3566299d95fcfc9a8d2382a9affc",
aggregation_strategy="simple",
)

print(ner.model.bert.pooler)
Output
Loading weights: 100%|█████████████████████████████████████████| 199/199 [00:00<00:00, 13213.86it/s]
[transformers] BertForTokenClassification LOAD REPORT from: dslim/bert-base-NER
Key | Status | Details
-------------------------+------------+--------
bert.pooler.dense.weight | UNEXPECTED |
bert.pooler.dense.bias | UNEXPECTED |

Notes:
- UNEXPECTED: can be ignored when loading from different task/architecture; not ok if you expect identical arch.
None

None: no pooler. The report appeared again, since the model was loaded again.

Where the report comes from. log_state_dict_report in transformers/utils/loading_report.py builds the table and logs it with logger.warning(...). It's a warning from Transformers' logging, so Transformers' logging level decides whether it shows.

Why It Happens​

The dslim/bert-base-NER file contains the weights of a pooler. The BertForTokenClassification model that loads it is built without a pooler, because labelling tokens doesn't use one. Transformers 5 lists the two weights it leaves unused as UNEXPECTED. Nothing is missing, and the results are correct.

The Fix​

Nothing in the model needs fixing. Once you've read the report and know the unexpected weights are only the pooler, you can stop Transformers from printing warnings. Its logging documentation says "the default verbosity of the library is WARNING", and set_verbosity_error() changes it so that it reports only errors:

ner.py
from transformers import logging, pipeline

logging.set_verbosity_error()

ner = pipeline(
"ner",
model="dslim/bert-base-NER",
revision="d1a3e8f13f8c3566299d95fcfc9a8d2382a9affc",
aggregation_strategy="simple",
)

print(ner("Grace Hopper joined the United States Navy in New York."))

The fixed ner.py in a macOS-style code window: logging and pipeline imported from transformers, logging.set_verbosity_error() called before the NER pipeline with dslim/bert-base-NER is created, and the sentence about Grace Hopper printed through it.

logging here is Transformers' own logging module, imported from transformers. The call has to come before the pipeline is created, because the report is printed while the model loads.

After the Fix​

Terminal
uv run python ner.py
Output
Loading weights: 100%|█████████████████████████████████████████| 199/199 [00:00<00:00, 13712.73it/s]
[{'entity_group': 'PER', 'score': np.float32(0.99951303), 'word': 'Grace Hopper', 'start': 0, 'end': 12}, {'entity_group': 'ORG', 'score': np.float32(0.98393327), 'word': 'United States Navy', 'start': 24, 'end': 42}, {'entity_group': 'LOC', 'score': np.float32(0.99934256), 'word': 'New York', 'start': 46, 'end': 54}]

The terminal after the fix: the weights loading, then the three entities, Grace Hopper as PER, United States Navy as ORG and New York as LOC, with no load report.

The report is gone, and the entities and scores are exactly the same. The commands work unchanged in PowerShell.

Common Mistakes​

MistakeWhat happensDo this instead
Hiding warnings before reading the reportYou'd also hide a report that matters, such as MISSING weights in a model you expected to be completeRead it once, then decide
Calling set_verbosity_error() after creating the pipelineThe report has already been printedCall it before loading any model
Expecting only this report to disappearEvery Transformers warning disappears, such as the one about texts longer than the model's maximumTurn the level back with logging.set_verbosity_warning() where you need warnings

Troubleshooting​

SymptomLikely causeFix
A MISSING row in the reportThe model needs weights its file doesn't have. The report's note says "those params were newly initialized because missing from the checkpoint. Consider training on your downstream task."Use a model trained for your task, or train it
A load report with other UNEXPECTED keysAnother model whose file has parts the loading class doesn't useCheck the keys' names against the class's code before ignoring them

FAQ​

Can I hide it without changing the code?​

Yes. The logging documentation describes an environment variable, TRANSFORMERS_VERBOSITY, that sets the same level when you run a script. Running the original ner.py with TRANSFORMERS_VERBOSITY=error in front of the command printed no report.

Does the report appear every time?​

Every time the model loads. Printing the pooler loaded the model a second time, and the report came again.

Conclusion​

BertForTokenClassification LOAD REPORT from: dslim/bert-base-NER listed bert.pooler.dense.weight and bert.pooler.dense.bias as UNEXPECTED because the model's file has a pooler that the token-classification model doesn't use. The entities were right all along; logging.set_verbosity_error() before creating the pipeline hid the report.

Additional Resources​