|
4 | 4 |  |
5 | 5 | [](https://github.com/keras-team/keras-nlp/issues) |
6 | 6 |
|
7 | | -KerasNLP is a repository of modular building blocks (e.g. layers, metrics, losses) |
8 | | -to support modern Natural Language Processing (NLP) workflows. |
9 | | -Engineers working with applied NLP can leverage it to |
10 | | -rapidly assemble training and inference pipelines that are both state-of-the-art |
11 | | -and production-grade. Common use cases for application include sentiment |
12 | | -analysis, named entity recognition, text generation, etc. |
| 7 | +KerasNLP is a simple and powerful API for building Natural Language Processing |
| 8 | +(NLP) models within the Keras ecosystem. |
13 | 9 |
|
14 | | -KerasNLP can be understood as a horizontal extension of the Keras API: they're |
15 | | -new first-party Keras objects (layers, metrics, etc) that are too specialized to |
16 | | -be added to core Keras, but that receive the same level of polish and backwards |
17 | | -compatibility guarantees as the rest of the Keras API and that are maintained by |
18 | | -the Keras team itself (unlike TFAddons). |
| 10 | +KerasNLP provides modular building blocks following |
| 11 | +standard Keras interfaces (layers, metrics) that allow you to quickly and |
| 12 | +flexibly iterate on your task. Engineers working in applied NLP can leverage the |
| 13 | +library to assemble training and inference pipelines that are both |
| 14 | +state-of-the-art and production-grade. |
19 | 15 |
|
20 | | -Currently, KerasNLP is operating pre-release. Upon launch of KerasNLP 1.0, full |
21 | | -API docs and code examples will be available. |
| 16 | +KerasNLP can be understood as a horizontal extension of the Keras API — |
| 17 | +components are first-party Keras objects that are too specialized to be |
| 18 | +added to core Keras, but that receive the same level of polish as the rest of |
| 19 | +the Keras API. |
22 | 20 |
|
23 | | -## Contributors |
| 21 | +We are a new and growing project, and welcome [contributions](CONTRIBUTING.md). |
24 | 22 |
|
25 | | -If you'd like to contribute, please see our [contributing guide](CONTRIBUTING.md). |
| 23 | +## Quick Links |
26 | 24 |
|
27 | | -The fastest way to find a place to contribute is to browse our |
28 | | -[open issues](https://github.com/keras-team/keras-nlp/issues) and find an |
29 | | -unclaimed issue to work on. Issues with a [contributions welcome]( |
30 | | -https://github.com/keras-team/keras-nlp/issues?q=is%3Aissue+is%3Aopen+label%3A%22contributions+welcome%22) |
31 | | -tag are places where we are actively looking for support, and a |
32 | | -[good first issue](https://github.com/keras-team/keras-nlp/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) |
33 | | -tag means we think this could be a accessible a first time contributor. |
| 25 | +- [Contributing](CONTRIBUTING.md) |
| 26 | +- [Roadmap](ROADMAP.md) |
| 27 | +- [Style Guide](STYLE_GUIDE.md) |
| 28 | +- [API Design Guide](API_DESIGN_GUIDE.md) |
| 29 | +- [Call for Contributions](https://github.com/keras-team/keras-nlp/issues?q=is%3Aissue+is%3Aopen+label%3A%22contributions+welcome%22) |
34 | 30 |
|
35 | | -If you would like to propose a new symbol or feature, please open an issue to |
36 | | -discuss. Be aware the design for new features may take longer than contributing |
37 | | -pre-planned features. If you have a design in mind, please include a colab |
38 | | -notebook showing the proposed design in a end-to-end example. Make sure to |
39 | | -follow the [Keras API design guidelines]( |
40 | | -https://github.com/keras-team/governance/blob/master/keras_api_design_guidelines.md). |
| 31 | +## Quick Start |
41 | 32 |
|
42 | | -## Roadmap |
43 | | - |
44 | | -This is an early stage project, and we are actively working on a more detailed |
45 | | -roadmap to share soon. For now, most of our immediate planning is done through |
46 | | -GitHub issues. |
47 | | - |
48 | | -At this stage, we are primarily building components for a short list of |
49 | | -"greatest hits" NLP models (e.g. BERT, GPT-2, word2vec). We will be focusing |
50 | | -on components that follow a established Keras interface (e.g. |
51 | | -`keras.layers.Layer`, `keras.metrics.Metric`, or |
52 | | -`keras_nlp.tokenizers.Tokenizer`). |
53 | | - |
54 | | -As we progress further with the library, we will attempt to cover an ever |
55 | | -expanding list of widely cited model architectures. |
56 | | - |
57 | | -## Releases |
58 | | - |
59 | | -KerasNLP release are documented on our |
60 | | -[github release page](https://github.com/keras-team/keras-nlp/releases) and |
61 | | -available to download from our [PyPI project]( |
62 | | -https://pypi.org/project/keras-nlp/). |
63 | | - |
64 | | -To install KerasNLP and all it's dependencies, simply run: |
| 33 | +Install the latest release: |
65 | 34 |
|
66 | 35 | ``` |
67 | | -pip install keras-nlp |
| 36 | +pip install keras-nlp --upgrade |
| 37 | +``` |
| 38 | + |
| 39 | +Tokenize text, build a tiny transformer, and train a single batch: |
| 40 | + |
| 41 | +```python |
| 42 | +import keras_nlp |
| 43 | +import tensorflow as tf |
| 44 | +from tensorflow import keras |
| 45 | + |
| 46 | +# Tokenize some inputs with a binary label. |
| 47 | +vocab = ["[UNK]", "the", "qu", "##ick", "br", "##own", "fox", "."] |
| 48 | +sentences = ["The quick brown fox jumped.", "The fox slept."] |
| 49 | +tokenizer = keras_nlp.tokenizers.WordPieceTokenizer( |
| 50 | + vocabulary=vocab, |
| 51 | + sequence_length=10, |
| 52 | +) |
| 53 | +x, y = tokenizer(sentences), tf.constant([1, 0]) |
| 54 | + |
| 55 | +# Create a tiny transformer. |
| 56 | +inputs = keras.Input(shape=(None,), dtype="int32") |
| 57 | +outputs = keras_nlp.layers.TokenAndPositionEmbedding( |
| 58 | + vocabulary_size=len(vocab), |
| 59 | + sequence_length=10, |
| 60 | + embedding_dim=16, |
| 61 | +)(inputs) |
| 62 | +outputs = keras_nlp.layers.TransformerEncoder( |
| 63 | + num_heads=4, |
| 64 | + intermediate_dim=32, |
| 65 | +)(outputs) |
| 66 | +outputs = keras.layers.GlobalAveragePooling1D()(outputs) |
| 67 | +outputs = keras.layers.Dense(1, activation="sigmoid")(outputs) |
| 68 | +model = keras.Model(inputs, outputs) |
| 69 | + |
| 70 | +# Run a single batch of gradient descent. |
| 71 | +model.compile(loss="binary_crossentropy", jit_compile=True) |
| 72 | +model.train_on_batch(x, y) |
68 | 73 | ``` |
69 | 74 |
|
70 | 75 | ## Compatibility |
71 | 76 |
|
72 | 77 | We follow [Semantic Versioning](https://semver.org/), and plan to |
73 | 78 | provide backwards compatibility guarantees both for code and saved models built |
74 | | -with our components. While we continue with pre-release `0.y.z` development, we |
75 | 79 | may break compatibility at any time and APIs should not be consider stable. |
76 | 80 |
|
| 81 | +## Citing KerasNLP |
| 82 | + |
| 83 | +If KerasNLP helps your research, we appreciate your citations. |
| 84 | +Here is the BibTeX entry: |
| 85 | + |
| 86 | +```bibtex |
| 87 | +@misc{kerasnlp2022, |
| 88 | + title={KerasNLP}, |
| 89 | + author={Watson, Matthew, and Qian, Chen, and Zhu, Scott and Chollet, Fran\c{c}ois and others}, |
| 90 | + year={2022}, |
| 91 | + howpublished={\url{https://github.com/keras-team/keras-nlp}}, |
| 92 | +} |
| 93 | +``` |
| 94 | + |
77 | 95 | Thank you to all of our wonderful contributors! |
78 | 96 |
|
79 | 97 | <a href="https://github.com/keras-team/keras-nlp/graphs/contributors"> |
80 | 98 | <img src="https://contrib.rocks/image?repo=keras-team/keras-nlp" /> |
81 | | -</a> |
| 99 | +</a> |
0 commit comments