Skip to main content

Factotum Logo

Factotum

Fast, lightweight, offline context & entity clarification for Vietnamese shorthand, abbreviations, unaccented typing, and missing words — zero GPU required.

Live Demo on Hugging Face Spaces Python 3.10+ Zero Dependencies Offline No GPU Release v1.1.0 MIT License

🇺🇸 English | 🇻🇳 Tiếng Việt

Try it online: open the Hugging Face Spaces Demo to test Factotum right in your browser with no setup required.

Factotum Live Pipeline Demo


You Type Fast — Factotum Clarifies the Context

Every day, users type shorthand (tngt, atgt, csgt, xpvphc, nd), omit Vietnamese diacritics (xu phat vi pham), drop words (an toan thong), or make Telex/key-repeat typos (buowcs, phappp). Fragmented queries like these easily confuse search bars, autocomplete widgets, and entity-extraction pipelines.

Factotum expands abbreviations, restores Vietnamese diacritics, recovers dropped words, and fixes typos using surrounding context — making queries clear for both human readers and downstream search engines:

Real-World Case What You Type Factotum Clarifies To
Unaccented typing xu phat vi pham hanh chinh xử phạt vi phạm hành chính
Chained long abbreviations csgt xpvphc người không có gplx cảnh sát giao thông xử phạt vi phạm hành chính người không có giấy phép lái xe
Context-aware acronym disambiguation nd 23/24 quy định về atgt đường bộ / tòa án nd tối cao nghị định 23/24 quy định về an toàn giao thông đường bộ / tòa án nhân dân tối cao
Dropped middle word an toan thong / xe k bang lai an toàn giao thông / xe không có bằng lái
Telex, key-repeat & spelling typos buowcs, uống dượu bia phạt bao nhiêu, hộ kihw doan bước, uống rượu bia phạt bao nhiêu, hộ kinh doanh
Already valid sentence chạy xe vượt đèn đỏ bị phạt bao nhiêu tiền Kept intact without over-correcting

Key Highlights

  • Built for Context & Entity Clarification: Surfaces the exact domain terms hidden behind shorthand and missing diacritics so keyword search, vector embeddings, RAG, and entity extractors perform far more accurately.
  • Lightweight, Local, Zero GPU: Requires only Python 3.10+ with zero external dependencies. The entire learned knowledge base packs into a single ~1.3 MB .ftm binary file.
  • Full Control Over Private Data: When deployed on your machine or private server, all document learning and text clarification run 100% locally — nothing is ever sent to third-party APIs.
  • Millisecond Latency: Fast enough to sit directly in front of a search box or typeahead dropdown as the user types.
  • Learns Directly From Your Documents: Point Factotum at your .doc, .docx, or .txt folder — it automatically extracts domain terminology with no manual labeling.
  • Transparent & Inspectable: Never hallucinates outside its learned corpus. When an input is too ambiguous, Factotum preserves the original text instead of guessing blindly; all knowledge files can be inspected and edited as plain text.

Benchmark Highlights (v1.1.0)

Evaluated across 20,064 test queries (report_10000_20261127_201343.txt):

Benchmark Suite Queries Raw (KW-Rec) Base-2g (KW-Rec) Factotum v1.1 (KW-Rec / All-KW / Ctx-F1) Median Latency
Document-level Held-out 10,000 19.5% 87.3% 95.8% / 91.0% / 96.2% 3.15 ms
64 Real-World Context Cases 64 23.4% 64.3% 98.4% / 96.9% / 99.7% 12.33 ms
In-Sample Stress Test 10,000 16.9% 91.1% 99.1% / 97.6% / 99.2% 2.22 ms

Factotum Version Progress


Real-World Use Cases & Integration

Factotum works best as a query & text clarification layer for domains with recurring terminology:

User types quickly: "csgt xpvphc người không có gplx"
           ↓
      [ Factotum ]        Clarifies context & entities in milliseconds
           ↓
"cảnh sát giao thông xử phạt vi phạm hành chính người không có giấy phép lái xe"
           ↓
[ Search / Embeddings & RAG / NER / Autocomplete ] → More accurate results
Domain Practical Problem How Factotum Helps
Document Search & RAG Shorthand queries (nd 23/24, xpvphc, gplx) hurt keyword matching and embedding recall. Run model.restore(query) right before search or vector encoding to surface full terms.
Legal & Public Administration Clerks and citizens search laws using tngt, atgt, xpvphc, tòa án nd tối cao. Drop in the included output/factotum_law.ftm model in front of legal search bars or shorthand tools.
Healthcare & Pharmacy Doctors and nurses jot down abbreviated drug names and diagnoses while keeping records private. Run fit_folder() on internal medical notes / drug catalogs (.docx/.txt) to build an offline .ftm model.
Customer Support & Chatbots Customers send unaccented, typo-filled, or word-dropped messages that trip FAQ/intent classifiers. Place Factotum ahead of intent routing or chatbots to boost accuracy with zero per-message API cost.
Accounting & Operations Staff enter reports, material codes, and SOP terms full of company-specific shorthand. Train on internal SOPs and incrementally append new documents via update_folder().

How Factotum Organizes Knowledge


1-Minute Quick Start

1. Install

git clone https://github.com/evilogre1112/Factotum.git
cd Factotum
pip install -e .
from factotum import Factotum

model = Factotum.load("output/factotum_law.ftm")

print(model.restore("csgt xpvphc người không có gplx"))
# cảnh sát giao thông xử phạt vi phạm hành chính người không có giấy phép lái xe

print(model.restore("nd 23/24 quy định về atgt đường bộ"))
# nghị định 23/24 quy định về an toàn giao thông đường bộ

print(model.restore("tòa án nd tối cao"))  # tòa án nhân dân tối cao
print(model.restore("an toan thong"))      # an toàn giao thông

3. Train Factotum on Your Own Documents

Factotum reads .txt, .docx, and .doc files directly:

from factotum import Factotum

# Learn from your document folder
model = Factotum().fit_folder("path/to/your_documents")

# Save as a single portable .ftm file
model.save("my_company.ftm")

# Later, incrementally learn new documents without rebuilding from scratch:
# model.update_folder("path/to/new_documents")

4. Launch Interactive Interfaces

python src/app.py                         # Interactive CLI (ingest data, test queries, update KB)
pip install gradio && python demo/app.py  # Visual Web UI at http://127.0.0.1:7860

Configuration & Customization

1. Use confidence to Auto-Apply or Suggest

When embedding Factotum in an application, retrieve ranked candidates with 0% – 100% confidence scores and explicit edits spans:

results = model.predict("csgt xpvphc người không có gplx", top_k=3)
best = results[0]

if not best.is_fallback and best.confidence >= 0.70:
    # High confidence → safe to auto-apply
    text = best.phrase
elif not best.is_fallback and best.confidence >= 0.50:
    # Medium confidence → show as suggestions
    suggestions = [r.phrase for r in results]
else:
    # Not certain enough → keep user's original input
    text = "csgt xpvphc người không có gplx"

2. Customize Dangling End Words

Edit output/dangling_end_words.txt directly to add or remove function/conjunction words (của, cho, về, thì, và...). Predictions ending abruptly on these words are automatically filtered out. Changes take effect within ~2 seconds without retraining.

3. Manage & Inspect Knowledge Files

See output/README.md for a breakdown of every file in output/ (which files are safe to edit and which should be left untouched).

Optional C++ Acceleration on Linux / macOS (pre-bundled on Windows)

On Windows, the C++ Suffix Array/LCP accelerator is already pre-bundled. On Linux/macOS, Factotum runs out of the box in pure Python; if you want faster ingestion on large corpora, compile the native library with one command:

# Linux
g++ -O3 -std=c++17 -shared -fPIC src/factotum/builder/native/sa_lcp.cpp -o src/factotum/builder/native/libsa_lcp.so

# macOS
g++ -O3 -std=c++17 -shared -fPIC src/factotum/builder/native/sa_lcp.cpp -o src/factotum/builder/native/libsa_lcp.dylib

Current Limitations

To help you evaluate Factotum accurately for your project, here are its practical boundaries:

  • Corpus-dependent: Factotum performs best within the domain of documents you trained it on. Very rare words, unseen entities, or multi-topic social slang may be pulled toward more frequent domain phrases.
  • No deep paragraph-level semantics: Factotum does not use an LLM, so it cannot infer complex intent, summarize text, or rewrite sentences in a different style.
  • Isolated short acronyms: A standalone 3–4 letter token with no surrounding context can validly map to multiple phrases (e.g., cnt could be cho nhà thầu or của nhà thầu). Provide surrounding context or surface Top-3 suggestions in those cases.
  • Multiple consecutive dropped words + heavy typos: Word recovery is optimized for a single dropped word inside a phrase; when a query simultaneously drops multiple consecutive words and contains heavy typos, Factotum prefers returning the original input to avoid wrong edits.

Benchmarks & Documentation

Full evaluation reports, charts, and reproduction instructions are maintained in dedicated documents:

License

MIT License.

Metadata

Release files for factotum-vn-nlp 1.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 factotum-vn-nlp 1.1.0
File Size Uploaded Provenance Actions
factotum_vn_nlp-1.1.0.tar.gz 241.7 kB Without provenance Details for factotum_vn_nlp-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for factotum-vn-nlp 1.1.0
File Interpreter ABI Platform Actions
factotum_vn_nlp-1.1.0-py3-none-any.whl Python 3 none any Details for factotum_vn_nlp-1.1.0-py3-none-any.whl

Total release size: 480.4 kB

Release files / factotum_vn_nlp-1.1.0.tar.gz

Download URL factotum_vn_nlp-1.1.0.tar.gz
Size 241.7 kB
Tags Source
SHA-256 checksum
How to use checksums
37e1c2dbe17835faa8707a0484708561bd7657ba78764f035d50ec5d0c6a845d
BLAKE2b-256 checksum
How to use checksums
646073b030c66892013e08542dcd4c47089bea9abcd2c70be33f7586c6513766
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Release files / factotum_vn_nlp-1.1.0-py3-none-any.whl

Download URL factotum_vn_nlp-1.1.0-py3-none-any.whl
Size 238.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e92c541bdf7208c39aabe0af5da92c3a0bb4785f63b6226f94f08f765f7ebbaa
BLAKE2b-256 checksum
How to use checksums
96f363dc7e0b00ce4715ac7a0fe74a145b499a68e47d6bd62e7a251fd483f65b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.2

Security for factotum-vn-nlp 1.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