For example, we can assign a paragraph consisting of a couple of phrases to an input variable, which is then used by the code to generate paraphrased text. This code block generates the following output:Ĭreate a Colab/Jupyter notebook that expands on this example (which generates paraphrased text for a single input phrase) by making a version that can take in multiple phrases as input. Perform a nested for loop on the para_phrases variable: - Print the returned output of the paraphrases from the para_phrases variable that have been generated iteratively (the 4 paraphrased text that we will soon see in the next section).Generated paraphrases are assigned to the para_phrases variable. Perform the paraphrasing using the gment() function that takes in as input argument the phrase being iterated.Print "Input phrase: " followed by the returned output of the phrase that is being iterated.Print out the - character for 100 times.Here, we’ll be using a for loop to iterate through all the sentences in the phrases variable (in the example above we assigned only a single sentence or a single phrase to this variable). for phrase in phrases: print("-"*100) print("Input_phrase: ", phrase) print("-"*100) para_phrases = gment(input_phrase=phrase) for para_phrase in para_phrases: print(para_phrase) 7.2. The CodeĮnter the following code block into the code cell and run the cell. Now, to the fun part of generating the paraphrased text using the PARROT T5 model. To find out the answer to that make sure to watch the accompanying YouTube video ( How to paraphrase text in Python using the PARROT library (Ft. The input text for this example, which is What’s the most delicious papayas?, will be assigned to the phrases variable, which we will be using in just a moment. The models will be loaded as shown below: parrot = Parrot(model_tag="prithivida/parrot_paraphraser_on_T5", use_gpu=False) We will now load and initialize the PARROT model by entering the following into a code cell and run the cell. To set the random seed number for reproducibility, enter the following code block into the code cell: def random_state(seed): torch.manual_seed(seed) if _available(): _seed_all(seed) random_state(1234) 5. What this does is produce the same results for the same seed number (even if it is re-run multiple times). In order to allow reproducibility of the text paraphrasing, the random seed number will be set. It should be noted that Hugging Face is the company that develops the transformer library which hosts the parrot_paraphraser_on_T5 model.Īs the code implies, warnings that appears will be ignored via the warnings library. This model is called parrot_paraphraser_on_T5 and is listed on the Hugging Face website. Under the hood, the pre-trained text paraphrasing model was created using PyTorch ( torch) and thus we’re importing it here in order to run the model. The parrot library contains the pre-trained text paraphrasing model that we will use to perform the paraphrasing task. Screenshot of the play button that allows the code cell to be run. Ken Jee)) to this article is shown below. It should be noted that an accompanying YouTube video ( How to paraphrase text in Python using the PARROT library (Ft. At a high-level, text generation is niche area of the exciting area of natural language processing (NLP), which is generally referred to as artificial intelligence or AI when explained to the general audience. Particularly, under the hood PARROT’s paraphrasing technology is based on the T5 algorithm (an acronym for Text-To-Text Transfer Transformer) that was originally developed by Google (for more information refer to the T5 resource at Papers with Code). In this article, you will learn how to paraphrase text for FREE in Python using the PARROT library. Wouldn’t it be great if we could paraphrase text automatically? Paraphrasing content is also another great way to take existing content (either from your own or from others) and add your own spin to it. Perhaps this could help end writer’s block? This is a debatable question that is best saved for a later time. Text generation tools can help to rapidly generate original contents by just giving the AI a few keyword ideas to work with. Tools such as Grammarly can help with language editing. A step-by-step tutorial on the use of AI for Content CreationĪs writers, we often seek out tools to help us become more efficient or productive.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |