LNN
LNN copied to clipboard
Cannot import name 'ForAll' from 'lnn'
Hi, I'm currently studying the LNN, and trying to evaluate the example code.
However, I've got this error from the example code:
- example code:
https://ibm.github.io/LNN/education/examples/reasoning.html#simple-geometry-reasoning-example
- where I stuck:
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.11.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from lnn import (Predicate, Variable,
...: Exists, Implies, ForAll, Model, Fact, World)
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from lnn import (Predicate, Variable,
2 Exists, Implies, ForAll, Model, Fact, World)
ImportError: cannot import name 'ForAll' from 'lnn' (/home/sungjin/.virtualenvs/lnn/lib/python3.10/site-packages/lnn/__init__.py)
I know that LNN is a great tool which will leverage the next step of AI, and I glad to know about it. And I hope there will be a chance to the newcomers like me. Thank you.
Oh, I figured it out why it does not work. ForAll
is changed to Forall
, the 'a' in the name is no longer capital.
In [1]: from lnn import ForAll
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from lnn import ForAll
ImportError: cannot import name 'ForAll' from 'lnn' (/home/sungjin/.virtualenvs/lnn/lib/python3.10/site-packages/lnn/__init__.py)
In [2]: from lnn import Forall
In [3]:
however, I got another error, that is,
from lnn import (Predicate, Variable,
Exists, Implies, Forall, Model, Fact, World)
model = Model()
# Variable
x = Variable('x')
# Predicate declarations
square = Predicate('square')
rectangle = Predicate('rectangle')
foursides = Predicate('foursides')
# Axioms declarations
square_rect = Forall(x, Implies(square(x), rectangle(x)))
rect_foursides = Forall(x, Implies(rectangle(x), foursides(x)))
# Query
query = Exists(x, foursides(x))
# Add predicates and rules to the model
model.add_knowledge(square, rectangle, square_rect, rect_foursides, query)
# Add facts to the model
model.add_data({square: {'c': Fact.TRUE, 'k': Fact.TRUE}})
# Perform inference
steps, facts_inferred = model.infer()
# Inspect the query node
# print(model['foursided_objects'].true_groundings)
print(model[query].true_groundings)
which is expected to emit the result:
{'c', 'k'}
but it just says:
(lnn) sungjin@daisylab:~/home/lnn-examples> python simple.py
set()