A more elegant and convenient CRF built on tensorflow-addons.
Project description
keras-crf
A more elegant and convenient CRF built on tensorflow-addons.
Python Compatibility is limited to tensorflow/addons, you can check the compatibility from it's home page.
Installation
pip install keras-crf
Usage
Here is an example to show you how to build a CRF model easily:
import tensorflow as tf
from keras_crf import CRFModel
# build backbone model, you can use large models like BERT
sequence_input = tf.keras.layers.Input(shape=(None,), dtype=tf.int32, name='sequence_input')
outputs = tf.keras.layers.Embedding(100, 128)(sequence_input)
outputs = tf.keras.layers.Dense(256)(outputs)
base = tf.keras.Model(inputs=sequence_input, outputs=outputs)
# build CRFModel, 5 is num of tags
model = CRFModel(base, 5)
# no need to specify a loss for CRFModel, model will compute crf loss by itself
model.compile(
optimizer=tf.keras.optimizers.Adam(3e-4)
metrics=['acc'],
)
# you can now train this model
model.fit(dataset, epochs=10, callbacks=None)
# or summary the model
model.build(tf.TensorShape([None, 256]))
model.summary()
The model summary:
Model: "crf_model"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
model (Functional) (None, None, 256) 2737408
_________________________________________________________________
crf (CRF) multiple 1320
=================================================================
Total params: 2,738,728
Trainable params: 2,738,728
Non-trainable params: 0
_________________________________________________________________
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
keras_crf-0.2.0.tar.gz
(11.1 kB
view hashes)
Built Distribution
keras_crf-0.2.0-py3-none-any.whl
(12.4 kB
view hashes)
Close
Hashes for keras_crf-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c63dabd2e19c12d45b0e5d329d727c6a967f64f1c43bb5e2f4b40fff907913d |
|
MD5 | 393ec0692cfbb3582f4da963a94c1d18 |
|
BLAKE2b-256 | 64a8e8b11718872f1564787e27375b116288bf66abc2acb2bbdd36539f568238 |