{"id":23930,"library":"keras-nlp","title":"KerasNLP","description":"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.","status":"active","version":"0.28.0","language":"python","source_language":"en","source_url":"https://github.com/keras-team/keras/tree/master/keras_nlp","tags":["keras","nlp","pretrained-models","deep-learning"],"install":[{"cmd":"pip install keras-nlp","lang":"bash","label":"Install"}],"dependencies":[],"imports":[{"note":"Module imports as keras_nlp, not keras_nlp.models.","symbol":"KerasNLP","correct":"import keras_nlp"},{"note":"BERTTokenizer is in the tokenizers submodule, not models.","wrong":"from keras_nlp.models import BertTokenizer","symbol":"BertTokenizer","correct":"from keras_nlp.tokenizers import BertTokenizer"},{"note":"Preprocessors are in the models submodule with model name prefix.","wrong":"import bert_base_preprocessor","symbol":"bert_base_preprocessor","correct":"from keras_nlp.models import bert_base_preprocessor"}],"quickstart":{"code":"import keras_nlp\nimport keras\n\n# Load a pretrained BERT model\nmodel = keras_nlp.models.BertClassifier.from_preset(\n    \"bert_tiny_en_uncased\",\n    num_classes=2,\n)\n\n# Encode sample text using the built-in preprocessor\npreprocessor = keras_nlp.models.bert_base_preprocessor()\ninputs = preprocessor([\"Hello, world!\"])\n\n# Predict\noutputs = model(inputs)\nprint(outputs)","lang":"python","description":"Load a pretrained BERT classifier and make a prediction."},"warnings":[{"fix":"Install Keras 3: pip install 'keras>=3.0' and set backend via KERAS_BACKEND env var.","message":"KerasNLP models require Keras 3 and TensorFlow/JAX/PyTorch backend. Using with Keras 2 will fail.","severity":"breaking","affected_versions":">=0.6.0"},{"fix":"Use keras_nlp.presets.list_presets() to see current presets.","message":"Presets like 'bert_tiny_en_uncased' may be removed or renamed in future versions. Always refer to the official preset list.","severity":"deprecated","affected_versions":"all"},{"fix":"Use a preset tokenizer: tokenizer = keras_nlp.tokenizers.BertTokenizer.from_preset('bert_tiny_en_uncased')","message":"Tokenizers and preprocessors must be built with a vocabulary before use. Calling .fit() on a raw tokenizer will raise an error.","severity":"gotcha","affected_versions":">=0.10.0"},{"fix":"Add import os; os.environ['KERAS_BACKEND'] = 'tensorflow' before importing keras_nlp.","message":"From version 0.13.0, 'import keras_nlp' no longer imports TensorFlow. You must explicitly import the backend.","severity":"breaking","affected_versions":">=0.13.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use: from keras_nlp.models import BertClassifier","cause":"Wrong import path. BertClassifier is in keras_nlp.models.","error":"AttributeError: module 'keras_nlp' has no attribute 'BertClassifier'"},{"fix":"Use: tokenizer = keras_nlp.tokenizers.BertTokenizer.from_preset('bert_tiny_en_uncased')","cause":"Tokenizers from presets need to be built or used via from_preset which builds automatically.","error":"RuntimeError: You must call `build()` on the tokenizer before using it."},{"fix":"Run: print(keras_nlp.presets.list_presets()) to see valid names.","cause":"Typo or outdated preset name.","error":"ValueError: Unknown preset: 'bert_tiny_uncased'"},{"fix":"Use: from keras_nlp.models import BertPreprocessor (or check preset-specific exports).","cause":"The preprocessor name may vary by preset; not all presets have this symbol.","error":"ImportError: cannot import name 'bert_base_preprocessor' from 'keras_nlp.models'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}