Instructions to use ai-forever/sage-fredt5-large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ai-forever/sage-fredt5-large with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("ai-forever/sage-fredt5-large") model = AutoModelForSeq2SeqLM.from_pretrained("ai-forever/sage-fredt5-large", device_map="auto") - Notebooks
- Google Colab
- Kaggle
sage-fredt5-large
Summary
The model corrects spelling and punctuation errors and typos by bringing all the words in the text to the norm of the Russian language. Corrector had been trained based on the model FRED-T5-large. An extensive dataset with โartificialโ errors was taken as a training corpus: the corpus was assembled on the basis of the Russian-language Wikipedia and transcripts of Russian-language videos, then typos and spelling errors were automatically introduced into it using the library SAGE.
Public references
- SAGE library announcement, DataFest 2023
- Paper about synthetic error generation methods, Dialogue 2023
- SAGE EACL 2024 paper
Examples
| Input | Output |
|---|---|
| ะ ะฝะต ััะฝะพ ะฟัะพั ะพะถะธะผ ะฒ ััะพั ะดะตะฝั ะฝะตะฟะพะณะพะถะนะธ ะฟะพัะตะผั ั ะฒะตัะตะปัะน ัะฐะบะนะพ | ะ ะฝะต ััะฝะพ ะฟัะพั ะพะถะธะผ ะฒ ััะพั ะดะตะฝั ะฝะตะฟะพะณะพะถะธะน, ะฟะพัะตะผั ั ะฒะตัะตะปัะน ัะฐะบะพะน. |
| ะะฐะถะดะน ะดะตะฝั ะฒะพััะฐะบ ะดะตะปะพะน, ะธ ัะฟะตะฝะฐ ะฑะฐะปะตัั ะฝะธะฑัะดะตั. ะ ะฒะพัะฐะบ ะบะฐะถะดัะน ะดะตะฝั ะฝะธะดะตะปะฐะน | ะะฐะถะดัะน ะดะตะฝั ะฒะพั ัะฐะบ ะดะตะปะฐะน ะธ ัะฟะธะฝะฐ ะฑะพะปะตัั ะฝะต ะฑัะดะตั. ะ ะฒะพั ัะฐะบ ะบะฐะถะดัะน ะดะตะฝั ะฝะต ะดะตะปะฐะน. |
| ะัะฝะพะฒะฐั ัะตะปั ะผะตัะพะฟัะธััะธั ะฟัะฐะบัะธัะตัะบะฐั ะพััะฐะฑะพัะบะฐ ะฝะฐะฒัะบะพะฒ ะฟะพ ะพะบะฐะทะฐะฝะธั ะฟะพะผะพัะธ ะณัะฐะถะดะฐะฝะฐะผ, ะฟะพะฟะฐะฒัะธะผ ะฒ ะะขะ ะฐ ัะฐะบะถะต ะฟะพะฒััะตะฝะธะต ะธ ัะพะฒะตััะตะฝััะฒะพะฒะฐะฝะธะต ััะพะฒะฝั ะฟัะพัะตััะธะพะฝะฐะปัะฝะพะน ะฟะพะดะณะพัะพะฒะบะธ ัะพัััะดะฝะธะบะพะฒ ะะงะก ะฟัะธ ะฟัะพะฒะตะดะตะฝะธะธ ะฐะฒะฐัะธะนะฝะพ-ัะฟะฐัะฐัะตะปัะฝัั ัะฐะฑะพั ะฟะพ ะปะธะบะฒะธะดะฐัะธะธ ะฟะพัะปะตะดััะฒะธะน ะดะพัะพะถะฝะพ-ััะฐะฝัะฟะพััะฝัั ะฟัะพะธัะตััะฒะธะน ัะพะบัะฐัะตะฝะธะต ะฒัะตะผะตะฝะฝัั ะฟะพะบะฐะทะฐัะตะปะตะน ัะตะฐะณะธัะพะฒะฐะฝะธั. | ะัะฝะพะฒะฝะฐั ัะตะปั ะผะตัะพะฟัะธััะธั โ ะฟัะฐะบัะธัะตัะบะฐั ะพััะฐะฑะพัะบะฐ ะฝะฐะฒัะบะพะฒ ะฟะพ ะพะบะฐะทะฐะฝะธั ะฟะพะผะพัะธ ะณัะฐะถะดะฐะฝะฐะผ, ะฟะพะฟะฐะฒัะธะผ ะฒ ะะขะ, ะฐ ัะฐะบะถะต ะฟะพะฒััะตะฝะธะต ะธ ัะพะฒะตััะตะฝััะฒะพะฒะฐะฝะธะต ััะพะฒะฝั ะฟัะพัะตััะธะพะฝะฐะปัะฝะพะน ะฟะพะดะณะพัะพะฒะบะธ ัะพัััะดะฝะธะบะพะฒ ะะงะก ะฟัะธ ะฟัะพะฒะตะดะตะฝะธะธ ะฐะฒะฐัะธะนะฝะพ-ัะฟะฐัะฐัะตะปัะฝัั ัะฐะฑะพั ะฟะพ ะปะธะบะฒะธะดะฐัะธะธ ะฟะพัะปะตะดััะฒะธะน ะดะพัะพะถะฝะพ-ััะฐะฝัะฟะพััะฝัั ะฟัะพะธััะตััะฒะธะน, ัะพะบัะฐัะตะฝะธะต ะฒัะตะผะตะฝะฝัั ะฟะพะบะฐะทะฐัะตะปะตะน ัะตะฐะณะธัะพะฒะฐะฝะธั |
Metrics
Quality
Below are automatic metrics for determining the correctness of the spell checkers. We compare our solution with both open automatic spell checkers and the ChatGPT family of models on all four available datasets:
- RUSpellRU: texts collected from (LiveJournal), with manually corrected typos and errors;
- MultidomainGold: examples from 7 text sources, including the open web, news, social media, reviews, subtitles, policy documents and literary works;
- MedSpellChecker: texts with errors from medical anamnesis;
- GitHubTypoCorpusRu: spelling errors and typos in commits from GitHub;
RUSpellRU
| Model | Pr. (spell) | Rec. (spell) | F1 (spell) | Pr. (punc) | Rec. (punc) | F1 (punc) | Pr. (case) | Rec. (case) | F1 (case) |
|---|---|---|---|---|---|---|---|---|---|
| sage-fredt5-large | 57.3 | 68.0 | 62.2 | 86.7 | 46.1 | 60.2 | 92.1 | 67.8 | 78.1 |
| sage-fredt5-large (ft) | 88.4 | 80.9 | 84.5 | 88.2 | 85.3 | 86.8 | 95.5 | 94.0 | 94.7 |
| sage-ai-service | 90.3 | 86.3 | 88.2 | 90.3 | 86.6 | 88.4 | 95.2 | 95.9 | 95.6 |
| gpt-3.5-turbo | 33.6 | 58.5 | 42.7 | 85.9 | 64.6 | 73.7 | 84.9 | 73.9 | 79.0 |
| gpt-4 | 54.9 | 76.7 | 64.0 | 84.0 | 82.3 | 83.2 | 91.5 | 90.2 | 90.9 |
MultidomainGold
| Model | Pr. (spell) | Rec. (spell) | F1 (spell) | Pr. (punc) | Rec. (punc) | F1 (punc) | Pr. (case) | Rec. (case) | F1 (case) |
|---|---|---|---|---|---|---|---|---|---|
| sage-fredt5-large | 43.4 | 49.7 | 46.3 | 21.8 | 21.3 | 21.6 | 58.8 | 23.9 | 34.0 |
| sage-fredt5-large (ft) | 80.3 | 75.1 | 77.6 | 69.0 | 66.5 | 67.7 | 78.6 | 80.0 | 79.3 |
| sage-ai-service | 81.6 | 77.7 | 79.6 | 70.2 | 67.5 | 68.8 | 80.5 | 80.5 | 80.5 |
| gpt-3.5-turbo | 18.8 | 48.1 | 27.1 | 42.0 | 31.8 | 36.2 | 47.1 | 51.3 | 49.1 |
| gpt-4 | 25.4 | 68.0 | 37.0 | 57.8 | 54.3 | 56.0 | 54.0 | 67.5 | 60.0 |
MedSpellChecker
| Model | Pr. (spell) | Rec. (spell) | F1 (spell) | Pr. (punc) | Rec. (punc) | F1 (punc) | Pr. (case) | Rec. (case) | F1 (case) |
|---|---|---|---|---|---|---|---|---|---|
| sage-fredt5-large | 35.2 | 54.5 | 42.8 | 19.2 | 13.2 | 15.7 | 48.7 | 36.8 | 41.9 |
| sage-fredt5-large (ft) | 72.5 | 72.2 | 72.3 | 74.6 | 66.4 | 70.3 | 79.3 | 85.1 | 82.1 |
| sage-ai-service | 71.3 | 73.5 | 72.4 | 75.1 | 69.2 | 72.0 | 80.9 | 72.8 | 76.6 |
| gpt-3.5-turbo | 14.7 | 45.9 | 22.3 | 69.9 | 52.3 | 59.8 | 26.4 | 41.8 | 32.3 |
| gpt-4 | 37.8 | 72.3 | 49.6 | 81.4 | 64.3 | 71.9 | 73.0 | 62.1 | 67.1 |
GitHubTypoCorpusRu
| Model | Pr. (spell) | Rec. (spell) | F1 (spell) | Pr. (punc) | Rec. (punc) | F1 (punc) | Pr. (case) | Rec. (case) | F1 (case) |
|---|---|---|---|---|---|---|---|---|---|
| sage-fredt5-large | 46.0 | 46.6 | 46.3 | 22.7 | 18.3 | 20.2 | 12.0 | 13.2 | 12.6 |
| sage-fredt5-large (ft) | 67.5 | 53.2 | 59.5 | 48.5 | 38.0 | 42.6 | 37.3 | 50.0 | 42.7 |
| sage-ai-service | 70.8 | 56.3 | 62.7 | 48.9 | 35.8 | 41.4 | 32.9 | 45.3 | 38.1 |
| gpt-3.5-turbo | 23.7 | 38.7 | 29.4 | 37.6 | 23.3 | 28.7 | 19.6 | 35.9 | 25.3 |
| gpt-4 | 27.0 | 52.8 | 35.7 | 45.9 | 32.6 | 38.2 | 25.7 | 36.8 | 30.2 |
How to use
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("ai-forever/sage-fredt5-large")
model = AutoModelForSeq2SeqLM.from_pretrained("ai-forever/sage-fredt5-large", device_map='cuda')
sentence = "ะ ะฝะต ััะฝะพ ะฟัะพั
ะพะถะธะผ ะฒ ััะพั ะดะตะฝั ะฝะตะฟะพะณะพะถะนะธ ะฟะพัะตะผั ั ะฒะตัะตะปัะน ัะฐะบะนะพ"
inputs = tokenizer(sentence, max_length=None, padding="longest", truncation=False, return_tensors="pt")
outputs = model.generate(**inputs.to(model.device), max_length = inputs["input_ids"].size(1) * 1.5)
print(tokenizer.batch_decode(outputs, skip_special_tokens=True))
# ["ะ ะฝะต ััะฝะพ ะฟัะพั
ะพะถะธะผ ะฒ ััะพั ะดะตะฝั ะฝะตะฟะพะณะพะถะธะน, ะฟะพัะตะผั ั ะฒะตััะปัะน ัะฐะบะพะน?"]
Limitations
- The model is intended to be fine-tuned on sets with natural errors for better performance. The realized model is a pre-train and pre-train task is different from the usual spell checking in terms of density of the noise in a corpus and its origin;
- Complex formatting may cause some trouble in output generation.
Resources
- SAGE library, GitHub
- sage-fredt5-large, HuggingFace
- sage-fredt5-distilled-95m, HuggingFace
- sage-m2m100-1.2B, HuggingFace
- sage-mt5-large, HuggingFace
License
Model FRED-T5-large, on the basis of which our solution is made, and its source code are supplied under the MIT license. Our solution comes with MIT license also.
Specifications
- File size: 3.3 Gb;
- Framework: pytorch
- Version: v1.0
- Developer: SberDevices, AGI NLP
Contacts
- Downloads last month
- 1,057
Collection including ai-forever/sage-fredt5-large
Evaluation results
- F1 (spell) on RUSpellRU (spell&punct)self-reported62.200
- F1 (punct) on RUSpellRU (spell&punct)self-reported60.200
- F1 (case) on RUSpellRU (spell&punct)self-reported78.100
- F1 (spell) on MultidomainGold (spell&punct)self-reported46.300
- F1 (punct) on MultidomainGold (spell&punct)self-reported21.600
- F1 (case) on MultidomainGold (spell&punct)self-reported34.000
- F1 (spell) on MedSpellchecker (spell&punct)self-reported42.700
- F1 (punct) on MedSpellchecker (spell&punct)self-reported15.700
