Skip to content
forked from xuxingya/tf2crf

CRF layer for tensorflow 2 keras

License

Notifications You must be signed in to change notification settings

ravi0912/tf2crf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tf2crf

  • a simple CRF layer for tensorflow 2 keras
  • support keras masking

Install

$ pip install tf2crf

Tips

It has been tested under tensorflow 2.1.0 and tensorflow-nightly.

Example

from tf2CRF import CRF
from tensorflow.keras.layers import Input, Embedding, Bidirectional, GRU, Dense
from tensorflow.keras.models import Model

inputs = Input(shape=(None,), dtype='int32')
output = Embedding(len(vocab), dim, trainable=True, mask_zero=True)(inputs)
output = Bidirectional(GRU(64, return_sequences=True))(output)
output = Dense(len(class_num), activation=None)(output)
crf = CRF()
output = crf(output)
model = Model(inputs, output)
model.compile(loss=crf.loss, optimizer='adam', metrics=[crf.accuracy])

About

CRF layer for tensorflow 2 keras

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%