Skip to content

xspin/DLGrammarCorrection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DLGrammarCorrection

A deep learning model for English grammar correction

Six error types:

  • preposition
  • noun
  • article
  • verb
  • predicate
  • punctuation

Requirements

  • Python 3.x
  • nltk
  • TensorFlow
  • numpy

See also: https://github.com/xspin/deep-text-corrector


训练模型:

python3 train.py

使用模型:

python3 test.py

模型要求

纠正英文句子中的6种错误

  • 介词错误
  • 名词错误
  • 冠词错误
  • 动词错误
  • 谓语错误
  • 标点错误

运行环境

  • Python 3.6
  • TensorFlow 1.10
  • NLTK 3.3
  • NumPy 1.13

模型及参数

主要思想是 sequence-to-sequence + attention mechanism,细节可参见 Bahdanau et al., 2014

encoder 和 decoder 的 RNN 每层大小和层数: 512, 4

RNN 单元:LSTM

最大单词(token)数(词典大小):2000

因使用了一种处理OOV词(词典外的词)的策略,可以使用较小的词典,可参见 Addressing the Rare Word Problem in NMT

数据集

数据处理

基本思想是对正确的句子加入随机“噪声”来得到训练数据,分别针对下面不同情况进行处理

  • 介词、冠词、谓语、标点:将其随机替换成其他相应的词或去掉
  • 动词:随机改变时态

错误标记

对原句子和纠正后的句子分别用NLTK标记各单词的词性,然后贪心地找出不同的(被纠正的)词,最后根据其词性确定错误的类型。

代码结构

  • corrector/corrector.py 定义了Corrector 类,封装了训练和对句子进行纠正的函数,调用方法可参考 train.py 和 test.py
  • corrector/data_reader.py, text_corrector_data_readers.py 实现了对各数据集的读取和处理
  • corrector/text_corrector_models.py 实现seq2seq模型
  • corrector/seq2seq.py 旧版本tf中的seq2seq包
  • corrector/noise.py 提供了对文本添加噪声的函数

参考资料

About

A deep learning model for English grammar correction

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages