tensorflow/models · error · ValueError
Can not find embedding layer in the encoder.
Error message
Can not find embedding layer in the encoder.
What it means
Error "Can not find embedding layer in the encoder." thrown in tensorflow/models.
Source
Thrown at official/projects/edgetpu/nlp/modeling/model_builder.py:81
num_feedforward_networks=encoder_cfg.num_feedforward_networks,
normalization_type=encoder_cfg.normalization_type,
classifier_activation=encoder_cfg.classifier_activation,
input_mask_dtype=encoder_cfg.input_mask_dtype,
quantization_friendly=quantization_friendly)
if pretrainer_cfg.cls_heads:
cls_heads = [
modeling.layers.ClassificationHead(**cfg.as_dict())
for cfg in pretrainer_cfg.cls_heads
]
else:
cls_heads = []
# Get the embedding table from the encoder model.
def _get_embedding_table(encoder):
for layer in encoder.layers:
if layer.name.startswith('mobile_bert_embedding'):
return layer.word_embedding.embeddings
raise ValueError('Can not find embedding layer in the encoder.')
masked_lm = masked_lm or modeling.layers.MobileBertMaskedLM(
embedding_table=_get_embedding_table(encoder),
activation=tf_utils.get_activation(pretrainer_cfg.mlm_activation),
initializer=tf_keras.initializers.TruncatedNormal(
stddev=pretrainer_cfg.mlm_initializer_range),
output_weights_use_proj=pretrainer_cfg.mlm_output_weights_use_proj,
name='cls/predictions')
pretrainer = edgetpu_pretrainer.MobileBERTEdgeTPUPretrainer(
encoder_network=encoder,
classification_heads=cls_heads,
customized_masked_lm=masked_lm,
name=name)
return pretrainer
View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/projects/edgetpu/nlp/modeling/model_builder.py:81 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/a7ce40ccf548ab05.
Report an issue: GitHub.