Keras Adaptive Softmax
Install
pip install keras-adaptive-softmax
Usage
Generally, AdaptiveEmbedding and AdaptiveSoftmax should be used together. AdaptiveEmbedding provides variable length embeddings, while AdaptiveSoftmax calculates the similarities between the outputs and the generated embeddings.
import keras
from keras_adaptive_softmax import AdaptiveEmbedding, AdaptiveSoftmax
input_layer = keras.layers.Input(shape=(None,))
embed_layer = AdaptiveEmbedding(
input_dim=30,
output_dim=32,
cutoffs=[5, 15, 25],
div_val=2,
return_embeddings=True,
return_projections=True,
mask_zero=True,
)(input_layer)
dense_layer = keras.layers.Dense(
units=32,
activation='tanh',
)(embed_layer[0])
softmax_layer = AdaptiveSoftmax(
input_dim=32,
output_dim=30,
cutoffs=[5, 15, 25],
div_val=2,
bind_embeddings=True,
bind_projections=True,
)([dense_layer] + embed_layer[1:])
model = keras.models.Model(inputs=input_layer, outputs=softmax_layer)
model.compile('adam', 'sparse_categorical_crossentropy')
model.summary()
cutoffs and div_val controls the length of embeddings for each token. Suppose we have 30 distinct tokens, in the above example:
- The lengths of the embeddings of the first 5 tokens are 32
- The lengths of the embeddings of the next 10 tokens are 16
- The lengths of the embeddings of the next 10 tokens are 8
- The lengths of the embeddings of the last 5 tokens are 4
Metadata
Release files for keras-adaptive-softmax 0.9.0
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-adaptive-softmax-0.9.0.tar.gz | 15.2 kB | Without provenance | Details for keras-adaptive-softmax-0.9.0.tar.gz |
Release files / keras-adaptive-softmax-0.9.0.tar.gz
| Download URL | keras-adaptive-softmax-0.9.0.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0fe19ab75b62b63e150b4c4266b3fdc169d42eebe8ee77400b19b547ab5af38
|
|
BLAKE2b-256 checksum How to use checksums |
9c509a1df7260fa0ee12a1adb36af030c5af25139e3d9231367411ab4f6a87d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.55.2 CPython/3.7.4
|
Security for keras-adaptive-softmax 0.9.0
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.