Text Generation
Transformers
Safetensors
Uzbek
Russian
t5
text2text-generation
uzbek
russian
text-normalization
error-correction
byt5
base-model
finetuning
text-generation-inference
Instructions to use islomov/rubai-corrector-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use islomov/rubai-corrector-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="islomov/rubai-corrector-base")# Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("islomov/rubai-corrector-base") model = AutoModelForSeq2SeqLM.from_pretrained("islomov/rubai-corrector-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use islomov/rubai-corrector-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "islomov/rubai-corrector-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "islomov/rubai-corrector-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/islomov/rubai-corrector-base
- SGLang
How to use islomov/rubai-corrector-base 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 "islomov/rubai-corrector-base" \ --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": "islomov/rubai-corrector-base", "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 "islomov/rubai-corrector-base" \ --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": "islomov/rubai-corrector-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use islomov/rubai-corrector-base with Docker Model Runner:
docker model run hf.co/islomov/rubai-corrector-base
| #!/usr/bin/env python3 | |
| """Run example inference for rubai-corrector-base.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import torch | |
| from transformers import AutoModelForSeq2SeqLM, AutoTokenizer | |
| EXAMPLES = [ | |
| { | |
| "category": "abbreviation", | |
| "input": "telefon rqami qaysi", | |
| "expected": "Telefon raqami qaysi", | |
| }, | |
| { | |
| "category": "apostrophe", | |
| "input": "men ozim kordim", | |
| "expected": "Men o'zim ko'rdim", | |
| }, | |
| { | |
| "category": "apostrophe", | |
| "input": "togri yoldan boring", | |
| "expected": "To'g'ri yo'ldan boring", | |
| }, | |
| { | |
| "category": "ocr", | |
| "input": "rnen universitetda oqiyrnan", | |
| "expected": "Men universitetda o'qiyman", | |
| }, | |
| { | |
| "category": "ocr", | |
| "input": "bu juda rnuhirn masala", | |
| "expected": "Bu juda muhim masala", | |
| }, | |
| { | |
| "category": "numbers", | |
| "input": "narxi yigirma besh ming so'm", | |
| "expected": "Narxi 25 000 so'm", | |
| }, | |
| { | |
| "category": "numbers", | |
| "input": "uchrashuv o'n beshinchi yanvar kuni", | |
| "expected": "Uchrashuv 15-yanvar kuni", | |
| }, | |
| { | |
| "category": "mixed_uz_ru", | |
| "input": "men segodnya bozorga bordim", | |
| "expected": "Men сегодня bozorga bordim", | |
| }, | |
| { | |
| "category": "mixed_script", | |
| "input": "privet kak делa", | |
| "expected": "Привет как дела", | |
| }, | |
| { | |
| "category": "uzbek_cleanup", | |
| "input": "xamma narsa tayyor", | |
| "expected": "Hamma narsa tayyor", | |
| }, | |
| ] | |
| def parse_args() -> argparse.Namespace: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument( | |
| "--model-path", | |
| type=Path, | |
| default=Path(__file__).resolve().parent, | |
| help="Path to the packaged model folder.", | |
| ) | |
| parser.add_argument( | |
| "--device", | |
| default="cuda:0" if torch.cuda.is_available() else "cpu", | |
| help="Inference device, for example cuda:0 or cpu.", | |
| ) | |
| parser.add_argument( | |
| "--text", | |
| type=str, | |
| default=None, | |
| help="Run a single custom input instead of the built-in example suite.", | |
| ) | |
| parser.add_argument( | |
| "--max-new-tokens", | |
| type=int, | |
| default=256, | |
| help="Maximum generation length.", | |
| ) | |
| parser.add_argument( | |
| "--json", | |
| action="store_true", | |
| help="Print results as JSON.", | |
| ) | |
| return parser.parse_args() | |
| def load_model(model_path: Path, device: str): | |
| tokenizer = AutoTokenizer.from_pretrained(model_path) | |
| model = AutoModelForSeq2SeqLM.from_pretrained(model_path) | |
| model.to(device) | |
| model.eval() | |
| return tokenizer, model | |
| def predict(texts: list[str], tokenizer, model, device: str, max_new_tokens: int) -> list[str]: | |
| prompts = [f"correct: {text}" for text in texts] | |
| inputs = tokenizer(prompts, return_tensors="pt", padding=True) | |
| inputs = {name: tensor.to(device) for name, tensor in inputs.items()} | |
| with torch.inference_mode(): | |
| output_ids = model.generate(**inputs, max_new_tokens=max_new_tokens) | |
| return tokenizer.batch_decode(output_ids, skip_special_tokens=True) | |
| def main() -> int: | |
| args = parse_args() | |
| tokenizer, model = load_model(args.model_path, args.device) | |
| if args.text is not None: | |
| prediction = predict([args.text], tokenizer, model, args.device, args.max_new_tokens)[0] | |
| if args.json: | |
| print(json.dumps({"input": args.text, "prediction": prediction}, ensure_ascii=False, indent=2)) | |
| else: | |
| print(f"Input: {args.text}") | |
| print(f"Prediction: {prediction}") | |
| return 0 | |
| predictions = predict( | |
| [example["input"] for example in EXAMPLES], | |
| tokenizer, | |
| model, | |
| args.device, | |
| args.max_new_tokens, | |
| ) | |
| results = [] | |
| for example, prediction in zip(EXAMPLES, predictions): | |
| results.append( | |
| { | |
| "category": example["category"], | |
| "input": example["input"], | |
| "expected": example["expected"], | |
| "prediction": prediction, | |
| "exact_match": prediction == example["expected"], | |
| } | |
| ) | |
| if args.json: | |
| print(json.dumps(results, ensure_ascii=False, indent=2)) | |
| return 0 | |
| print(f"Model: {args.model_path}") | |
| print(f"Device: {args.device}") | |
| print() | |
| for row in results: | |
| print(f"[{row['category']}]") | |
| print(f"Input: {row['input']}") | |
| print(f"Expected: {row['expected']}") | |
| print(f"Prediction: {row['prediction']}") | |
| print(f"Exact: {row['exact_match']}") | |
| print() | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |