Parrot Paraphraser

repository·main·Indexed 21 days ago

https://github.com/prithivirajdamodaran/parrot_paraphraser

A paraphrase-based utterance augmentation framework designed to accelerate NLU model training. Parrot generates diverse paraphrases that preserve intents and slots, specifically optimized for conversational interfaces with a maximum length of 32 tokens. It includes a Parrot class with an .augment() method to control diversity, adequacy, and fluency thresholds.

Tokens
1.5K
Snippets
5
Records
7
Agent score
26%

What's inside parrot_paraphraser

  1. How Parrot works as an NLU augmentor

    main

    Parrot is designed to accelerate training for Natural Language Understanding (NLU) models. Unlike standard paraphrasers, a good NLU augmentor must preserve intents and slots/entities.

    In a typical NLU augmentation workflow:

    1. An input utterance with annotations (intents and slots) is provided.
    2. The augmentor generates $N$ paraphrases while attempting to preserve the original meaning and slot positions.
    3. The output paraphrases are converted back into annotated data (e.g., Rasa format) by mapping the original slots to the new text.

    Parrot is optimized for conversational interfaces, meaning it is trained on text samples with a maximum length of 32 tokens.

  2. Quickstart with Parrot

    main

    To use Parrot, initialize the Parrot class with a model_tag (e.g., prithivida/parrot_paraphraser_on_T5). Use the .augment() method to generate paraphrases for a given input phrase. Note that you should initialize the model only once in your application lifecycle.

    from parrot import Parrot
    import torch
    import warnings
    warnings.filterwarnings("ignore")
    
    # Init models (make sure you init ONLY once if you integrate this to your code)
    parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5")
    
    phrases = ["Can you recommend some upscale restaurants in Newyork?"]
    
    for phrase in phrases:
      print("Input_phrase: ", phrase)
      para_phrases = parrot.augment(input_phrase=phrase, use_gpu=False)
      for para_phrase in para_phrases:
       print(para_phrase)
  3. Install Parrot for AMD GPUs (ROCm)

    main

    If you are using an AMD GPU on Linux (tested on Ubuntu 22.04 with Radeon RX 6650 XT), you can install the project using the ROCm-specific requirements.

    Follow these steps:

    1. Clone the repository.
    2. Install dependencies from requirements-rocm.txt.

    To verify the installation, check if PyTorch can detect the GPU. If it returns False, you may need to set the HSA_OVERRIDE_GFX_VERSION environment variable to a compatible version (e.g., 10.3.0) to allow the ROCm driver to function correctly.

    git clone https://github.com/PrithivirajDamodaran/Parrot_Paraphraser.git
    cd Parrot_Paraphraser
    pip install -r requirements-rocm.txt
    
    # Verify installation
    python3 -c 'import torch; print(torch.cuda.is_available())'
    
    # If verification returns False, try:
    export HSA_OVERRIDE_GFX_VERSION=10.3.0
    python3 -c 'import torch; print(torch.cuda.is_available())'
  4. Known limitations of Parrot Paraphraser

    main

    When using Parrot, be aware of the following current limitations:

    • Diversity Scores: Diversity scores are not normalized; different diversity rankers score paraphrases differently.
    • Command Style Inputs: Some command-style input phrases may generate less adequate paraphrases.
  5. Configure paraphrase diversity and quality knobs

    main

    The .augment() method provides several parameters to control the quality and variety of the generated paraphrases:

    • input_phrase: The text to be paraphrased.
    • use_gpu: Boolean to enable/disable GPU acceleration.
    • do_diverse: Boolean. When True, it increases syntactic and phrasal diversity/variety in the output.
    • diversity_ranker: The method used to rank diversity (e.g., "levenshtein").
    • max_return_phrases: Integer. The maximum number of paraphrases to return.
    • max_length: Integer. The maximum length of the generated phrases.
    • adequacy_threshold: Float. Minimum threshold for meaning preservation.
    • fluency_threshold: Float. Minimum threshold for grammatical correctness.
    para_phrases = parrot.augment(input_phrase=phrase,
                                   use_gpu=False,
                                   diversity_ranker="levenshtein",
                                   do_diverse=False, 
                                   max_return_phrases = 10, 
                                   max_length=32, 
                                   adequacy_threshold = 0.99, 
                                   fluency_threshold = 0.90)