Install & Compatibility
Where this runs
tested against v0.25.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
build_error
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 39.4s · import 19.564s · 2355.2MB
2417MB installed
● package 2417MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
KerasNLP
✓ import keras_nlp
Module imports as keras_nlp, not keras_nlp.models.
BertTokenizer
✓ from keras_nlp.tokenizers import BertTokenizer
✗ from keras_nlp.models import BertTokenizer
BERTTokenizer is in the tokenizers submodule, not models.
bert_base_preprocessor
✓ from keras_nlp.models import bert_base_preprocessor
✗ import bert_base_preprocessor
Preprocessors are in the models submodule with model name prefix.
Load a pretrained BERT classifier and make a prediction.
import keras_nlp
import keras
# Load a pretrained BERT model
model = keras_nlp.models.BertClassifier.from_preset(
"bert_tiny_en_uncased",
num_classes=2,
)
# Encode sample text using the built-in preprocessor
preprocessor = keras_nlp.models.bert_base_preprocessor()
inputs = preprocessor(["Hello, world!"])
# Predict
outputs = model(inputs)
print(outputs)
Errors
Common errors & fixes
AttributeError: module 'keras_nlp' has no attribute 'BertClassifier'
Wrong import path. BertClassifier is in keras_nlp.models.
fixUse: from keras_nlp.models import BertClassifier
RuntimeError: You must call `build()` on the tokenizer before using it.
Tokenizers from presets need to be built or used via from_preset which builds automatically.
fixUse: tokenizer = keras_nlp.tokenizers.BertTokenizer.from_preset('bert_tiny_en_uncased') ValueError: Unknown preset: 'bert_tiny_uncased'
Typo or outdated preset name.
fixRun: print(keras_nlp.presets.list_presets()) to see valid names.
ImportError: cannot import name 'bert_base_preprocessor' from 'keras_nlp.models'
The preprocessor name may vary by preset; not all presets have this symbol.
fixUse: from keras_nlp.models import BertPreprocessor (or check preset-specific exports).
Upgrade
Version history
0.29.1latest on PyPI · released Jun 2, 2026
Audit
Dependencies
No dependency data recorded yet.