lichengunc / refer-parser2

Referring Expression Parser
26 stars 7 forks source link

Error while parsing attributes #5

Closed abhinavkaul95 closed 3 years ago

abhinavkaul95 commented 3 years ago

While executing the following command:

python parse_atts.py --dataset refcoco --splitBy unc

I am getting the following error:

`Traceback (most recent call last): File "parse_atts.py", line 57, in main attparser.reset(parse) File "/media/disk/user/abhinav/refer-parser2/pyutils/attparser/cocoParser.py", line 21, in reset BaseParser.reset(self, parse) File "/media/disk/user/abhinav/refer-parser2/pyutils/attparser/baseParser.py", line 29, in reset self._tree = Tree.fromstring(parse['parsetree']) File "/media/disk/user/abhinav/MAttNet/venv/lib/python3.7/site-packages/nltk/tree.py", line 687, in fromstring cls._parse_error(s, match, open_b) File "/media/disk/user/abhinav/MAttNet/venv/lib/python3.7/site-packages/nltk/tree.py", line 738, in _parse_error raise ValueError(msg) ValueError: Tree.read(): expected '(' but got '[Text=lady' at index 0. "[Text=lady..." ^

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "parse_atts.py", line 85, in main(params) File "parse_atts.py", line 63, in main sent['left'] = attparser.leftWords() File "/media/disk/user/abhinav/refer-parser2/pyutils/attparser/baseParser.py", line 89, in leftWords all_wds = [word[0] for word in self._words] AttributeError: 'CocoParser' object has no attribute '_words'`

Following is my requirements.txt:

cached-property==1.5.2
click==7.1.2
cycler==0.10.0
Cython==0.29.22
decorator==4.4.2
h5py==3.2.1
imageio==2.9.0
joblib==1.0.1
kiwisolver==1.3.1
matplotlib==3.3.4
networkx==2.5
nltk==3.5
numpy==1.20.1
pexpect==4.8.0
Pillow==8.1.2
pkg-resources==0.0.0
progressbar==2.5
ptyprocess==0.7.0
pyparsing==2.4.7
python-dateutil==2.8.1
PyWavelets==1.1.1
regex==2021.3.17
scikit-image==0.18.1
scipy==1.1.0
six==1.15.0
tifffile==2021.3.17
tqdm==4.59.0
abhinavkaul95 commented 3 years ago

Looks like parse_sents is making a parse tree like this: '[Text=lady CharacterOffsetBegin=4 CharacterOffsetEnd=8 PartOfSpeech=NN Lemma=lady] [Text=with CharacterOffsetBegin=9 CharacterOffsetEnd=13 PartOfSpeech=IN Lemma=with] [Text=the CharacterOffsetBegin=14 CharacterOffsetEnd=17 PartOfSpeech=DT Lemma=the] [Text=blue CharacterOffsetBegin=18 CharacterOffsetEnd=22 PartOfSpeech=JJ Lemma=blue] [Text=shirt CharacterOffsetBegin=23 CharacterOffsetEnd=28 PartOfSpeech=NN Lemma=shirt] (ROOT (NP (NP (DT the) (NN lady)) (PP (IN with) (NP (DT the) (JJ blue) (NN shirt)))))' but parse_attrs is expecting a tree like this: (ROOT (NP (NP (DT the) (NN lady)) (PP (IN with) (NP (DT the) (JJ blue) (NN shirt)))))' and that is why the error.

wansenwu commented 1 year ago

Hi! I met this issue as well, so how to fix it?

AKASH2907 commented 1 year ago

Quick hack could be just find the first instance of '(':

index = output['parsetree'].find('(')
output['parsetree'] = output['parsetree'][index:]