PrithivirajDamodaran/Parrot_Paraphraser

TypeError: 'NoneType' object is not iterable

Closed this issue · 6 comments

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`

Same here.

You could do something like this:

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

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

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.

If you look at the code, there are limits that could lead to None if not good candidates are found:

adequacy_filtered_phrases = self.adequacy_score.filter(input_phrase, paraphrases, adequacy_threshold, device )

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]

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