Tensorflow Keras implementation of CORAL ordinal regression output layer, loss, activation, and metrics
Project description
Ordinal regression in Tensorflow Keras
Tensorflow Keras implementation of ordinal regression (aka ordinal classification) using consistent rank logits (CORAL) by Cao, Mirjalili, & Raschka (2019).
This package includes:
- Ordinal output layer:
CoralOrdinal()
- Ordinal loss function:
OrdinalCrossEntropy()
- Ordinal error metric:
MeanAbsoluteErrorLabels()
- Ordinal activation function:
ordinal_softmax()
This is a work in progress, so please post any issues to the issue queue. The package was developed as part of the Berkeley D-Lab's hate speech measurement project and paper (Kennedy et al. 2020).
Acknowledgments: Many thanks to Sebastian Raschka for the help in porting from the PyTorch source repository.
Key pending items:
- Function docstrings
- Docs
- Tests
Installation
Install the stable version via pip:
pip install coral-ordinal
Install the most recent code on GitHub via pip:
pip install git+https://github.com/ck37/coral-ordinal/
Dependencies
This package relies on Python 3.6+, Tensorflow 2.2+, and numpy.
Example
This is a quick example to show a basic model implementation. With actual data one would also want to specify the input shape.
import coral_ordinal as coral
NUM_CLASSES = 5
model = tf.keras.Sequential()
model.add(tf.keras.layers.Dense(32, activation = "relu"))
model.add(coral.CoralOrdinal(num_classes = NUM_CLASSES)) # Ordinal variable has 5 labels, 0 through 4.
model.compile(loss = coral.OrdinalCrossEntropy(),
metrics = [coral.MeanAbsoluteErrorLabels()])
See this colab notebook for extended examples of ordinal regression with MNIST (multilayer perceptron) and Amazon reviews (universal sentence encoder).
Note that the minimum value of the ordinal variable needs to be 0. If your labeled data ranges from 1 to 5, you will need to subtract 1 so that it is scaled to be 0 to 4.
References
Cao, W., Mirjalili, V., & Raschka, S. (2019). Rank-consistent ordinal regression for neural networks. arXiv preprint arXiv:1901.07884, 6.
Kennedy, C. J., Bacon, G., Sahn, A., & von Vacano, C. (2020). Constructing interval variables via faceted Rasch measurement and multitask deep learning: a hate speech application. arXiv preprint arXiv:2009.10277.
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
Built Distribution
File details
Details for the file coral-ordinal-0.1.8.tar.gz
.
File metadata
- Download URL: coral-ordinal-0.1.8.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1996fe0d98fdd761bed286991a1753aef8cb1dcefc22d7ace1c7efb0d8e84da9 |
|
MD5 | afb106b11187b9aa7ea3066d07473bb3 |
|
BLAKE2b-256 | bd3ed9e57c2fdde67703215c85db11aee360b65a67b5b3af8a2b01e0fed437e2 |
File details
Details for the file coral_ordinal-0.1.8-py3-none-any.whl
.
File metadata
- Download URL: coral_ordinal-0.1.8-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a987b68ab8f72b3f095dcf9103109a43f4cffdd99471398deaae3ec3d6c88c40 |
|
MD5 | 1f5a6e0f444b0909b007bafde784db49 |
|
BLAKE2b-256 | c982a44763ee684b2524e67aacc2fe3b3800d648f23d63feecdff1180b2aee0a |