Text Generation
Transformers
Safetensors
English
nano-proofread
grammar-correction
proofreading
homophones
tiny
byte-level
from-scratch
Instructions to use vukrosic/nano-proofread with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vukrosic/nano-proofread with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="vukrosic/nano-proofread")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("vukrosic/nano-proofread", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use vukrosic/nano-proofread with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vukrosic/nano-proofread" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vukrosic/nano-proofread", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/vukrosic/nano-proofread
- SGLang
How to use vukrosic/nano-proofread with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "vukrosic/nano-proofread" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vukrosic/nano-proofread", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "vukrosic/nano-proofread" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vukrosic/nano-proofread", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use vukrosic/nano-proofread with Docker Model Runner:
docker model run hf.co/vukrosic/nano-proofread
Upload test_nano_proofread.py with huggingface_hub
Browse files- test_nano_proofread.py +61 -0
test_nano_proofread.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests that gate the science: identity examples exist, most inputs carry an error,
|
| 2 |
+
corrected phrases are clean (no doubled words), determinism, the context-free script
|
| 3 |
+
provably fails on a real fraction (the must-beat-a-script filter), and a regression
|
| 4 |
+
test that the PUBLISHED weights still fix the demo phrases.
|
| 5 |
+
|
| 6 |
+
pytest test_nano_proofread.py -q
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import os
|
| 12 |
+
|
| 13 |
+
from data_proofread import naive_fix, proofread_pairs
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_identity_examples_exist():
|
| 17 |
+
pairs = proofread_pairs(7, 4000)
|
| 18 |
+
ident = sum(1 for i, t in pairs if i[:-4] == t)
|
| 19 |
+
assert 0.08 <= ident / len(pairs) <= 0.25
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def test_most_inputs_have_an_error():
|
| 23 |
+
pairs = proofread_pairs(3, 4000)
|
| 24 |
+
changed = sum(1 for i, t in pairs if i[:-4] != t)
|
| 25 |
+
assert changed / len(pairs) > 0.7
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def test_targets_are_clean():
|
| 29 |
+
for _, tgt in proofread_pairs(5, 2000):
|
| 30 |
+
toks = tgt.split()
|
| 31 |
+
assert all(toks[i] != toks[i + 1] for i in range(len(toks) - 1)), tgt
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def test_deterministic():
|
| 35 |
+
assert proofread_pairs(0, 300) == proofread_pairs(0, 300)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def test_context_free_script_cannot_be_exact():
|
| 39 |
+
"""The best context-free script must get a real fraction of examples wrong,
|
| 40 |
+
because the homophone confusions are context-dependent."""
|
| 41 |
+
pairs = proofread_pairs(11, 4000)
|
| 42 |
+
wrong = sum(1 for inp, tgt in pairs if naive_fix(inp[:-4]) != tgt)
|
| 43 |
+
assert wrong > 0.15 * len(pairs)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_published_weights_reproduce():
|
| 47 |
+
if not (os.path.exists("model.safetensors") and os.path.exists("config.json")):
|
| 48 |
+
import pytest
|
| 49 |
+
pytest.skip("weights not present in this checkout")
|
| 50 |
+
from modeling_nano_proofread import load, proofread
|
| 51 |
+
m = load()
|
| 52 |
+
for phrase, gold in [
|
| 53 |
+
("their going to win", "they're going to win"),
|
| 54 |
+
("its raining again", "it's raining again"),
|
| 55 |
+
("the the cat sat", "the cat sat"),
|
| 56 |
+
("we went they're", "we went there"),
|
| 57 |
+
("this is bigger then that", "this is bigger than that"),
|
| 58 |
+
("they're house is big", "their house is big"),
|
| 59 |
+
("she is happy today", "she is happy today"), # already correct -> unchanged
|
| 60 |
+
]:
|
| 61 |
+
assert proofread(m, phrase) == gold, (phrase, proofread(m, phrase))
|