Day 64 – Correct Grammatical Errors Using Gramformer AI With Source Code – Part II

Image Source: Gramformer

We have seen in Part I – What are Gramformer and its use?

Today, we will see the sample code how it corrects grammatical errors for given words/sentences.

I am using Google Colab to test Gramformer’s standard code.

Copy to Clipboard
Collecting git+https://github.com/PrithivirajDamodaran/Gramformer.git
  Cloning https://github.com/PrithivirajDamodaran/Gramformer.git to /tmp/pip-req-build-kd6oj35h
  Running command git clone -q https://github.com/PrithivirajDamodaran/Gramformer.git 
/tmp/pip-req-build-kd6oj35h
Collecting transformers
  Downloading https://files.pythonhosted.org/packages/00/92/
6153f4912b84ee1ab53ab45663d23e7cf3704161cb5ef18b0c07e207cef2/transformers-4.7.0-py3-none-any.whl (2.5MB)
     |████████████████████████████████| 2.5MB 4.2MB/s 
Collecting sentencepiece
  Downloading https://files.pythonhosted.org/packages/ac/
aa/1437691b0c7c83086ebb79ce2da16e00bef024f24fec2a5161c35476f499/
sentencepiece-0.1.96-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2MB)
     |████████████████████████████████| 1.2MB 37.6MB/s 
Collecting python-Levenshtein
  Downloading https://files.pythonhosted.org/packages/2a/dc/
97f2b63ef0fa1fd78dcb7195aca577804f6b2b51e712516cc0e902a9a201/python-Levenshtein-0.12.2.tar.gz (50kB)
     |████████████████████████████████| 51kB 5.8MB/s 
Collecting fuzzywuzzy
  Downloading https://files.pythonhosted.org/packages/43/ff/
74f23998ad2f93b945c0309f825be92e04e0348e062026998b5eefef4c33/fuzzywuzzy-0.18.0-py2.py3-none-any.whl
Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages 
(from transformers->gramformer==0.1) (2.23.0)
Requirement already satisfied: importlib-metadata; python_version < "3.8" in 
/usr/local/lib/python3.7/dist-packages (from transformers->gramformer==0.1) (4.5.0)
Collecting sacremoses
  Downloading https://files.pythonhosted.org/packages/75/
ee/67241dc87f266093c533a2d4d3d69438e57d7a90abb216fa076e7d475d4a/sacremoses-0.0.45-py3-none-any.whl (895kB)
     |████████████████████████████████| 901kB 36.2MB/s 
Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.7/dist-packages 
(from transformers->gramformer==0.1) (1.19.5)
Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.7/dist-packages 
(from transformers->gramformer==0.1) (2019.12.20)
Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages 
(from transformers->gramformer==0.1) (20.9)
Requirement already satisfied: pyyaml in /usr/local/lib/python3.7/dist-packages 
(from transformers->gramformer==0.1) (3.13)
Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.7/dist-packages 
(from transformers->gramformer==0.1) (4.41.1)
Collecting huggingface-hub==0.0.8
  Downloading https://files.pythonhosted.org/packages/a1/88/
7b1e45720ecf59c6c6737ff332f41c955963090a18e72acbcbeac6b25e86/huggingface_hub-0.0.8-py3-none-any.whl
Requirement already satisfied: filelock in /usr/local/lib/python3.7/dist-packages 
(from transformers->gramformer==0.1) (3.0.12)
Collecting tokenizers<0.11,>=0.10.1
  Downloading https://files.pythonhosted.org/packages/d4/e2/
df3543e8ffdab68f5acc73f613de9c2b155ac47f162e725dcac87c521c11/
tokenizers-0.10.3-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.
manylinux_2_12_x86_64.manylinux2010_x86_64.whl (3.3MB)
     |████████████████████████████████| 3.3MB 37.2MB/s 
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages 
(from python-Levenshtein->gramformer==0.1) (57.0.0)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in 
/usr/local/lib/python3.7/dist-packages (from requests->transformers->gramformer==0.1) (1.24.3)
Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages 
(from requests->transformers->gramformer==0.1) (2.10)
Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages 
(from requests->transformers->gramformer==0.1) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages 
(from requests->transformers->gramformer==0.1) (2021.5.30)
Requirement already satisfied: typing-extensions>=3.6.4; python_version < "3.8" in
 /usr/local/lib/python3.7/dist-packages (from importlib-metadata; python_version 
< "3.8"->transformers->gramformer==0.1) (3.7.4.3)
Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages
 (from importlib-metadata; python_version < "3.8"->transformers->gramformer==0.1) (3.4.1)
Requirement already satisfied: joblib in /usr/local/lib/python3.7/dist-packages
 (from sacremoses->transformers->gramformer==0.1) (1.0.1)
Requirement already satisfied: click in /usr/local/lib/python3.7/dist-packages 
(from sacremoses->transformers->gramformer==0.1) (7.1.2)
Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages 
(from sacremoses->transformers->gramformer==0.1) (1.15.0)
Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/lib/python3.7/dist-packages
 (from packaging->transformers->gramformer==0.1) (2.4.7)
Building wheels for collected packages: gramformer, python-Levenshtein
  Building wheel for gramformer (setup.py) ... done
  Created wheel for gramformer: filename=gramformer-0.1-cp37-none-any.whl size=6973 
sha256=cc8ba01f1be00e5d17d45572a78df0597010af1ce67a383ad0bc9a8964c6b476
  Stored in directory: /tmp/pip-ephem-wheel-cache-k4jfy6h1/
wheels/b8/35/c2/5479786d648505c55c84349e47553e2f6f1e51032d6f534b8b
  Building wheel for python-Levenshtein (setup.py) ... done
  Created wheel for python-Levenshtein: 
filename=python_Levenshtein-0.12.2-cp37-cp37m-linux_x86_64.whl size=149810 
sha256=608363fe2c9e1560044d8ac21610fc526ec6bf429a497a0bf6f97220210b671b
  Stored in directory: /root/.cache/pip/wheels/b3/26/73/4b48503bac73f01cf18e52cd250947049a7f339e940c5df8fc
Successfully built gramformer python-Levenshtein
Installing collected packages: sacremoses, huggingface-hub, tokenizers, 
transformers, sentencepiece, python-Levenshtein, fuzzywuzzy, gramformer
Successfully installed fuzzywuzzy-0.18.0 gramformer-0.1 huggingface-hub-0.0.8 
python-Levenshtein-0.12.2 sacremoses-0.0.45 sentencepiece-0.1.96 tokenizers-0.10.3 transformers-4.7.0
Copy to Clipboard
Copy to Clipboard
Gramformer Downloading
Output:
[Gramformer] Grammar error correction model loaded..
[Input]  What s yur name?
[Correction]  What's your name?
---------------------------------------------------------------------------
[Input]  Gopi Chandrakesan ride bike.
[Correction]  Gopi Chandrakesan riding his bike.
---------------------------------------------------------------------------
[Input]  We watch phantom movie.
[Correction]  We watched a phantom movie.
---------------------------------------------------------------------------
[Input]  My friend and I is going to shopping mall.
[Correction]  My friend and I are going to a shopping mall.
---------------------------------------------------------------------------
[Input]  Who is you?
[Correction]  Who are you?
---------------------------------------------------------------------------
[Input]  Where are he eating?
[Correction]  Where is he eating?
---------------------------------------------------------------------------
[Input]  Sunflower are nice flower.
[Correction]  Sunflowers are nice flowers.
---------------------------------------------------------------------------

To download full Gramformer library from GitHub, click here.

By |2021-06-23T19:59:21+00:00June 21st, 2021|Artificial Intelligence|0 Comments

About the Author:

Leave A Comment