Views
No views yet
| # | precision | recall | f1-score | support |
|---|---|---|---|---|
| TYPO | 0.992332 | 0.985997 | 0.989154 | 416054.0 |
| micro avg | 0.992332 | 0.985997 | 0.989154 | 416054.0 |
| macro avg | 0.992332 | 0.985997 | 0.989154 | 416054.0 |
| weighted avg | 0.992332 | 0.985997 | 0.989154 | 416054.0 |
pip install transformers1import torch
2from transformers import AutoConfig, AutoTokenizer, AutoModelForTokenClassification
3from transformers import pipeline
4
5
6model_name_or_path = "m3hrdadfi/typo-detector-distilbert-en"
7config = AutoConfig.from_pretrained(model_name_or_path)
8tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
9model = AutoModelForTokenClassification.from_pretrained(model_name_or_path, config=config)
10nlp = pipeline('token-classification', model=model, tokenizer=tokenizer, aggregation_strategy="average")1sentences = [
2 "He had also stgruggled with addiction during his time in Congress .",
3 "The review thoroughla assessed all aspects of JLENS SuR and CPG esign maturit and confidence .",
4 "Letterma also apologized two his staff for the satyation .",
5 "Vincent Jay had earlier won France 's first gold in gthe 10km biathlon sprint .",
6 "It is left to the directors to figure out hpw to bring the stry across to tye audience .",
7]
8
9for sentence in sentences:
10 typos = [sentence[r["start"]: r["end"]] for r in nlp(sentence)]
11
12 detected = sentence
13 for typo in typos:
14 detected = detected.replace(typo, f'<i>{typo}</i>')
15
16 print(" [Input]: ", sentence)
17 print("[Detected]: ", detected)
18 print("-" * 130)1 [Input]: He had also stgruggled with addiction during his time in Congress .
2[Detected]: He had also <i>stgruggled</i> with addiction during his time in Congress .
3----------------------------------------------------------------------------------------------------------------------------------
4 [Input]: The review thoroughla assessed all aspects of JLENS SuR and CPG esign maturit and confidence .
5[Detected]: The review <i>thoroughla</i> assessed all aspects of JLENS SuR and CPG <i>esign</i> <i>maturit</i> and confidence .
6----------------------------------------------------------------------------------------------------------------------------------
7 [Input]: Letterma also apologized two his staff for the satyation .
8[Detected]: <i>Letterma</i> also apologized <i>two</i> his staff for the <i>satyation</i> .
9----------------------------------------------------------------------------------------------------------------------------------
10 [Input]: Vincent Jay had earlier won France 's first gold in gthe 10km biathlon sprint .
11[Detected]: Vincent Jay had earlier won France 's first gold in <i>gthe</i> 10km biathlon sprint .
12----------------------------------------------------------------------------------------------------------------------------------
13 [Input]: It is left to the directors to figure out hpw to bring the stry across to tye audience .
14[Detected]: It is left to the directors to figure out <i>hpw</i> to bring the <i>stry</i> across to <i>tye</i> audience .
15----------------------------------------------------------------------------------------------------------------------------------