Skip to main content

Industry-strength Natural Language Processing extensions for Keras.

Project description

KerasNLP

Python Tensorflow contributions welcome

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

Quick Start

Install the latest release:

pip install keras-nlp --upgrade

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)

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.

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}},
}

Thank you to all of our wonderful contributors!

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keras-nlp-0.3.1.dev1.tar.gz (91.4 kB view details)

Uploaded Source

Built Distribution

keras_nlp-0.3.1.dev1-py3-none-any.whl (151.1 kB view details)

Uploaded Python 3

File details

Details for the file keras-nlp-0.3.1.dev1.tar.gz.

File metadata

  • Download URL: keras-nlp-0.3.1.dev1.tar.gz
  • Upload date:
  • Size: 91.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for keras-nlp-0.3.1.dev1.tar.gz
Algorithm Hash digest
SHA256 f2199872e3eaf8c1df11af8aa7a98dca27de2e5fd33f66b872ad1feee5f0032e
MD5 9906edbd70ce59d3cd829b54469b9d53
BLAKE2b-256 db35ec0fc3de5748d3421ba51a2d9f1c0e6ffcff7cdabc1be0b3cb9fa73e1d89

See more details on using hashes here.

Provenance

File details

Details for the file keras_nlp-0.3.1.dev1-py3-none-any.whl.

File metadata

File hashes

Hashes for keras_nlp-0.3.1.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 b4a4888b312255f411d3ac83a41af2f0be5095a576a887deab29d7cec6f80322
MD5 e430c1551176c68fa76a89f758aa5806
BLAKE2b-256 bfd43da78445b99eadccc6b05a86004f5afaccfad5d717b82b46eef0386ac751

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page