Update README.md
Browse files
README.md
CHANGED
@@ -91,6 +91,26 @@ These substitutions represent phonetic similarities and common mistakes made by
|
|
91 |
|
92 |
To use the model for spell correction:
|
93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
## License
|
96 |
|
|
|
91 |
|
92 |
To use the model for spell correction:
|
93 |
|
94 |
+
```python
|
95 |
+
import torch
|
96 |
+
from transformers import MT5ForConditionalGeneration, MT5Tokenizer
|
97 |
+
|
98 |
+
# Load the tokenizer and model
|
99 |
+
tokenizer = MT5Tokenizer.from_pretrained('LocalDoc/azerbaijani_spell_corrector')
|
100 |
+
model = MT5ForConditionalGeneration.from_pretrained('LocalDoc/azerbaijani_spell_corrector')
|
101 |
+
|
102 |
+
# Function to correct sentences
|
103 |
+
def correct_sentence(sentence):
|
104 |
+
input_text = "correct: " + sentence
|
105 |
+
input_ids = tokenizer.encode(input_text, return_tensors='pt', max_length=128, truncation=True)
|
106 |
+
outputs = model.generate(input_ids=input_ids, max_length=128, num_beams=5, early_stopping=True)
|
107 |
+
corrected_sentence = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
108 |
+
return corrected_sentence
|
109 |
+
|
110 |
+
# Example usage
|
111 |
+
incorrect_sentence = "Pul dogru adamlarda deyil"
|
112 |
+
print(correct_sentence(incorrect_sentence))
|
113 |
+
```
|
114 |
|
115 |
## License
|
116 |
|