Token Classification
Transformers
Safetensors
ONNX
Transformers.js
modernbert
punctuation
punctuation-restoration
asr
speech-recognition
transcription
mmbert
Instructions to use seamon67/Punctuation-Restoration with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use seamon67/Punctuation-Restoration with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="seamon67/Punctuation-Restoration")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("seamon67/Punctuation-Restoration") model = AutoModelForTokenClassification.from_pretrained("seamon67/Punctuation-Restoration", device_map="auto") - Transformers.js
How to use seamon67/Punctuation-Restoration with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('token-classification', 'seamon67/Punctuation-Restoration'); - Notebooks
- Google Colab
- Kaggle
Download code/punct/build_spoken.py from seamon67/Punctuation-Restoration: direct link, hf CLI and curl.
- Browser
- Download file 2.44 kB
-
https://huggingface.co/seamon67/Punctuation-Restoration/resolve/main/code/punct/build_spoken.py
- Command line
-
hf download hf://seamon67/Punctuation-Restoration/code/punct/build_spoken.py
-
curl -L -o build_spoken.py https://huggingface.co/seamon67/Punctuation-Restoration/resolve/main/code/punct/build_spoken.py
2.44 kB
| """Training windows from Qwen spoken-style transcripts (punct/gen_spoken.py) + merged training dir. | |
| python punct/build_spoken.py OUT_DIR EVAL_DIR V1_DATA_DIR SPOKEN.jsonl [...] | |
| Windows as in build_data.py (<= 230 units, 30% cut mid-sentence); transcripts sharing a sentence with any eval set are dropped. | |
| OUT_DIR/spoken.parquet and OUT_DIR/data/{train,val}.parquet (= v1 train + spoken windows; v1 val).""" | |
| import json, os, random, re, shutil, sys | |
| import pandas as pd | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from common import units, L2I, NOSPACE | |
| OUT, EV, V1 = sys.argv[1:4]; ins = sys.argv[4:] | |
| os.makedirs(f"{OUT}/data", exist_ok=True); rng = random.Random(0) | |
| CODE = {"Chinese (Simplified)": "cmn_Hani", "Chinese (Traditional)": "cmn_Hani", "Japanese": "jpn_Jpan", "Greek": "ell_Grek", "Thai": "tha_Thai"} | |
| norm = lambda s: re.sub(r"\W+", " ", s.lower()).strip() | |
| SPLIT = re.compile(r"(?<=[.!?。!?])\s*") | |
| ev = set() | |
| for f in ["flores.parquet", "ted.parquet", "europarl.parquet"]: | |
| for t in pd.read_parquet(f"{EV}/{f}").text: | |
| ev |= {norm(x) for x in SPLIT.split(t) if len(x) > 25} | |
| rows, dropped, n = [], 0, 0 | |
| for fn in ins: | |
| for line in open(fn): | |
| d = json.loads(line); n += 1 | |
| lang = CODE.get(d["lang"], "xxx_Latn") | |
| if lang == "tha_Thai": | |
| continue | |
| t = d["text"] | |
| if any(norm(x) in ev for x in SPLIT.split(t) if len(x) > 25): | |
| dropped += 1; continue | |
| c, e, l = units(t, lang); nos = lang in NOSPACE; cap = 400 if nos else 230 | |
| for a in range(0, len(e), cap): | |
| ee, ll = e[a:a + cap], l[a:a + cap] | |
| if len(ee) < 8: | |
| continue | |
| off = e[a - 1] + (0 if nos else 1) if a else 0 | |
| if rng.random() < 0.3 and len(ee) > 12: | |
| cut = rng.randint(8, len(ee) - 1); ee, ll = ee[:cut], ll[:cut] | |
| rows.append((c[off:ee[-1]], [x - off for x in ee], [L2I[x] for x in ll], d["lang"])) | |
| sp = pd.DataFrame(rows, columns=["text", "ends", "labs", "lang"]); sp.to_parquet(f"{OUT}/spoken.parquet") | |
| print("transcripts", n, "dropped (eval overlap)", dropped, "windows", len(sp), "languages", sp.lang.nunique(), flush=True) | |
| t = pd.read_parquet(f"{V1}/train.parquet") | |
| pd.concat([t, sp], ignore_index=True).sample(frac=1.0, random_state=0).to_parquet(f"{OUT}/data/train.parquet") | |
| shutil.copy(f"{V1}/val.parquet", f"{OUT}/data/val.parquet"); print("train", len(t) + len(sp)) | |