[Python Script] Simple Paraphrasing Tool - Free

JNinja

Junior Member
Joined
Aug 13, 2022
Messages
191
Reaction score
212
I noticed that this forum seems to love Paraphrasing tools (obvious reasons why) but a lot of the paraphrasing tools have low character limits on free plans and can be quite expensive.

This is a 100% free paraphrasing tool with no limits. It is built in Python and you would run it on your local machine or server if you know how to set that up. It is basic but should get the job done.

Here's the code:
Code:
import nltk
from nltk.corpus import wordnet

def paraphrase(text):
    # Tokenize the text
    tokens = nltk.word_tokenize(text)

    # Part-of-speech tag the tokens
    pos_tags = nltk.pos_tag(tokens)

    # Create an empty list to store the paraphrased words
    paraphrased_words = []

    # Loop through each token and its part-of-speech tag
    for token, pos in pos_tags:
        # If the token is a noun or a verb, find its synonyms
        if pos.startswith("NN") or pos.startswith("VB"):
            # Get the synonyms of the word
            synonyms = wordnet.synsets(token)

            # If there are synonyms, choose one at random
            if synonyms:
                paraphrased_word = synonyms[0].lemmas()[0].name()

                # If the paraphrased word is not the same as the original word, use it
                if paraphrased_word != token:
                    paraphrased_words.append(paraphrased_word)
                    continue

        # If no synonyms were found or the word is not a noun or verb, use the original word
        paraphrased_words.append(token)

    # Join the paraphrased words to form the paraphrased sentence
    paraphrased_text = " ".join(paraphrased_words)

    return paraphrased_text

# Test the paraphrasing tool
text = "The quick brown fox jumps over the lazy dog."
paraphrased_text = paraphrase(text)
print(paraphrased_text)
 
can you make a video showing how to use this? a lot of people dont know how to use python and it would be helpful for running scripts

great share.

thanks
 
can you make a video showing how to use this? a lot of people dont know how to use python and it would be helpful for running scripts

great share.

thanks

But that is the basic thing you will find anywhere on internet how to compile python script.

Here are tweaks which will help.

Python:
import random
import nltk
from nltk.corpus import wordnet
def paraphrase(text):
tokens = nltk.word_tokenize(text)
pos_tags = nltk.pos_tag(tokens)
paraphrased_words = []
for token, pos in pos_tags:
if pos.startswith("NN") or pos.startswith("VB"):
synonyms = wordnet.synsets(token)
if synonyms:
paraphrased_word = random.choice(synonyms).lemmas()[0].name()
if paraphrased_word != token:
paraphrased_words.append(paraphrased_word)
continue
paraphrased_words.append(token)
paraphrased_text = " ".join(paraphrased_words)
return paraphrased_text
text = "The quick brown fox jumps over xCode."
paraphrased_text = paraphrase(text)
print(paraphrased_text)
 
I noticed that this forum seems to love Paraphrasing tools (obvious reasons why) but a lot of the paraphrasing tools have low character limits on free plans and can be quite expensive.

This is a 100% free paraphrasing tool with no limits. It is built in Python and you would run it on your local machine or server if you know how to set that up. It is basic but should get the job done.

Here's the code:
Code:
import nltk
from nltk.corpus import wordnet

def paraphrase(text):
    # Tokenize the text
    tokens = nltk.word_tokenize(text)

    # Part-of-speech tag the tokens
    pos_tags = nltk.pos_tag(tokens)

    # Create an empty list to store the paraphrased words
    paraphrased_words = []

    # Loop through each token and its part-of-speech tag
    for token, pos in pos_tags:
        # If the token is a noun or a verb, find its synonyms
        if pos.startswith("NN") or pos.startswith("VB"):
            # Get the synonyms of the word
            synonyms = wordnet.synsets(token)

            # If there are synonyms, choose one at random
            if synonyms:
                paraphrased_word = synonyms[0].lemmas()[0].name()

                # If the paraphrased word is not the same as the original word, use it
                if paraphrased_word != token:
                    paraphrased_words.append(paraphrased_word)
                    continue

        # If no synonyms were found or the word is not a noun or verb, use the original word
        paraphrased_words.append(token)

    # Join the paraphrased words to form the paraphrased sentence
    paraphrased_text = " ".join(paraphrased_words)

    return paraphrased_text

# Test the paraphrasing tool
text = "The quick brown fox jumps over the lazy dog."
paraphrased_text = paraphrase(text)
print(paraphrased_text)
Thanks for sharing information
 
Use YouTube to learn how to execute Python script from terminal...
 
thanks - useful tool - but the output quality of nltk English seems really bad... not usable without heavy editing - which would defeat the purpose somewhat
 
Back
Top