Downloads · 30 days
92
8% of all-time downloads
CrabInHoney/t5-ru-text-normalization-v1
t5-ru-text-normalization-v1 is a text generation model from CrabInHoney. Use it when you need the model to write or continue text. The card lists the license as apache-2.0.
A T5-based neural network model for Russian text normalization that corrects spelling errors, fixes spacing issues, and normalizes text with various typing mistakes or noise.
Downloads · 30 days
92
8% of all-time downloads
All-time downloads
1.2K
Public
Parameters
59.8M
240 MB on disk
Likes
2
Public
Click a slice to open those files.
.safetensors239 MB · 100%
From the Hugging Face model README
A T5-based neural network model for Russian text normalization that corrects spelling errors, fixes spacing issues, and normalizes text with various typing mistakes or noise.
This model is built on the T5 architecture and is specifically trained to normalize Russian text by:
import torch
from transformers import T5Tokenizer, T5ForConditionalGeneration
def load_model_and_tokenizer(checkpoint_dir: str):
tokenizer = T5Tokenizer.from_pretrained(checkpoint_dir)
model = T5ForConditionalGeneration.from_pretrained(checkpoint_dir)
device = torch.device("cuda:0")
model = model.to(device)
return model, tokenizer, device
def test_model(model, tokenizer, device, test_text: str, max_length: int = 512):
inputs = tokenizer(
test_text,
return_tensors="pt",
padding=True,
truncation=True,
max_length=max_length
)
inputs = {k: v.to(device) for k, v in inputs.items()}
outputs = model.generate(
inputs["input_ids"],
max_length=max_length,
num_beams=4,
early_stopping=True
)
decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
return decoded_output
if __name__ == "__main__":
CHECKPOINT_DIR = "CrabInHoney/t5-ru-text-normalization-v1"
model, tokenizer, device = load_model_and_tokenizer(CHECKPOINT_DIR)
test_texts = [
"В ецлом, диакрит и4чежкие звнаки чАСто сеисп0оль зуются8даже ввв тттехме6стах,где онимо глибып,озво литьизбеждь пу4таницв.",
"Псле дожждя ул ца стаал сырй",
"Числао, показыыфчщее,насколькосильномооодель ошибаеиссянатех данных, на кофырых онаучитсяпрымосейчас.",
]
for test_text in test_texts:
result = test_model(model, tokenizer, device, test_text)
print(f"Input: {test_text}")
print(f"Outpt: {result}")
print("-" * 50)
Input: В ецлом, диакрит и4чежкие звнаки чАСто сеисп0оль зуются8даже ввв тттехме6стах,где онимо глибып,озво литьизбеждь пу4таницв.
Output: В целом, диакаритические знаки часто неиспользуются даже в тех местах, где они могли бы позволить избежать путаницы.
Input: Псле дожждя ул ца стаал сырй
Output: После дождя улица стала сырой.
Input: Числао, показыыфчщее,насколькосильномооодель ошибаеиссянатех данных, на кофырых онаучитсяпрымосейчас.
Output: Число, показывающее, насколько сильно модель ошибается на тех данных, на которых она учится прямо сейчас.