TopHumanWriting: exemplar-alignment writing audit toolkit (PDF + exemplar library).
Project description
TopHumanWriting | 顶级范文对齐写作(后端 Python 包:CLI + SDK)
English
TopHumanWriting is a backend-only Python package (CLI + library) for “exemplar-alignment writing audit”:
- Build a local PDF exemplar library (50–200 PDFs, zh/en/mixed)
- Audit a target PDF and output white-box results:
- what looks unlike exemplars, where, and why
- exemplar evidence (PDF + page)
- optional “rewrite templates” (controlled, temperature=0)
- Optional CiteCheck: author-year citation accuracy with evidence paragraphs
This PyPI distribution intentionally does not ship the web UI (to keep the package lean).
Install
- Minimal:
pip install tophumanwriting - With RAG (required for exemplar retrieval):
pip install "tophumanwriting[rag]"(default: Chroma)- or
pip install "tophumanwriting[rag-faiss]"(FAISS)
- With optional syntax checks:
pip install "tophumanwriting[syntax]" - Everything for backend:
pip install "tophumanwriting[all]"
Quickstart (CLI)
-
(Optional) Configure OpenAI-compatible LLM API (used by LLM review + CiteCheck):
TOPHUMANWRITING_LLM_API_KEY(fallback:SKILL_LLM_API_KEY,OPENAI_API_KEY)TOPHUMANWRITING_LLM_BASE_URL(fallback:SKILL_LLM_BASE_URL,OPENAI_BASE_URL, usually ends with/v1)TOPHUMANWRITING_LLM_MODEL(fallback:SKILL_LLM_MODEL,OPENAI_MODEL)
-
Run end-to-end (build once if needed → audit):
thw run --paper main.pdf --exemplars reference_papers --max-llm-tokens 200000
-
Output: the CLI prints an export folder that contains
result.json+report.md.
Budgeting:
- Use
--max-llm-tokensto hard-cap total LLM usage per run (LLM review + CiteCheck). - (Optional) Provide
--cost-per-1m-tokensand--max-costto show an approximate cost in reports (unitless; depends on your pricing).
Build Once → Audit Many (recommended for real workflows)
- Download the semantic embedder model (once):
thw models download-semantic
- Build exemplar library artifacts (slow, one-time):
thw library build --name reference_papers --pdf-root reference_papers
- Run audits repeatedly (fast reuse):
thw audit run --paper main.pdf --library reference_papers --max-llm-tokens 200000
Quickstart (Python)
from tophumanwriting import TopHumanWriting
thw = TopHumanWriting(exemplars="reference_papers") # folder with PDFs
export = thw.run("main.pdf", max_llm_tokens=200000) # fit if needed + audit
print(export.report_md_path)
Data & Cache Location
TopHumanWriting stores reusable artifacts under a writable data directory:
TopHumanWriting_data/settings.json(optional LLM config)libraries/*.json(library manifests / stats)libraries/<name>.sentences.json+libraries/<name>.embeddings.npyrag/<library>/(RAG index)cite/<library>/(citation bank)audit/exports/(export bundles)
Override with TOPHUMANWRITING_DATA_DIR (legacy AIWORDDETECTOR_DATA_DIR also works).
Limitations / Notes
- Only text-based PDFs are supported (scanned PDFs are out of scope).
- If you change the semantic model but keep an old index, rebuild the library to see changes.
Publishing to PyPI (maintainers)
- Bump version in
pyproject.toml - Build:
python -m build
- Verify:
python -m twine check dist/*
- Upload:
python -m twine upload dist/tophumanwriting-<version>*
中文
TopHumanWriting 是一个后端 Python 包(CLI + SDK),用于“模仿同领域顶级范文写法”的对照式白箱体检:
- 你提供本地 PDF 范文库(50–200 篇,中英混合可)
- 对待检测 PDF 做端到端体检并输出白箱结果:
- 哪里不像范文、为什么不像、参考哪段范文(PDF+页码)
- 可选:给出“可复用的改写模板/句式骨架”(温度=0,尽量不发散)
- 可选:引用核查(CiteCheck),核查 author-year 引用是否准确/是否张冠李戴(附证据段落)
本 PyPI 包为了更轻量,不包含前端网页。
安装
- 最小安装:
pip install tophumanwriting - 安装检索编排(做范文检索必需):
pip install "tophumanwriting[rag]"(默认:Chroma)- 或
pip install "tophumanwriting[rag-faiss]"(FAISS)
- 可选句法检查:
pip install "tophumanwriting[syntax]" - 一次装齐后端所有依赖:
pip install "tophumanwriting[all]"
快速开始(CLI)
-
(可选)配置 OpenAI 兼容大模型 API(用于 LLM 分治体检 + CiteCheck):
TOPHUMANWRITING_LLM_API_KEY(fallback:SKILL_LLM_API_KEY,OPENAI_API_KEY)TOPHUMANWRITING_LLM_BASE_URL(fallback:SKILL_LLM_BASE_URL,OPENAI_BASE_URL,通常以/v1结尾)TOPHUMANWRITING_LLM_MODEL(fallback:SKILL_LLM_MODEL,OPENAI_MODEL)
-
一条命令端到端运行(必要时会自动建库):
thw run --paper main.pdf --exemplars reference_papers --max-llm-tokens 200000
-
输出:命令行会打印导出目录,里面包含
result.json+report.md。
预算说明:
- 用
--max-llm-tokens硬限制单次运行的 LLM 总 tokens(同时覆盖 LLM 分治体检 + 引用核查)。 - (可选)用
--cost-per-1m-tokens+--max-cost仅用于在报告里展示估算成本(单位自定)。
建库一次 → 反复体检(推荐)
- 下载一次语义模型:
thw models download-semantic - 建范文库工件(慢,一次性):
thw library build --name reference_papers --pdf-root reference_papers - 反复体检(复用索引):
thw audit run --paper main.pdf --library reference_papers --max-llm-tokens 200000
快速开始(Python)
from tophumanwriting import TopHumanWriting
thw = TopHumanWriting(exemplars="reference_papers")
export = thw.run("main.pdf", max_llm_tokens=200000)
print(export.report_md_path)
数据与缓存位置
TopHumanWriting 会把可复用的工件写到数据目录:
TopHumanWriting_data/settings.jsonlibraries/*.jsonlibraries/<库名>.sentences.json+libraries/<库名>.embeddings.npyrag/<库名>/(检索索引)cite/<库名>/(引用句式库)audit/exports/(导出包)
可用环境变量 TOPHUMANWRITING_DATA_DIR 覆盖(旧的 AIWORDDETECTOR_DATA_DIR 也兼容)。
注意事项
- 仅支持可复制文字的文本型 PDF;扫描版不考虑。
- 更换语义模型后建议重建范文库工件,否则效果可能看起来没变化。
Project Structure | 项目结构
TopHumanWriting/
├── tophumanwriting/ # PyPI package (CLI + sklearn-style API)
│ ├── api.py # TopHumanWriting.fit/audit/run
│ ├── cli.py # `thw` entrypoint
│ ├── models.py # semantic model download/status
│ ├── _version.py
│ └── locales/
├── aiwd/ # audit core (RAG/citecheck/LLM reviews)
├── ai_word_detector.py # legacy module (kept for compatibility)
├── pyproject.toml
├── MANIFEST.in
└── README.md
License
MIT License - See LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tophumanwriting-2.9.6.tar.gz.
File metadata
- Download URL: tophumanwriting-2.9.6.tar.gz
- Upload date:
- Size: 177.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14080e8ee5ef3042ec0d9d2991b1f7469a1ebd302710574ec1ef3e4feff8362a
|
|
| MD5 |
98ded17040dcaffe5c7c8e77fb32f9a7
|
|
| BLAKE2b-256 |
9e17eaa6d1bb3f273b46b1daf92aedda98834a66104207ab495ebb1347ae40ba
|
File details
Details for the file tophumanwriting-2.9.6-py3-none-any.whl.
File metadata
- Download URL: tophumanwriting-2.9.6-py3-none-any.whl
- Upload date:
- Size: 184.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b0218e4fd96d8faa0161fcb281e9b00fdfe98790d6ee973d92cef4ca7ba7f32
|
|
| MD5 |
b752eab3c5daa1997aebfd466404c313
|
|
| BLAKE2b-256 |
b08ceb436863af47873ca87d2c9c080c3b2ae6abe5fcd2dfe87eb73b148330a3
|