Skip to main content

keras-crf

Python package PyPI version Python

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(21128, 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'],
    )
model.summary()

# you can now train this model
model.fit(dataset, epochs=10, callbacks=None)

The model summary:

Model: "crf_model"
__________________________________________________________________________________________________
Layer (type)                    Output Shape         Param #     Connected to                     
==================================================================================================
sequence_input (InputLayer)     [(None, None)]       0                                            
__________________________________________________________________________________________________
embedding (Embedding)           (None, None, 128)    2704384     sequence_input[0][0]             
__________________________________________________________________________________________________
dense (Dense)                   (None, None, 256)    33024       embedding[0][0]                  
__________________________________________________________________________________________________
crf (CRF)                       [(None, None), (None 1320        dense[0][0]                      
__________________________________________________________________________________________________
decode_sequence (Lambda)        (None, None)         0           crf[0][0]                        
__________________________________________________________________________________________________
potentials (Lambda)             (None, None, 5)      0           crf[0][1]                        
__________________________________________________________________________________________________
sequence_length (Lambda)        (None,)              0           crf[0][2]                        
__________________________________________________________________________________________________
kernel (Lambda)                 (5, 5)               0           crf[0][3]                        
==================================================================================================
Total params: 2,738,728
Trainable params: 2,738,728
Non-trainable params: 0
__________________________________________________________________________________________________

Release files for keras-crf 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for keras-crf 0.3.0
File Size Uploaded
keras_crf-0.3.0.tar.gz 7.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for keras-crf 0.3.0
File Interpreter ABI Platform
keras_crf-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 kB

Release files / keras_crf-0.3.0.tar.gz

Download URL keras_crf-0.3.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6a291bef9941cc45c675a31bd68a8548cf2f851d22c1769a9cd292ae2cab6746
BLAKE2b-256 checksum
How to use checksums
c8e32dbacbfcccce3afd37910896f7dfbea6eed3e72659e5de97393d4cc395d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

Release files / keras_crf-0.3.0-py3-none-any.whl

Download URL keras_crf-0.3.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b36e1fe8817bf8bae64049f744486c10ffb4c1fdf22232b9326b7c85c1919f2
BLAKE2b-256 checksum
How to use checksums
ae31053c867acd214e0b436d8b9600d1d6904c7d05c8a553764b82e1815d03c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page