File size: 1,626 Bytes
b74c8d6
 
 
 
 
8f7e0df
43be54a
 
 
 
 
 
 
 
 
 
 
 
 
8f7e0df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
datasets:
- liweili/c4_200m
language:
- en
---
# English Grammar Error Correction with T5

## Overview
This repository contains a pretrained T5 model fine-tuned for English grammar error correction using Hugging Face's Transformers library. The model leverages a seq2seq architecture and was trained on the C4 dataset for grammar correction purposes.

## Model Details

- Model Name: english-grammar-error-correction-t5-seq2seq
- Tokenizer: T5Tokenizer
- Model Architecture: T5ForConditionalGeneration
- Training Data: Fine-tuned on C4 dataset for grammar error correction tasks.

## Usage

```python
# Load model directly
import torch
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

torch_device = 'cuda' if torch.cuda.is_available() else 'cpu'

tokenizer = AutoTokenizer.from_pretrained("thenHung/english-grammar-error-correction-t5-seq2seq")
model = AutoModelForSeq2SeqLM.from_pretrained("thenHung/english-grammar-error-correction-t5-seq2seq").to(torch_device)


def correct_grammar(input_text,num_return_sequences):
  batch = tokenizer([input_text],truncation=True,padding='max_length',max_length=64, return_tensors="pt").to(torch_device)
  translated = model.generate(**batch,max_length=64,num_beams=4, num_return_sequences=num_return_sequences, temperature=1.5)
  tgt_text = tokenizer.batch_decode(translated, skip_special_tokens=True)
  return tgt_text

input_text = """
He are an teachers.
"""
num_return_sequences = 3
corrected_texts = correct_grammar(input_text, num_return_sequences)
print(corrected_texts)

# output:
# ['He is a teacher.', 'He is an educator.', 'He is one of the teachers.']
```