CQCL / lambeq

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

Ty('P') Error #18

Closed ACE07-Sev closed 2 years ago

ACE07-Sev commented 2 years ago

Traceback (most recent call last): File "C:\Users\elmm\Desktop\CQM\QNLP Depression.py", line 141, in train_circuits = [ansatz(diagram) for diagram in train_diagrams] File "C:\Users\elmm\Desktop\CQM\QNLP Depression.py", line 141, in train_circuits = [ansatz(diagram) for diagram in train_diagrams] File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\ansatz\circuit.py", line 59, in call return self.functor(diagram) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\discopy\rigid.py", line 651, in call return super().call(diagram) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\discopy\monoidal.py", line 900, in call result = result >> id_l @ self(box) @ id_r File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\discopy\rigid.py", line 642, in call return super().call(diagram) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\discopy\monoidal.py", line 894, in call return super().call(diagram) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\discopy\cat.py", line 911, in call return self.ar[arrow] File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\discopy\cat.py", line 961, in getitem return self._func(box) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\ansatz\circuit.py", line 118, in _ar dom, cod = self._ob(box.dom), self._ob(box.cod) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\ansatz\circuit.py", line 63, in _ob return sum(self.ob_map[Ty(factor.name)] for factor in pg_type) File "C:\Users\elmm\AppData\Local\Programs\Python\Python39\lib\site-packages\lambeq\ansatz\circuit.py", line 63, in return sum(self.ob_map[Ty(factor.name)] for factor in pg_type) KeyError: Ty('p')

How can I resolve this?

ACE07-Sev commented 2 years ago

This issue can be resolved by adding a AtomicType.PREPOSITIONAL_PHRASE to the IQP ansatz. for versions under 0.2.3 it will be AtomicType.PREPOSITION, and for 0.2.3 AtomicType.PREPOSITIONAL_PHRASE.

y-richie-y commented 2 years ago

Thanks for the issue! Yes, it is necessary in general to provide mappings for noun, sentence and propositional phrase types in the Ansatz mapping. We will update the examples in the documentation to reflect this.

dimkart commented 2 years ago

This will be now closed.