PrithivirajDamodaran / Parrot_Paraphraser

A practical and feature-rich paraphrasing framework to augment human intents in text form to build robust NLU models for conversational engines. Created by Prithiviraj Damodaran. Open to pull requests and other forms of collaboration.
Apache License 2.0
866 stars 141 forks source link

TypeError: 'NoneType' object is not iterable #30

Closed 0x11c11e closed 1 year ago

0x11c11e commented 2 years ago

Hi,

Why do I get the error when running the following code?

`phrases = ["Can you recommend some upscale restaurants in Newyork?", "What are the famous places we should not miss in Russia?" ]

for phrase in phrases: print("-"100) print("Input_phrase: ", phrase) print("-"100) para_phrases = parrot.augment(input_phrase=phrase, use_gpu=False, do_diverse=True, diversity_ranker="levenshtein") for para_phrase in para_phrases: print(para_phrase)`

Error:

`TypeError Traceback (most recent call last) /home/user/Code/Parrot/main.ipynb Cell 4 in <cell line: 5>() 8 print("-"*100) 9 para_phrases = parrot.augment(input_phrase=phrase, use_gpu=False, do_diverse=True, diversity_ranker="levenshtein") ---> 10 for para_phrase in para_phrases: 11 print(para_phrase)

TypeError: 'NoneType' object is not iterable`

jasontian6666 commented 2 years ago

Same here.

rahulpr-kore commented 2 years ago

You could do something like this:

  if not para_phrases:
      continue
  for para_phrase in para_phrases:
      print("[INFO] Generated: {}".format(para_phrase[0]))
jasontian6666 commented 2 years ago

@rahulpr-kore Thank you. But this only ignores the issue without any fix. I still can't get any result.

MansiSharma98 commented 2 years ago

Same here. This is so frustrating!!

what the parrot paraphraser usually returns: a list of tuples each tuple consists of two things : paraphrased string token_count

if we give max_return_phrases = 3, then it will return a list of 3 such tuples.

but it is randomly returning None for sentences and there is no definite pattern, if I rerun the cell for the same sentence, it then sometimes returns the paraphrases.

tsikerdekis commented 1 year ago

If you look at the code, there are limits that could lead to None if not good candidates are found: https://github.com/PrithivirajDamodaran/Parrot_Paraphraser/blob/2cffbe911341e52dc73b77f9b0154c18d570603f/parrot/parrot.py#L130

You can bypass this by lowering those limits. For example:

para_phrases = None
    fluency_threshold = 0.90
    adequacy_threshold = 0.99
    iter = 0
    while para_phrases == None:
        para_phrases = parrot.augment(input_phrase=paraphrase_sent,
                                diversity_ranker="levenshtein",
                                do_diverse=False,
                                max_return_phrases = 1, 
                                max_length=1000, 
                                adequacy_threshold = adequacy_threshold, 
                                fluency_threshold = fluency_threshold)
        fluency_threshold -= 0.10
        adequacy_threshold -= 0.10
        iter += 1
        print(iter)
    return para_phrases[0][0]
PrithivirajDamodaran commented 1 year ago

I added a new demo notebook, and everything works fine. (check for the link in Readme)