Registry / ai-ml / keras-nlp

keras-nlp

JSON →
library0.29.1pypypi✓ verified 84d ago

KerasNLP provides pretrained NLP models (e.g., BERT, GPT-2, T5) and preprocessing utilities for Keras. Current version 0.28.0 supports Python >=3.10. Released approximately monthly.

pip install keras-nlp
INSTALL
IMPORT
SIG · KERAS-NLP
K
keras-nlp
ai-mlpythonv0.29.1
Install
39.4s avg
Import
19564ms
Disk
2417MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
build_error
glibc
py 3.103.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)
Debug
Known issues
breakingKerasNLP models require Keras 3 and TensorFlow/JAX/PyTorch backend. Using with Keras 2 will fail.
fix
Install Keras 3: pip install 'keras>=3.0' and set backend via KERAS_BACKEND env var.
affects: >=0.6.0
deprecatedPresets like 'bert_tiny_en_uncased' may be removed or renamed in future versions. Always refer to the official preset list.
fix
Use keras_nlp.presets.list_presets() to see current presets.
affects: all
gotchaTokenizers and preprocessors must be built with a vocabulary before use. Calling .fit() on a raw tokenizer will raise an error.
fix
Use a preset tokenizer: tokenizer = keras_nlp.tokenizers.BertTokenizer.from_preset('bert_tiny_en_uncased')
affects: >=0.10.0
breakingFrom version 0.13.0, 'import keras_nlp' no longer imports TensorFlow. You must explicitly import the backend.
fix
Add import os; os.environ['KERAS_BACKEND'] = 'tensorflow' before importing keras_nlp.
affects: >=0.13.0
Errors
Common errors & fixes
AttributeError: module 'keras_nlp' has no attribute 'BertClassifier'
Wrong import path. BertClassifier is in keras_nlp.models.
fix
Use: 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.
fix
Use: tokenizer = keras_nlp.tokenizers.BertTokenizer.from_preset('bert_tiny_en_uncased')
ValueError: Unknown preset: 'bert_tiny_uncased'
Typo or outdated preset name.
fix
Run: 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.
fix
Use: 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.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
keras-nlp — pip install keras-nlp · libregistry