Text Generation
Transformers
Safetensors
English
Chinese
qwen3
qwen3-8b
lora
qlora
sft
rag
faiss
dense-retrieval
agent
ppo
rlhf
rule-reward
harness-engineering
um-handbook
question-answering
chatbot
education
tensor-talk
Instructions to use TensorCat/TensorTalk with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TensorCat/TensorTalk with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TensorCat/TensorTalk")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("TensorCat/TensorTalk", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use TensorCat/TensorTalk with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TensorCat/TensorTalk" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TensorCat/TensorTalk", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/TensorCat/TensorTalk
- SGLang
How to use TensorCat/TensorTalk 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 "TensorCat/TensorTalk" \ --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": "TensorCat/TensorTalk", "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 "TensorCat/TensorTalk" \ --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": "TensorCat/TensorTalk", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use TensorCat/TensorTalk with Docker Model Runner:
docker model run hf.co/TensorCat/TensorTalk
File size: 8,936 Bytes
052d67e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
from pathlib import Path
import json
import re
import time
from typing import List
import fitz
import pytesseract
from PIL import Image
from um_handbook_config import (
GENERAL_PDF,
COMPLETE_PDF,
GENERAL_BLOCKS,
COMPLETE_BLOCKS,
DATA_ROOT,
MARKDOWN_DIR,
REPORTS_DIR,
)
PROJECT_DIR = Path(__file__).resolve().parent
DATA_ROOT.mkdir(exist_ok=True)
MARKDOWN_DIR.mkdir(exist_ok=True)
REPORTS_DIR.mkdir(exist_ok=True)
GENERAL_MD = MARKDOWN_DIR / "general_handbook_structured.md"
COMPLETE_MD = MARKDOWN_DIR / "complete_handbook_structured.md"
REPORT_PATH = REPORTS_DIR / "um_handbook_markdown_report.json"
BAD_PAGE_PATTERNS = [
r"\bmore info\b",
r"fsktm[_\.]?um",
r"POSTGRADUATE\s+PROGRAMME\s+HANDBOOK",
r"UNDERGRADUATE\s+PROGRAMME\s+HANDBOOK",
r"^C\s*O\s*N\s*T\s*E\s*N\s*T\s*S$",
]
def normalize_whitespace(text: str) -> str:
text = text.replace("\u00a0", " ").replace("\xad", "")
text = text.replace("fi", "fi").replace("fl", "fl")
text = re.sub(r"[ \t]+", " ", text)
text = re.sub(r"\n{3,}", "\n\n", text)
return text.strip()
def clean_page_text(text: str) -> str:
lines = []
for raw in text.splitlines():
line = raw.strip()
if not line:
continue
if re.fullmatch(r"\d+", line):
continue
if len(line) == 1 and not line.isalnum():
continue
lines.append(line)
text = "\n".join(lines)
text = re.sub(r"(?m)^\s*[•▪●]\s*", "- ", text)
text = re.sub(r"(?m)^\s*([a-z])\)\s*", r"- ", text)
return normalize_whitespace(text)
def ocr_page(page: fitz.Page, zoom: float = 1.5) -> str:
pix = page.get_pixmap(matrix=fitz.Matrix(zoom, zoom), alpha=False)
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
return pytesseract.image_to_string(img)
def looks_like_noise_page(text: str) -> bool:
t = normalize_whitespace(text)
if not t:
return True
compact = t.replace("\n", " ")
alpha_words = re.findall(r"[A-Za-z][A-Za-z&'/-]+", compact)
# real content pages normally have more than a handful of alphabetic words
if len(alpha_words) < 8:
return True
# low-information cover / contents / banner pages
for pattern in BAD_PAGE_PATTERNS:
if re.search(pattern, compact, flags=re.IGNORECASE):
if len(alpha_words) < 60:
return True
# very short all-caps dividers
if len(compact) < 120 and compact.upper() == compact and len(alpha_words) < 15:
return True
return False
def extract_page_text(doc: fitz.Document, page_number_1_based: int) -> tuple[str, str]:
page = doc[page_number_1_based - 1]
native = clean_page_text(page.get_text("text"))
source = "native"
need_ocr = len(native) < 120 or looks_like_noise_page(native)
if need_ocr:
ocr_text = clean_page_text(ocr_page(page))
if len(ocr_text) > len(native):
native = ocr_text
source = "ocr"
if looks_like_noise_page(native):
return "", f"{source}_filtered"
return native, source
def progress_bar(current: int, total: int, width: int = 28) -> str:
if total <= 0:
return "[no-progress]"
filled = int(width * current / total)
bar = "#" * filled + "-" * (width - filled)
pct = (current / total) * 100
return f"[{bar}] {current}/{total} ({pct:5.1f}%)"
def block_to_markdown(doc: fitz.Document, block: dict, block_index: int, total_blocks: int, pdf_label: str) -> tuple[str, dict]:
start, end = block["pages"]
if block.get("manual_text"):
print()
print("=" * 90)
print(f"[BLOCK {block_index}/{total_blocks}] {pdf_label} | {block['section']} :: {block['subsection']} | pages {start}-{end} | MANUAL OVERRIDE")
print("=" * 90)
body = normalize_whitespace(block["manual_text"])
header = (
f"## {block['section']} :: {block['subsection']}\n\n"
f"- scope_label: {block['scope_label']}\n"
f"- source_doc: {block['source_doc']}\n"
f"- pages: {start}-{end}\n"
)
meta = {
"section": block["section"],
"subsection": block["subsection"],
"scope_label": block["scope_label"],
"source_doc": block["source_doc"],
"pages": [start, end],
"page_stats": [{"page": f"{start}-{end}", "source": "manual_visual_override", "chars": len(body), "seconds": 0.0}],
"total_chars": len(body),
"seconds": 0.0,
}
print(f"[DONE BLOCK] {block['section']} :: {block['subsection']} | MANUAL OVERRIDE")
return (header + ("\n" + body + "\n" if body else "\n"), meta)
pieces: List[str] = []
page_stats = []
block_start_time = time.time()
total_pages = end - start + 1
print()
print("=" * 90)
print(f"[BLOCK {block_index}/{total_blocks}] {pdf_label} | {block['section']} :: {block['subsection']} | pages {start}-{end}")
print("=" * 90)
for i, p in enumerate(range(start, end + 1), start=1):
page_start_time = time.time()
print(f" {progress_bar(i, total_pages)} -> extracting page {p} ... ", end="", flush=True)
text, source = extract_page_text(doc, p)
elapsed = time.time() - page_start_time
if text:
pieces.append(f"### Page {p}\n{text}")
page_stats.append(
{
"page": p,
"source": source,
"chars": len(text),
"seconds": round(elapsed, 2),
}
)
print(f"{source.upper():12s} | chars={len(text):5d} | {elapsed:6.2f}s", flush=True)
block_elapsed = time.time() - block_start_time
body = "\n\n".join(pieces).strip()
header = (
f"## {block['section']} :: {block['subsection']}\n\n"
f"- scope_label: {block['scope_label']}\n"
f"- source_doc: {block['source_doc']}\n"
f"- pages: {start}-{end}\n"
)
meta = {
"section": block["section"],
"subsection": block["subsection"],
"scope_label": block["scope_label"],
"source_doc": block["source_doc"],
"pages": [start, end],
"page_stats": page_stats,
"total_chars": len(body),
"seconds": round(block_elapsed, 2),
}
print(f"[DONE BLOCK] {block['section']} :: {block['subsection']} | {block_elapsed:.2f}s")
return (header + ("\n" + body + "\n" if body else "\n"), meta)
def write_markdown(pdf_path: Path, blocks: list[dict], out_path: Path, title: str) -> list[dict]:
print()
print("#" * 100)
print(f"[START] Building markdown for: {title}")
print(f"[PDF] {pdf_path}")
print(f"[OUT] {out_path}")
print(f"[BLOCKS] {len(blocks)}")
print("#" * 100)
sections = [f"# {title}", ""]
report_rows = []
start_time = time.time()
with fitz.open(pdf_path) as doc:
for idx, block in enumerate(blocks, start=1):
md, meta = block_to_markdown(
doc=doc,
block=block,
block_index=idx,
total_blocks=len(blocks),
pdf_label=pdf_path.name,
)
sections.append(md)
report_rows.append(meta)
out_path.write_text("\n\n".join(sections).strip() + "\n", encoding="utf-8")
elapsed = time.time() - start_time
print(f"[DONE FILE] {title} -> {out_path} | {elapsed:.2f}s")
return report_rows
def main() -> None:
total_start = time.time()
print("[INFO] Markdown preprocess started")
print(f"[INFO] General PDF : {GENERAL_PDF}")
print(f"[INFO] Complete PDF: {COMPLETE_PDF}")
print(f"[INFO] General MD : {GENERAL_MD}")
print(f"[INFO] Complete MD : {COMPLETE_MD}")
print(f"[INFO] Report Path : {REPORT_PATH}")
general_report = write_markdown(
GENERAL_PDF,
GENERAL_BLOCKS,
GENERAL_MD,
"General Handbook (Structured Markdown)",
)
complete_report = write_markdown(
COMPLETE_PDF,
COMPLETE_BLOCKS,
COMPLETE_MD,
"Complete Handbook (Structured Markdown)",
)
report = {
"generated_files": {
"general_markdown": str(GENERAL_MD),
"complete_markdown": str(COMPLETE_MD),
},
"general_block_count": len(general_report),
"complete_block_count": len(complete_report),
"general_blocks": general_report,
"complete_blocks": complete_report,
"total_seconds": round(time.time() - total_start, 2),
}
REPORT_PATH.write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
print()
print("=" * 100)
print(f"Wrote: {GENERAL_MD}")
print(f"Wrote: {COMPLETE_MD}")
print(f"Wrote: {REPORT_PATH}")
print(f"[ALL DONE] Total time: {time.time() - total_start:.2f}s")
print("=" * 100)
if __name__ == "__main__":
main()
|