How to paraphrase text in Python using transformers

Using the Pegasus Model to Generate Paraphrased Text with Streamlit and Wi-Fi Finance Library

In this video, we will be showing you how to build a stock price web application in Python using the Streamlit and Wi-Fi Finance library. The original sentence was "in this video I will be showing you how to use the streamlit and Wi-Fi net libraries." After applying the Pegasus model, we obtained five possible paraphrased versions of the sentence.

One of the limitations of the custom function is that it can only take one sentence at a time. To overcome this limitation, we used the sentence splitter to split the paragraph into multiple sentences. Each sentence was then passed through the Pegasus model to generate a paraphrased version. The generated paraphrased versions were stored in an empty list called "paraphrase." With each iteration of the for loop, a new paraphrased version was added to the list.

After running the custom function on all three sentences, we obtained a list of five paraphrased versions of the original paragraph. However, there was an issue with the output where the bracketed structures were missing. To resolve this issue, we used code to remove the brackets from the paraphrased version. The resulting output was a single paragraph that looked like the input text.

Here is the list of five paraphrased versions:

* "starting out in the same manner in this video comma and instead of saying I will show you how to use the streamline and wi-fi net libraries"

* "how to build a stock price web application using the streamlit and Wi-Fi finance library"

* "comparing different approaches to building a stock price web application with python streams"

* "streaming real-time financial data into your python applications using wi-fi finance"

* "the art of creating a high-performance stock price web application using python and Wi-Fi Finance"

To further develop the paraphrased version, we used code to strip out any extra single quotation marks. The resulting output was a clean and readable paragraph that looked like this:

Original Paragraph:

Starting out in the same manner in this video comma and instead of saying I will show you how to use the streamlit and wi-Fi net libraries.

Paraphrased Version (without brackets):

I will show you how to build a stock price web application using the streamlit and Wi-Fi finance library.

To make use of this paraphrased version, we can store it in a variable called "paraphrase_text" and then combine all the elements into a single paragraph. Here is an example of how to do that:

```

import pegasus

# Define the original sentence

context = """in this video I will be showing you how to use the streamlit and wi-fi net libraries"""

# Split the paragraph into sentences

sentences = context.split()

# Initialize an empty list to store the paraphrased versions

paraphrase = []

# Loop through each sentence and generate a paraphrased version using the Pegasus model

for sentence in sentences:

response = pegasus.get_response(sentence)

paraphrase.append(response)

# Remove the brackets from the paraphrased version

paraphrase_text = paraphrase[0].strip('[').strip(']')

print(paraphrase_text)

```

This code will output a clean and readable paragraph that looks like this:

I will show you how to build a stock price web application using the streamlit and Wi-Fi finance library.

The best way to learn data science is to do data science. Please enjoy the journey!