Skip to main content

cane-format

A lightweight, dependency-free Python library for CANE (Context-Anchored Natural Expression), an output format for LLM-based named entity recognition: write annotated text as CANE for few-shot prompts, parse model output back into character spans, and convert between CANE and common annotation formats.

CANE is introduced in the paper CANE is a Format: Rethinking Output Formats for Few-Shot LLM-Based Named Entity Recognition (Findings of EMNLP 2026).

pip install cane-format          # Python 3.10+, no dependencies

Early release; the API may change before 1.0.

Example

Entities:
`metastatic breast cancer` is a DISEASE found in `metastatic breast cancer cells`
`breast cancer cells` is a CELL found in `metastatic breast cancer cells caused`
`headache` and `nausea` are a ADR found in `caused headache and` and `and nausea`

One record per entity. The text after found in is an anchor that locates the entity; discontinuous entities list their parts joined by and.

Variant Anchor Discontinuous entities
Base ✗ ✗
Disco ✗ ✓
Context ✓ ✗
Full ✓ ✓

Usage

import cane_format as cane

examples = cane.read_brat("corpus/train")
prompt = cane.build_prompt(new_text, examples=examples[:5], variant="full")

output = your_llm(prompt)  # this library makes no model calls

result = cane.loads(output, text=new_text, variant="full", labels={"DRUG", "ADR"})
result.entities  # entities with character offsets
result.issues    # lines that could not be grounded

cane.write_brat([result.document], "predictions/")

Evaluation: nervaluate-disco via cane.to_nervaluate(docs).

Formats

Format Read / write
CANE loads, dumps
brat standoff read_brat, write_brat
BioC JSON read_bioc_json, write_bioc_json
CoNLL / IOB read_conll, write_conll
Inline XML read_xml, write_xml
Offset JSON read_json, write_json
cane-format convert corpus/ train.conll --from brat --to conll --on-conflict outermost
cane-format parse output.cane --text doc.txt --variant full --to brat -o predictions/

Behaviour

  • Text is kept unchanged; offsets are verified against the text.
  • What a format cannot represent raises an error, or is dropped with a warning if requested.
  • Strict by default; lenient matching is opt-in.

Grammar

output   ::= HEADER | [HEADER NEWLINE] ( EMPTY | record { NEWLINE record } )
record   ::= [HANDLE] parts COPULA [ARTICLE] LABEL [ANCHOR_INTRO anchors]
parts    ::= QUOTE text QUOTE { PART_CONNECTIVE QUOTE text QUOTE }
anchors  ::= QUOTE text QUOTE { ANCHOR_CONNECTIVE QUOTE text QUOTE }

Citation

If you use CANE or this library in your work, please cite the paper:

@inproceedings{cornelius-etal-2026-cane,
    title = "{CANE} is a Format: Rethinking Output Formats for Few-Shot {LLM}-Based Named Entity Recognition",
    author = "Cornelius, Joseph  and
      Ito, Kei K  and
      Rinaldi, Fabio",
    editor = "Lee, Hung-Yi  and
      Dev, Sunipa  and
      Li, Jessy  and
      Elliott, Desmond",
    booktitle = "Findings of the {A}ssociation for {C}omputational {L}inguistics: {EMNLP} 2026",
    month = oct,
    year = "2026",
    address = "Budapest, Hungary",
    publisher = "Association for Computational Linguistics",
    url = "https://aclanthology.org/2026.findings-emnlp.1398/",
    pages = "29773--29800",
    ISBN = "979-8-89176-462-0"
}

This code base is developed with the assistance of Claude (Anthropic).

Metadata

Release files for cane-format 0.1.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 cane-format 0.1.0
File Size Uploaded Provenance Actions
cane_format-0.1.0.tar.gz 125.3 kB Without provenance Details for cane_format-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cane-format 0.1.0
File Interpreter ABI Platform Actions
cane_format-0.1.0-py3-none-any.whl Python 3 none any Details for cane_format-0.1.0-py3-none-any.whl

Total release size: 180.8 kB

Release files / cane_format-0.1.0.tar.gz

Download URL cane_format-0.1.0.tar.gz
Size 125.3 kB
Tags Source
SHA-256 checksum
How to use checksums
99812de93e2fe949082fe01c799dddbcd6ce706b363792ea44b0490318813040
BLAKE2b-256 checksum
How to use checksums
e313275f3ef753e238285cd5b6fb25da8d00be4e093f86425229934e6f8013d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / cane_format-0.1.0-py3-none-any.whl

Download URL cane_format-0.1.0-py3-none-any.whl
Size 55.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
44d20a81b987ea2803c91a07b77a6b1e2071586dd7bd555a8e219227e03d0ef2
BLAKE2b-256 checksum
How to use checksums
707131cd056995271d20a567f06d11b7870eaafa7333043b5f9d6f6526641af5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for cane-format 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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