### Install Gramformer Python Library Source: https://github.com/prithivirajdamodaran/gramformer/blob/main/README.md This command installs the Gramformer library directly from its GitHub repository using pip. The '-U' flag ensures that any existing installation is upgraded to the latest version available in the repository. ```python pip install -U git+https://github.com/PrithivirajDamodaran/Gramformer.git ``` -------------------------------- ### Correcting Grammar with Gramformer in Python Source: https://github.com/prithivirajdamodaran/gramformer/blob/main/README.md This Python snippet demonstrates how to initialize the Gramformer model for grammar correction and apply it to a list of influent sentences. It shows how to set a random seed for reproducibility and iterate through sentences to get corrected versions. The model is initialized with `models = 1` for the corrector and `use_gpu=False` for CPU-only operation. The output of this code would be a side-by-side comparison of input and corrected sentences. ```python from gramformer import Gramformer import torch def set_seed(seed): torch.manual_seed(seed) if torch.cuda.is_available(): torch.cuda.manual_seed_all(seed) set_seed(1212) gf = Gramformer(models = 1, use_gpu=False) # 1=corrector, 2=detector influent_sentences = [ "He are moving here.", "I am doing fine. How is you?", "How is they?", "Matt like fish", "the collection of letters was original used by the ancient Romans", "We enjoys horror movies", "Anna and Mike is going skiing", "I walk to the store and I bought milk", " We all eat the fish and then made dessert", "I will eat fish for dinner and drink milk", "what be the reason for everyone leave the company", ] for influent_sentence in influent_sentences: corrected_sentences = gf.correct(influent_sentence, max_candidates=1) print("[Input] ", influent_sentence) for corrected_sentence in corrected_sentences: print("[Correction] ",corrected_sentence) print("-" *100) ``` -------------------------------- ### Get Detailed Grammar Edits using Gramformer in Python Source: https://github.com/prithivirajdamodaran/gramformer/blob/main/README.md This snippet demonstrates how to initialize the Gramformer library for correction and use its `get_edits` method. After correcting an influent sentence with `gf.correct`, `get_edits` provides a list of tuples, each detailing a specific correction (e.g., error type, original word, position, corrected word). ```python from gramformer import Gramformer set_seed(1212) gf = Gramformer(models = 1, use_gpu=False) # 1=corrector, 2=detector influent_sentences = [ "He are moving here.", "the collection of letters was original used by the ancient Romans", "We enjoys horror movies", "Anna and Mike is going skiing", "I will eat fish for dinner and drank milk", "what be the reason for everyone leave the comapny" ] for influent_sentence in influent_sentences: corrected_sentences = gf.correct(influent_sentence, max_candidates=1) print("[Input] ", influent_sentence) for corrected_sentence in corrected_sentences: print("[Edits] ", gf.get_edits(influent_sentence, corrected_sentence)) print("-" *100) ``` ```text [Input] He are moving here. [Edits] [('VERB:SVA', 'are', 1, 2, 'is', 1, 2)] ---------------------------------------------------------------------------------------------------- [Input] the collection of letters was original used by the ancient Romans [Edits] [('MORPH', 'original', 5, 6, 'originally', 5, 6)] ---------------------------------------------------------------------------------------------------- [Input] We enjoys horror movies [Edits] [('VERB:SVA', 'enjoys', 1, 2, 'enjoy', 1, 2), ('NOUN', 'movies', 3, 4, 'movies.', 3, 4)] ---------------------------------------------------------------------------------------------------- [Input] Anna and Mike is going skiing [Edits] [('VERB:SVA', 'is', 3, 4, 'are', 3, 4), ('OTHER', 'skiing', 5, 6, 'skiing!', 5, 6)] ---------------------------------------------------------------------------------------------------- [Input] I will eat fish for dinner and drank milk [Edits] [('VERB:TENSE', 'will eat', 1, 3, 'ate', 1, 2), ('MORPH', 'drank', 7, 8, 'drink', 6, 7), ('NOUN', 'milk', 8, 9, 'milk.', 7, 8)] ---------------------------------------------------------------------------------------------------- [Input] what be the reason for everyone leave the comapny [Edits] [('ORTH', 'what', 0, 1, 'What', 0, 1), ('VERB:TENSE', 'be', 1, 2, 'was', 1, 2), ('VERB:FORM', 'leave', 6, 7, 'leaving', 6, 7), ('SPELL', 'comapny', 8, 9, 'company?', 8, 9)] ---------------------------------------------------------------------------------------------------- ``` -------------------------------- ### Initialize Gramformer Detector Source: https://github.com/prithivirajdamodaran/gramformer/blob/main/README.md Initializes the Gramformer library for grammar detection. It sets up the model type (detector) and specifies whether to use GPU. The `detect` method then processes an input sentence to return a grammar fluency score. ```python from gramformer import Gramformer gf = Gramformer(models = 2, use_gpu=False) # 1=corrector, 2=detector grammar_fluency_score = gf.detect() ``` -------------------------------- ### Gramformer Available Models Source: https://github.com/prithivirajdamodaran/gramformer/blob/main/README.md Lists the different models available within Gramformer, detailing their type, return values, and current status. ```APIDOC Model: prithivida/grammar_error_detector Type: Classifier Return: Label Status: WIP (Reuse prithivida/parrot_fluency_on_BERT ? but I would'd say you wait :-)) Model: prithivida/grammar_error_highlighter Type: Seq2Seq Return: Grammar errors enclosed in and Status: WIP Model: prithivida/grammar_error_correcter Type: Seq2Seq Return: The corrected sentence Status: Beta / Pre-release (Not available anymore) Model: prithivida/grammar_error_correcter_v1 Type: Seq2Seq Return: The corrected sentence Status: Stable ``` -------------------------------- ### Highlight Grammar Corrections using Gramformer in Python Source: https://github.com/prithivirajdamodaran/gramformer/blob/main/README.md This snippet illustrates how to use the Gramformer library to correct sentences and then apply the `highlight` method. The `highlight` method generates an HTML-like string that visually marks the corrected parts within the original sentence, indicating the type of error and the suggested correction. ```python from gramformer import Gramformer set_seed(1212) gf = Gramformer(models = 1, use_gpu=False) # 1=corrector, 2=detector influent_sentences = [ "He are moving here.", "the collection of letters was original used by the ancient Romans", "We enjoys horror movies", "Anna and Mike is going skiing", "I will eat fish for dinner and drank milk", "what be the reason for everyone leave the comapny" ] for influent_sentence in influent_sentences: corrected_sentences = gf.correct(influent_sentence, max_candidates=1) print("[Input] ", influent_sentence) for corrected_sentence in corrected_sentences: print("[Edits] ", gf.highlight(influent_sentence, corrected_sentence)) print("-" *100) ``` ```text [Input] He are moving here. [Edits] He are moving here. ---------------------------------------------------------------------------------------------------- [Input] the collection of letters was original used by the ancient Romans [Edits] the collection of letters was original used by the ancient Romans ---------------------------------------------------------------------------------------------------- [Input] We enjoys horror movies [Edits] We enjoys horror movies ---------------------------------------------------------------------------------------------------- [Input] Anna and Mike is going skiing [Edits] Anna and Mike is going skiing ---------------------------------------------------------------------------------------------------- [Input] I will eat fish for dinner and drank milk [Edits] I will eat fish for dinner and drank milk ---------------------------------------------------------------------------------------------------- [Input] what be the reason for everyone leave the comapny [Edits] what be the reason for everyone leave the comapny ---------------------------------------------------------------------------------------------------- ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.