CQCL / lambeq

A high-level Python library for Quantum Natural Language Processing
https://cqcl.github.io/lambeq/
Apache License 2.0
439 stars 106 forks source link

Error with Bobcat Parser #57

Closed dancbeaulieu closed 1 year ago

dancbeaulieu commented 1 year ago

Hi,

I am having a relatively difficult to understand error. I am trying to look at the sentence "Senate Advances Bill To Approve Keystone Pipeline Despite Obamas Veto Threat", and can't figure out why it is giving me the error below. Does BobCatParser throw an error if it doesn't recognize a word? I am unclear what I would need to do to fix the sentence.

from lambeq import BobcatParser

parser = BobcatParser() diagram = parser.sentence2diagram('Senate Advances Bill To Approve Keystone Pipeline Despite Obamas Veto Threat') diagram.draw()

raceback (most recent call last):

File "/Users/dabeaulieu/opt/anaconda3/envs/qcware/lib/python3.9/site-packages/lambeq/text2diagram/bobcat_parser.py", line 382, in sentences2trees trees.append(self._build_ccgtree(result[0]))

File "/Users/dabeaulieu/opt/anaconda3/envs/qcware/lib/python3.9/site-packages/lambeq/bobcat/parser.py", line 258, in getitem return self.root[index]

IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "/Users/dabeaulieu/opt/anaconda3/envs/qcware/lib/python3.9/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec exec(code, globals, locals)

File "/Users/dabeaulieu/Documents/Initiatives/quantum/machine learning/notebooks/qnlp/ankush/Quantum_NLP/testcode.py", line 12, in diagram = parser.sentence2diagram('Senate Advances Bill To Approve Keystone Pipeline Despite Obamas Veto Threat')

File "/Users/dabeaulieu/opt/anaconda3/envs/qcware/lib/python3.9/site-packages/lambeq/text2diagram/ccg_parser.py", line 231, in sentence2diagram return self.sentences2diagrams(

File "/Users/dabeaulieu/opt/anaconda3/envs/qcware/lib/python3.9/site-packages/lambeq/text2diagram/ccg_parser.py", line 161, in sentences2diagrams trees = self.sentences2trees(sentences,

File "/Users/dabeaulieu/opt/anaconda3/envs/qcware/lib/python3.9/site-packages/lambeq/text2diagram/bobcat_parser.py", line 387, in sentences2trees raise BobcatParseError(' '.join(sent.words))

BobcatParseError: Bobcat failed to parse 'Senate Advances Bill To Approve Keystone Pipeline Despite Obamas Veto Threat'.

ianyfan commented 1 year ago

This works if you change the sentence to: Senate Advances Bill To Approve Keystone Pipeline Despite Obama 's Veto Threat (including the extra space)

Omitting the apostrophe changes the semantics of the sentence to something the parser doesn't find grammatical.

Hope that makes sense. Let me know if you want any more explanation.

dimkart commented 1 year ago

This issue will be close due to inactivity. @dancbeaulieu if you require any more help let us know.