tf2crf
- a simple CRF layer for tensorflow 2 keras
- support keras masking
Install
$ pip install tf2crf
Features
- easy to use CRF layer with tensorflow
- support mixed precision training
- support the ModelWithCRFLossDSCLoss with DSC loss, which increases f1 score with unbalanced data (refer the paper Dice Loss for Data-imbalanced NLP Tasks)
Attention
- Add internal kernel like CRF in keras_contrib, so now there is no need to stack a Dense layer before the CRF layer.
- I have changed the previous way that putting loss function and accuracy function in the CRF layer. Instead I choose to use ModelWappers (refered to jaspersjsun), which is more clean and flexible.
Tips
tensorflow >= 2.1.0 Recommmend use the latest tensorflow-addons which is compatiable with your tf version.
Example
import tensorflow as tf
from tf2CRF import CRF
from tensorflow.keras.layers import Input, Embedding, Bidirectional, GRU, Dense
from tensorflow.keras.models import Model
from tf2crf import CRF, ModelWithCRFLoss
inputs = Input(shape=(None,), dtype='int32')
output = Embedding(100, 40, trainable=True, mask_zero=True)(inputs)
output = Bidirectional(GRU(64, return_sequences=True))(output)
crf = CRF(units=9, type='float32')
output = crf(output)
base_model = Model(inputs, output)
model = ModelWithCRFLoss(base_model, sparse_target=True)
model.compile(optimizer='adam')
x = [[5, 2, 3] * 3] * 10
y = [[1, 2, 3] * 3] * 10
model.fit(x=x, y=y, epochs=2, batch_size=2)
model.save('tests/1')
Metadata
Release files for tf2crf 0.1.33
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tf2crf-0.1.33-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for tf2crf-0.1.33-py2.py3-none-any.whl |
Release files / tf2crf-0.1.33-py2.py3-none-any.whl
| Download URL | tf2crf-0.1.33-py2.py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
357057306fcbb5acb71ce0a657372dd461cd0c7c4d1d24a6047c156f12fcf776
|
|
BLAKE2b-256 checksum How to use checksums |
082dd5b522f5f8853fdd0b934cef668c9538e14e4f7b09a16fea5f5b47f4ea17
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.0
|
Security for tf2crf 0.1.33
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.