{"id":1675,"library":"python-crfsuite","title":"python-crfsuite","description":"python-crfsuite is a Python binding for CRFsuite, a fast implementation of Conditional Random Fields (CRFs) for labeling sequential data. It's widely used in Natural Language Processing (NLP) for tasks like Named Entity Recognition (NER), Part-of-Speech (POS) tagging, and other sequence labeling problems. The current version is 0.9.12, and releases primarily focus on Python version compatibility and stability.","status":"active","version":"0.9.12","language":"python","source_language":"en","source_url":"https://github.com/scrapinghub/python-crfsuite","tags":["NLP","Machine Learning","CRF","Sequence Labeling","Conditional Random Fields"],"install":[{"cmd":"pip install python-crfsuite","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"wrong":"import pycrfsuite\ntrainer = pycrfsuite.Trainer(...)","symbol":"Trainer","correct":"from pycrfsuite import Trainer"},{"wrong":"import pycrfsuite\ntagger = pycrfsuite.Tagger(...)","symbol":"Tagger","correct":"from pycrfsuite import Tagger"},{"wrong":"import pycrfsuite\nitem_sequence = pycrfsuite.ItemSequence(...)","symbol":"ItemSequence","correct":"from pycrfsuite import ItemSequence"}],"quickstart":{"code":"import pycrfsuite\nimport os\n\n# Sample data (features, labels)\nX_train = [\n    [['walk', 'big'], ['dog']],\n    [['eat', 'apple'], ['red', 'apple']],\n    [['run', 'fast'], ['cat']]\n]\ny_train = [\n    ['VERB', 'NOUN'],\n    ['VERB', 'NOUN'],\n    ['VERB', 'NOUN']\n]\n\n# 1. Train a CRF model\ntrainer = pycrfsuite.Trainer(verbose=False)\nfor xseq, yseq in zip(X_train, y_train):\n    trainer.append(xseq, yseq)\n\ntrainer.set_params({\n    'c1': 1.0,   # coefficient for L1 penalty\n    'c2': 1e-3,  # coefficient for L2 penalty\n    'max_iterations': 50, # stop earlier\n    'feature.possible_transitions': True\n})\n\nmodel_filename = 'model.crfsuite'\ntrainer.train(model_filename)\n\nprint(f\"Model trained and saved to '{model_filename}'\")\n\n# 2. Use the trained model for tagging\ntagger = pycrfsuite.Tagger()\ntagger.open(model_filename)\n\nX_test = [\n    [['see', 'small'], ['dog']]\n]\n\npredicted_tags = [tagger.tag(xseq) for xseq in X_test]\nprint(f\"Test sequence: {X_test}\")\nprint(f\"Predicted tags: {predicted_tags}\")\n\n# Clean up the model file\nos.remove(model_filename)","lang":"python","description":"This quickstart demonstrates how to train a Conditional Random Field (CRF) model using `pycrfsuite.Trainer` and then use the trained model with `pycrfsuite.Tagger` to predict labels for new sequences. The example uses a simple list-of-lists format for features and labels, which is common for sequence labeling tasks."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer (3.10, 3.11, 3.12, 3.13, 3.14 are supported). If unable to upgrade, pin to `python-crfsuite<0.9.12`.","message":"Version 0.9.12 dropped support for Python 3.6, 3.7, 3.8, and 3.9. Users on these older Python versions must either upgrade their Python environment or pin to an older `python-crfsuite` version.","severity":"breaking","affected_versions":"0.9.12 and later"},{"fix":"Always use `import pycrfsuite` in your Python code, even though you install it with `pip install python-crfsuite`.","message":"The PyPI package name is `python-crfsuite`, but the module to import in your Python code is `pycrfsuite`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your feature sequences are formatted as `list[list[str]]` where the outer list represents the sequence, and each inner list represents the features for a single token/item in that sequence. Refer to the quickstart for an example.","message":"The input data format for `Trainer.append()` and `Tagger.tag()` requires a list of feature lists for each item in the sequence. Each feature list is typically a list of strings (e.g., `[['feature1', 'feature2'], ['feature3']]`). Incorrectly formatted input will lead to errors.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.9.12':56 'bind':10 'compat':64 'condit':17,73 'crf':70 'crfs':20 'crfsuit':3,6,12 'current':53 'data':24 'entiti':38 'fast':14 'field':19,75 'focus':60 'implement':15 'label':22,50,72 'languag':31 'learn':69 'like':36 'machin':68 'name':37 'natur':30 'ner':40 'nlp':33,67 'part':42 'part-of-speech':41 'pos':45 'primarili':59 'problem':51 'process':32 'python':2,5,9,62 'python-crfsuit':1,4 'random':18,74 'recognit':39 'releas':58 'sequenc':49,71 'sequenti':23 'speech':44 'stabil':66 'tag':46 'task':35 'use':28 'version':54,63 'wide':27","created_at":"2026-04-09T03:58:18.676175+00:00","updated_at":"2026-04-16T20:17:32.598520+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.9.12","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/scrapinghub/python-crfsuite","docs":null,"changelog":null,"pypi":"https://pypi.org/project/python-crfsuite/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-08-27","next_check":"2026-07-30","install_tag":null}}