This release is a pre-release and may not be stable for production use.
KerasNLP
KerasNLP is a simple and powerful API for building Natural Language Processing (NLP) models within the Keras ecosystem.
KerasNLP provides modular building blocks following standard Keras interfaces (layers, metrics) that allow you to quickly and flexibly iterate on your task. Engineers working in applied NLP can leverage the library to assemble training and inference pipelines that are both state-of-the-art and production-grade.
KerasNLP can be understood as a horizontal extension of the Keras API — components are first-party Keras objects that are too specialized to be added to core Keras, but that receive the same level of polish as the rest of the Keras API.
We are a new and growing project, and welcome contributions.
Quick Links
For everyone
For contributors
Installation
To install the latest official release:
pip install keras-nlp --upgrade
To install the latest unreleased changes to the library, we recommend using pip to install directly from the master branch on github:
pip install git+https://github.com/keras-team/keras-nlp.git --upgrade
Quickstart
Tokenize text, build a tiny transformer, and train a single batch:
import keras_nlp
import tensorflow as tf
from tensorflow import keras
# Tokenize some inputs with a binary label.
vocab = ["[UNK]", "the", "qu", "##ick", "br", "##own", "fox", "."]
sentences = ["The quick brown fox jumped.", "The fox slept."]
tokenizer = keras_nlp.tokenizers.WordPieceTokenizer(
vocabulary=vocab,
sequence_length=10,
)
x, y = tokenizer(sentences), tf.constant([1, 0])
# Create a tiny transformer.
inputs = keras.Input(shape=(None,), dtype="int32")
outputs = keras_nlp.layers.TokenAndPositionEmbedding(
vocabulary_size=len(vocab),
sequence_length=10,
embedding_dim=16,
)(inputs)
outputs = keras_nlp.layers.TransformerEncoder(
num_heads=4,
intermediate_dim=32,
)(outputs)
outputs = keras.layers.GlobalAveragePooling1D()(outputs)
outputs = keras.layers.Dense(1, activation="sigmoid")(outputs)
model = keras.Model(inputs, outputs)
# Run a single batch of gradient descent.
model.compile(optimizer="adam", loss="binary_crossentropy", jit_compile=True)
model.train_on_batch(x, y)
For more in depth guides and examples, visit https://keras.io/keras_nlp/.
Compatibility
We follow Semantic Versioning, and plan to
provide backwards compatibility guarantees both for code and saved models built
with our components. While we continue with pre-release 0.y.z development, we
may break compatibility at any time and APIs should not be consider stable.
Disclaimer
KerasNLP provides access to pre-trained models via the keras_nlp.models API.
These pre-trained models are provided on an "as is" basis, without warranties
or conditions of any kind. The following underlying models are provided by third
parties, and subject to separate licenses:
DistilBERT, RoBERTa, XLM-RoBERTa, GPT-2.
Citing KerasNLP
If KerasNLP helps your research, we appreciate your citations. Here is the BibTeX entry:
@misc{kerasnlp2022,
title={KerasNLP},
author={Watson, Matthew, and Qian, Chen, and Zhu, Scott and Chollet, Fran\c{c}ois and others},
year={2022},
howpublished={\url{https://github.com/keras-team/keras-nlp}},
}
Acknowledgements
Thank you to all of our wonderful contributors!
Metadata
Release files for keras-nlp 0.4.0.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| keras-nlp-0.4.0.dev0.tar.gz | 185.7 kB | Without provenance | Details for keras-nlp-0.4.0.dev0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| keras_nlp-0.4.0.dev0-py3-none-any.whl | Python 3 | none | any | Details for keras_nlp-0.4.0.dev0-py3-none-any.whl |
Total release size: 523.1 kB
Release files / keras-nlp-0.4.0.dev0.tar.gz
| Download URL | keras-nlp-0.4.0.dev0.tar.gz |
|---|---|
| Size | 185.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f8e8351976e411850219615864dc24fda393dd26f4168104eb297fde1fb519b
|
|
BLAKE2b-256 checksum How to use checksums |
7b1e292ea22f758abd41192becdbfbc165edbaeb79fb50c26f1646b4f3b53fbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / keras_nlp-0.4.0.dev0-py3-none-any.whl
| Download URL | keras_nlp-0.4.0.dev0-py3-none-any.whl |
|---|---|
| Size | 337.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fa9e8c3ec0f217115f330ea363f4d19f84066abdc14d860db9dd647425403336
|
|
BLAKE2b-256 checksum How to use checksums |
497e2fd04b6ff964d257ae853177a1acea4cea2bd8e8a2db79f8feede7058d43
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for keras-nlp 0.4.0.dev0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.