marcotcr / checklist

Beyond Accuracy: Behavioral Testing of NLP models with CheckList
MIT License
2.01k stars 204 forks source link

editor.synonyms breaks on specific input #98

Closed CristianManta closed 3 years ago

CristianManta commented 3 years ago

Hi,

editor.synonyms works very well in general, but I get IndexError: list index out of range when trying on the following pair:

syn_list = editor.synonyms('Is it resetting?', 'resetting')

The code to reproduce the issue is:

from checklist.editor import Editor
editor = Editor()
syn_list = editor.synonyms('Is it resetting?', 'resetting')

The bug happens with the latest version of checklist and pytorch.

Here is the complete error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cristian/anaconda3/envs/test/lib/python3.7/site-packages/checklist/editor.py", line 394, in synonyms
    return self._wordnet_stuff(templates, word, 'synonyms', threshold=threshold, **kwargs)
  File "/home/cristian/anaconda3/envs/test/lib/python3.7/site-packages/checklist/editor.py", line 354, in _wordnet_stuff
    return [x[0][0] for x in fn(texts, word, threshold=threshold, pos=pos, depth=depth)]
  File "/home/cristian/anaconda3/envs/test/lib/python3.7/site-packages/checklist/text_generation.py", line 262, in synonyms
    return self.filter_options(texts, word, options, threshold)
  File "/home/cristian/anaconda3/envs/test/lib/python3.7/site-packages/checklist/text_generation.py", line 280, in filter_options
    score = [x for x in ret if np.all([y in [word, self.tokenizer.unk_token] for y in x[0]])][0][-1]
IndexError: list index out of range

Thank you in advance for looking into this.

marcotcr commented 3 years ago

Thanks, fixed in bf51a392daea25a8f920cbf1c8474f76bcf41e0d