<jupyter_start><jupyter_text>Paraphrase generator<jupyter_code>from parrot import Parrot
import torch
import warnings
warnings.filterwarnings("ignore")<jupyter_output><empty_output><jupyter_text>Initialize Parrot class with the pretrained model "prithivida/parrot_paraphraser_on_T5" which is available in huggingface. Loading of model might take sometime to complete so please patience. If there are errors during initializing of model then please rerun the below cell.<jupyter_code>parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5")<jupyter_output><empty_output><jupyter_text>The below code snippet will iterate through the phrases and print parapharse sentences for each phrase<jupyter_code>def print_paraphrase_sentences(phrases,phrase_diversity=False):
    for phrase in phrases:
      print("-"*100)
      print("Input_phrase: ", phrase)
      print("-"*100)
      para_phrases = parrot.augment(input_phrase=phrase, use_gpu=False, do_diverse=phrase_diversity)
      for para_phrase in para_phrases:
       print(para_phrase)<jupyter_output><empty_output><jupyter_text>Provide list of phrases for which you would need paraphrase sentences<jupyter_code>phrases = ["What are the famous places we should not miss in Russia?","Can you recommed some upscale restaurants in Newyork?"]
print_paraphrase_sentences(phrases)<jupyter_output><empty_output><jupyter_text>Getting phrasal diversity/variety in paraphrases<jupyter_code>diversity_phrases = ["How are the new Macbook Pros with M1 chips?"]<jupyter_output><empty_output><jupyter_text>Without diversity flag set<jupyter_code>print_paraphrase_sentences(diversity_phrases)<jupyter_output><empty_output><jupyter_text>With diversity flag set<jupyter_code>phrase_diversity = True

print_paraphrase_sentences(diversity_phrases,phrase_diversity)<jupyter_output><empty_output><jupyter_text>Interactive shell simulation<jupyter_code>while True:
    usr_q = input("Enter a phrase (To quit enter exit): ")
    if usr_q == "exit":
        break
    else:
        if usr_q:
            phrase_d = input("Do you want phrasal diversity (y or n): ")
            phrases = [usr_q]
            if phrase_d and phrase_d.lower() == "y": 
                print_paraphrase_sentences(phrases,phrase_diversity=True)
            else:
                print_paraphrase_sentences(phrases)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07940552016985138, 'fraction_numerical': 0.003821656050955414, 'mean_word_length': 5.868804664723032, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '502707', 'license': 'Apache-2.0', 'n_tokens_mistral': 789, 'n_tokens_neox': 754, 'n_words': 168, 'path': 'paraphrase_generator.ipynb', 'repo_name': 'kandikits/Parrot_Paraphraser', 'size': '2355'}