t5-ru-text-normalization-v1

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.

Description

This model is built on the T5 architecture and is specifically trained to normalize Russian text by:

  • Correcting spelling mistakes
  • Fixing spacing issues
  • Removing unwanted characters
  • Normalizing text with various typing errors

Usage

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)

Examples

Input: В ецлом, диакрит и4чежкие звнаки чАСто сеисп0оль зуются8даже ввв тттехме6стах,где онимо глибып,озво литьизбеждь пу4таницв.
Output: В целом, диакаритические знаки часто неиспользуются даже в тех местах, где они могли бы позволить избежать путаницы.

Input: Псле дожждя ул ца стаал сырй
Output: После дождя улица стала сырой.

Input: Числао, показыыфчщее,насколькосильномооодель ошибаеиссянатех данных, на кофырых онаучитсяпрымосейчас.
Output: Число, показывающее, насколько сильно модель ошибается на тех данных, на которых она учится прямо сейчас.

Downloads last month
22
Safetensors
Model size
59.8M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including CrabInHoney/t5-ru-text-normalization-v1