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
defload_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
deftest_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:
Число, показывающее, насколько сильно модель ошибается на тех данных, на которых она учится прямо сейчас.
Runs of CrabInHoney t5-ru-text-normalization-v1 on huggingface.co
79
Total runs
2
24-hour runs
0
3-day runs
4
7-day runs
41
30-day runs
More Information About t5-ru-text-normalization-v1 huggingface.co Model
More t5-ru-text-normalization-v1 license Visit here:
t5-ru-text-normalization-v1 huggingface.co is an AI model on huggingface.co that provides t5-ru-text-normalization-v1's model effect (), which can be used instantly with this CrabInHoney t5-ru-text-normalization-v1 model. huggingface.co supports a free trial of the t5-ru-text-normalization-v1 model, and also provides paid use of the t5-ru-text-normalization-v1. Support call t5-ru-text-normalization-v1 model through api, including Node.js, Python, http.
t5-ru-text-normalization-v1 huggingface.co is an online trial and call api platform, which integrates t5-ru-text-normalization-v1's modeling effects, including api services, and provides a free online trial of t5-ru-text-normalization-v1, you can try t5-ru-text-normalization-v1 online for free by clicking the link below.
CrabInHoney t5-ru-text-normalization-v1 online free url in huggingface.co:
t5-ru-text-normalization-v1 is an open source model from GitHub that offers a free installation service, and any user can find t5-ru-text-normalization-v1 on GitHub to install. At the same time, huggingface.co provides the effect of t5-ru-text-normalization-v1 install, users can directly use t5-ru-text-normalization-v1 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
t5-ru-text-normalization-v1 install url in huggingface.co: