Code Monkey home page Code Monkey logo

grammarcorrection's Introduction

Grammar correction with neural network

Seq2Seq (Encoder-Decoder) wiht Attention Mechanism for Grammar Correction in Keras.

How its work

At first, we should create our parallel dataset for training our model. In preprocess folder, lang8 and nucle modules convert each dataset into proper format. Lang8 dataset is very noisy, so I decided to do small preprocessing on that. I remove non-ascii characters, reduce length of character with 3 or more with 1 (e.g token like !!!!!!! convert to !), and remove unnecessary punctuation (all puntuation except {',','.','-'}).

At the final preprocessing step, I do some data augmentation. In each pair (source, target), in addition to existing error, I inject some typo/grmmatical error into the source samples. Things I do in this step include:

  • Dropout token
  • Modal replacement
  • Misspelling tokens
  • Change tense of verbs
  • Change singularity/pluarality of nouns
  • Change preposition

Accourding to this paper, above cases will cover most of the errors in English learner writings.

In training step, I used famous seq2seq Attention model here. The best hyper-parameters for seq2seq explored by the team at google in "Massive Exploration of Neural Machine Translation Architectures" paper. I used one layer encoder/decoder to keep things as simple as posible. It can be easily extend to 4 layer encoder/decoder famework (considering regularization and dropout).

How to use

  • git clone https://github.com/hadifar/GrammarCorrection.git
  • cd GrammarCorrection
  • virtualenv venv
  • source venv/bin/activate
  • sudo pip2 install -r requirements.txt
  • mkdir data
  • cd data
  • Download lang8 and NUCLE and put them in data folder.
  • cd ..
  • cd preprocess
  • sh preprocess_script.sh
  • cd ..
  • cd models
  • donwnload fasttext pretrained embeddings and put it in data/embedding folder
  • sh train_script.sh
  • That's all :)

How to use in Colab

  • Look into the riminder.ipynb in the root directory. (do not forget to put the dataset in your google drive).

TODO:

  • Use character ngram feature
  • Use language model for checking final output

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.