Metadata-Version: 2.4
Name: flowx-openner
Version: 0.2.0
Summary: Small, on-device NER & de-identification models for regulated industries (banking, insurance, logistics).
Project-URL: Homepage, https://flowx.ai
Project-URL: Repository, https://github.com/flowx-ai/openner
Project-URL: Model Hub, https://huggingface.co/flowxai
Author-email: "FlowX.AI" <opensource@flowx.ai>
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Keywords: banking,de-identification,insurance,logistics,ner,on-device,pii,privacy,slm
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.10
Requires-Dist: numpy
Requires-Dist: pyyaml>=6.0
Requires-Dist: torch>=2.2
Requires-Dist: transformers>=4.48
Provides-Extra: all
Requires-Dist: accelerate>=0.30; extra == 'all'
Requires-Dist: anthropic; extra == 'all'
Requires-Dist: datasets>=2.20; extra == 'all'
Requires-Dist: evaluate>=0.4; extra == 'all'
Requires-Dist: fastapi; extra == 'all'
Requires-Dist: google-genai; extra == 'all'
Requires-Dist: onnx; extra == 'all'
Requires-Dist: onnxruntime; extra == 'all'
Requires-Dist: onnxscript; extra == 'all'
Requires-Dist: openai; extra == 'all'
Requires-Dist: optimum; extra == 'all'
Requires-Dist: pillow>=10; extra == 'all'
Requires-Dist: seqeval>=1.2; extra == 'all'
Requires-Dist: uvicorn; extra == 'all'
Provides-Extra: benchmark
Requires-Dist: anthropic; extra == 'benchmark'
Requires-Dist: google-genai; extra == 'benchmark'
Requires-Dist: openai; extra == 'benchmark'
Provides-Extra: dev
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: export
Requires-Dist: onnx; extra == 'export'
Requires-Dist: onnxruntime; extra == 'export'
Requires-Dist: onnxscript; extra == 'export'
Requires-Dist: optimum; extra == 'export'
Provides-Extra: layout
Requires-Dist: pillow>=10; extra == 'layout'
Provides-Extra: serve
Requires-Dist: fastapi; extra == 'serve'
Requires-Dist: uvicorn; extra == 'serve'
Provides-Extra: train
Requires-Dist: accelerate>=0.30; extra == 'train'
Requires-Dist: datasets>=2.20; extra == 'train'
Requires-Dist: evaluate>=0.4; extra == 'train'
Requires-Dist: seqeval>=1.2; extra == 'train'
Description-Content-Type: text/markdown

# OpenNER

Small, on-device **NER & de-identification** models for regulated industries —
**banking · insurance · logistics**. Fine-tuned encoders that match or beat frontier
LLMs on structured, convention-bound extraction, while running on a CPU, a single GPU,
Apple Silicon, or in the browser/edge via ONNX — with **zero data egress**.

Built and maintained by [**FlowX.AI**](https://flowx.ai). Apache-2.0.
Pretrained models: [huggingface.co/flowxai](https://huggingface.co/flowxai).

## Install

```bash
pip install flowx-openner            # core inference
pip install "flowx-openner[serve]"   # + FastAPI server
pip install "flowx-openner[all]"     # + training, ONNX export, benchmarking
```

## Quickstart

Load any published model straight from the Hub by its repo id, or a local directory:

```python
from openner import analyze

res = analyze("Wire EUR 12,500 to DE44 5001 0517 5407 3249 31", model="flowxai/ibandetect")
print(res.entities)                       # [{'type': 'IBAN', 'text': 'DE44 ...', 'valid': True, ...}]

# De-identify with a compliance profile → redacted text + a signed audit report
deid = res.deidentify("pci-glba")
print(deid.text)                          # "Wire EUR 12,500 to [IBAN]"
print(deid.report.to_json())
```

Detected identifiers are **validated by checksum** — IBAN mod-97, card Luhn, ISIN/LEI
(ISO-7064), container (ISO-6346), VIN (ISO-3779), and national IDs (CNP, EGN, OIB, EMŠO,
Steuer-ID, NIR, Codice Fiscale, HU tax id) — a correctness guarantee general LLMs lack.

De-identification **fails safe**: every detected candidate is redacted even if its
checksum fails; the `valid` flag is recorded in the audit report but never suppresses
redaction.

## Models

33 models grouped into five collections on the Hub. Every model is a fine-tuned encoder
(token- or text-classification, plus one LayoutLMv3 Document-AI model), Apache-2.0, with
its own model card. Load any of them by short name (`analyze(text, model="mortgagedocner")`)
and it is pulled from `flowxai/<name>` on first use.

| Collection | Models |
|---|---|
| **Banking** | `ibandetect`, `panredact`, `counterpartylink`, `txnclassify`, `kycextract`, `sanctionscreen`, `amlnarrate`, `filingtag`, `mortgagedocner` |
| **Insurance** | `policydetect`, `claimextract`, `assetdetect`, `perilclassify`, `partyresolve`, `codemap`, `insurredact`, `medclaimner` |
| **Logistics** | `containerdetect`, `portroute`, `incotermextract`, `hazmatguard`, `partylink`, `bolparse`, `traderedact`, `hscodeclassify` |
| **Healthcare** | `intentrouter` (inbox routing), `expiryner` (expiry / lot / returns) |
| **Cross-industry** | `piiguard` (multilingual PII), `privacyfilter`, `invoicener`, `cvner`, `kybextract`, `docformner` (Document-AI, scanned forms) |

`piiguard` covers en, ro, bg, hu, sl, hr, de, it, fr with country-matched national-ID
checksums. `docformner` is a LayoutLMv3 Document-AI preview trained on synthetic rendered
forms; fine-tune it on real OCR'd scans before production. `hscodeclassify`, `intentrouter`
and `privacyfilter` are text classifiers; the rest are token-classification NER.

## Serve it (local REST API)

```bash
openner-serve                         # http://127.0.0.1:8000  (API + web UI)
```

```bash
curl localhost:8000/models
curl -X POST localhost:8000/deidentify -H 'content-type: application/json' \
  -d '{"text":"Wire to DE44 5001 0517 5407 3249 31","model":"ibandetect","profile":"pci-glba"}'
```

Endpoints: `GET /health`, `GET /models`, `POST /analyze`, `POST /deidentify`
(redacted text + a **signed audit report**), `POST /filter` (PrivacyFilter guard:
NONE / PERSONAL / FINANCIAL / HEALTH). Everything runs on-device.

## Train your own

Each model is one YAML config. Train on a laptop (small slice), a CUDA box, or a cloud GPU:

```bash
python -m openner.train --config configs/banking/filingtag.yaml --profile full
```

Add a model = add `configs/<industry>/<name>.yaml` (+ a dataset adapter if new). No other
code changes. Training data is synthetic and checksum-validated by construction (plus real
SEC filings for `filingtag`).

## Export for edge / phone / browser

```bash
python -m openner.export.to_onnx --model artifacts/filingtag-full
# → model.onnx (fp32) + model.int8.onnx (INT8, ~4× smaller), parity-checked against PyTorch.
# Load with onnxruntime / onnxruntime-web / onnxruntime-mobile.
```

## Layout

```
openner/    industry-agnostic library (data · train · metrics · serve · deid · export · benchmark)
configs/    one YAML per model  (banking/ · insurance/ · logistics/ · cross/)
scripts/    smoke_test.sh (laptop) · train_gcp.sh (GPU) · run_benchmark.py
```

## License

Apache-2.0. Copyright 2026 FlowX.AI. See [`LICENSE`](LICENSE) and [`NOTICE`](NOTICE).
Models are trained on synthetic, checksum-validated data; validate on your own real
documents before production use.
