HEmile / KENN-PyTorch

PyTorch implementation of the KENN model
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

Returned deltas are reversed #3

Open NooneBug opened 2 years ago

NooneBug commented 2 years ago

Hi,

I found a strange behavior of the code. After solving the other issue I posted as explained inside the issue, I used the code to see the deltas returned by the KnowledgeEnhancer (as you can see in the notebook).

I found that if I manually sum the returned deltas with the original preactivation I obtain a different vector w.r.t. the one returned by the KnowledgeEnhancer. I used the debugger to inspect the behavior and I found that in line 98 of ClauseEnhancer.py the variables scattered_delta and delta contain the same values but reversed. I also checked that scattered_delta is the summed variable to obtain the enhanced prediction and delta is the returned variable when save_training_data = True.

Why these variables are reversed?

I think that the correct one is scattered_delta, is it correct?

Thanks

DanieleAlessandro commented 2 years ago

Hi Manuel! Thanks for the feedback. I checked the code at line 98 and tried it in debug mode. The behavior seems correct to me. The correct matrix, used by the knowledge enhancer, is scattered_delta which contains the changes to be applied on the initial predicates. The delta matrix was used in the tensorflow version for explainability (but the code of the explainer is not available for the pytorch version, and not yet completed in the tensorflow one). It was copied from the tensorflow code while doing the migration but it can be removed.