File size: 1,099 Bytes
54babba
01e6349
 
 
 
b803244
54babba
01e6349
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
---
language: en
license: mit
tags:
- GECToR_gotutiyan
- grammatical error correction
---

# gector sample
This is an unofficial pretrained model of GECToR ([Omelianchuk+ 2020](https://aclanthology.org/2020.bea-1.16/)).

### How to use
The code is avaliable from https://github.com/gotutiyan/gector.

CLI
```sh
python predict.py --input <raw text file>     --restore_dir gotutiyan/gector-bert-base-cased-5k     --out <path to output file>
```

API
```py
from transformers import AutoTokenizer
from gector.modeling import GECToR
from gector.predict import predict, load_verb_dict
import torch

model_id = 'gotutiyan/gector-bert-base-cased-5k'
model = GECToR.from_pretrained(model_id)
if torch.cuda.is_available():
    model.cuda()
tokenizer = AutoTokenizer.from_pretrained(model_id)
encode, decode = load_verb_dict('data/verb-form-vocab.txt')
srcs = [
    'This is a correct sentence.',
    'This are a wrong sentences'
]
corrected = predict(
    model, tokenizer, srcs,
    encode, decode,
    keep_confidence=0.0,
    min_error_prob=0.0,
    n_iteration=5,
    batch_size=2,
)
print(corrected)
```