--- id: tf2crf version: "0.1.33" license: MIT License license_treatment: permissive maintenance: abandoned --- # tf2crf — a crf layer for tensorflow 2 keras License: permissive · Maintenance: abandoned · Downloads: 202.0K/mo ## What it is and what it does tf2crf wraps a CRF (Conditional Random Field) layer into TensorFlow 2 Keras, allowing you to add sequence-level constraints to neural sequence labeling models. It handles masking automatically and supports mixed precision training. The package includes a ModelWithCRFLoss wrapper that decouples the loss function from the layer itself, and offers an optional DSC (Dice) loss variant for imbalanced datasets. The layer is designed to sit at the end of a sequence model (typically after a BiLSTM or BiGRU) and learns transition probabilities between output labels. You build a standard Keras model, wrap it with ModelWithCRFLoss, and train normally. However, the package has been abandoned since mid-2021, so you should verify compatibility with your TensorFlow and tensorflow-addons versions before relying on it in production. Use it for: - Named entity recognition (NER) tasks where label transitions matter and you want CRF constraints - Part-of-speech tagging or other sequence labeling where forbidden transitions should be penalized - Imbalanced NLP classification using the DSC loss variant to improve F1 scores - Prototyping sequence models with Keras when you need CRF without building it from scratch ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides a Conditional Random Field (CRF) layer for TensorFlow 2 Keras models, enabling sequence labeling tasks with built-in support for masking and mixed precision training. Yes-with-conditions. The package solves a real problem (CRF in Keras) and has low install friction, but it is abandoned and last tested with TensorFlow versions from 2021. Install only if you can verify compatibility with your TensorFlow and tensorflow-addons versions, and accept the risk that bugs or incompatibilities will not be fixed upstream. For active projects, consider whether a maintained alternative or a custom CRF implementation is safer. ## Install pip install tf2crf uv add tf2crf poetry add tf2crf ## Installing tf2crf Before you install: Low install friction; pure Python wheel. However, the package is abandoned—last release was 2021-09-10 and last commit 2023-03-25. Depends on tensorflow and tensorflow-addons, which are large dependencies; you'll need to manage compatibility between them yourself. License in practice: MIT License permits commercial and private use with minimal restrictions, making it safe to adopt from a licensing standpoint. Quickstart: pip install tf2crf import tensorflow as tf from tf2crf import CRF, ModelWithCRFLoss from tensorflow.keras.layers import Input, Embedding, Bidirectional, GRU from tensorflow.keras.models import Model inputs = Input(shape=(None,), dtype='int32') output = Embedding(100, 40, 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') model.fit(x=x, y=y, epochs=2, batch_size=2) Requires TensorFlow >= 2.1.0 and compatible tensorflow-addons version; you must manage version alignment yourself. Verify before relying: - Whether the package works with current TensorFlow versions (last tested 2021-09-10) - Compatibility status with recent tensorflow-addons releases - Performance or correctness issues discovered since abandonment ## Package facts - License: MIT License (permissive) - Python support: unspecified - Install friction: low - Maintenance: abandoned - Downloads: 202.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags CRF layer tensorflow keras, sequence labeling tensorflow, conditional random field keras, NLP sequence tagging tensorflow, tensorflow CRF implementation, keras masking CRF, named entity recognition tensorflow, sequence-labeling, nlp, abandoned [View on SkillFed](https://skillfed.io/packages/tf2crf) · [View on PyPI](https://pypi.org/project/tf2crf/)