dice-group / Ontolearn

Ontolearn is an open-source software library for explainable structured machine learning in Python. It learns OWL class expressions from positive and negative examples.
https://ontolearn-docs-dice-group.netlify.app/index.html
MIT License
40 stars 9 forks source link

DRILL cannot access class hierarchy if we use a TripleStoreKnowledgeBase #446

Open MichaelRoeder opened 1 month ago

MichaelRoeder commented 1 month ago

Problem

DRILL crashes with the following stack trace:

Traceback (most recent call last):
  File "/local/upb/users/q/quannian/profiles/unix/cs/Pycharm_Project/Ontolearn-0.7.3/Ontolearn/examples/concept_learning_drill_[train.py](http://train.py/)", line 125, in <module>
    start(parser.parse_args())
  File "/local/upb/users/q/quannian/profiles/unix/cs/Pycharm_Project/Ontolearn-0.7.3/Ontolearn/examples/concept_learning_drill_[train.py](http://train.py/)", line 50, in start
    drill.train(num_of_target_concepts=args.num_of_target_concepts,
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/learners/[drill.py](http://drill.py/)", line 263, in train
    sum_of_rewards_per_actions = self.rl_learning_loop(pos_uri=frozenset(positives),   
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/learners/[drill.py](http://drill.py/)", line 224, in rl_learning_loop
    sequence_of_states, rewards = self.sequence_of_actions(root_rl_state)
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/learners/[drill.py](http://drill.py/)", line 464, in sequence_of_actions
    next_rl_states = list(self.apply_refinement(current_state))
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/learners/[drill.py](http://drill.py/)", line 444, in apply_refinement
    for i in self.operator.refine(rl_state.concept):  # O(N)
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/refinement_[operators.py](http://operators.py/)", line 249, in refine
    for i in self.refine_top():
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/refinement_[operators.py](http://operators.py/)", line 111, in refine_top
    most_general_concepts = [i for i in self.kb.get_most_general_classes()]
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/refinement_[operators.py](http://operators.py/)", line 111, in <listcomp>
    most_general_concepts = [i for i in self.kb.get_most_general_classes()]
  File "/upb/users/q/quannian/profiles/unix/cs/.conda/envs/ontolearn-0.7.3/lib/python3.10/site-packages/ontolearn/knowledge_[base.py](http://base.py/)", line 795, in get_most_general_classes
    yield from self.class_hierarchy.roots()
AttributeError: 'TripleStoreKnowledgeBase' object has no attribute 'class_hierarchy'

Recreate problem

Adapt the example script of DRILL in the following way:

def start(args):
-    kb = KnowledgeBase(path=args.path_knowledge_base)
+    kb = TripleStoreKnowledgeBase('http://dice-quan.cs.uni-paderborn.de:9080/sparql')
     drill = Drill(knowledge_base=kb,
                   path_embeddings=args.path_embeddings,
                   refinement_operator=LengthBasedRefinement(knowledge_base=kb),
                   quality_func=F1(),
                   reward_func=CeloeBasedReward(),
                   epsilon_decay=args.epsilon_decay,
                   learning_rate=args.learning_rate,
                   num_of_sequential_actions=args.num_of_sequential_actions,
                   num_episode=args.num_episode,
                   iter_bound=args.iter_bound,
                   max_runtime=args.max_runtime)

Possible source

It seems like the class_hierarchy attribute is never created because the TripleStoreKnowledgeBase initializes its superclass KnowledgeBase with load_class_hierarchy=False (see here).

Demirrr commented 3 weeks ago

Currently, we do not support TripleStoreKnowledgeBasefor the time being. So, please use TripleStore()
DRILL is not designed to acces class hiearahrcy :)