Skip to content

[Explainability]: explain support for heterogenous graphs. #6014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wsad1 opened this issue Nov 19, 2022 · 5 comments · Fixed by #6091
Closed

[Explainability]: explain support for heterogenous graphs. #6014

wsad1 opened this issue Nov 19, 2022 · 5 comments · Fixed by #6091

Comments

@wsad1
Copy link
Member

wsad1 commented Nov 19, 2022

🚀 The feature, motivation and pitch

Add a new class HeteroExplainer that supports explaining heterogenous graphs. This will involve the following changes to
explain module

  1. Create a BaseExplainer which will have common functions both HeteroExplainer and Explainer needs.
  2. Explainer class will inherit from BaseExplainer. Note: The Explainer class will have the same interface the only change is that it inherits form BaseExplainer
  3. Add HeteroExplanation(HeteroData) to hold heterogenous explanations.
  4. HeteroExplainer inherits from BaseExplainer. Both HeteroExplainer and Explainer can use the same config files as input.
class HeteroExplainer(BaseExplainer):
    def __call__(x_dict, edge_index_dict, *, target, target_idx)-> HeteroExplanation:
     ...
    def _threshold(self, explanation: HeteroExplanation)->HeteroExplanation:
    ...

cc: @dufourc1 @RexYing for thoughts

Alternatives

An alternative will be for Explainer to handle both hetero and homo graphs. But I feel this makes the interface more cluttered because it has to accept both dictionary or tensors and the implementation more complicated.

Additional context

This is part of the explainability roadmap: #5520, #5630

@wsad1 wsad1 self-assigned this Nov 19, 2022
@wsad1 wsad1 changed the title [Explainability]: Extend Explainer interface to support heterogenous graphs. [Explainability]: explain suppor for heterogenous graphs. Nov 19, 2022
@rusty1s
Copy link
Member

rusty1s commented Nov 21, 2022

Do you think we can just share the Explainer class for both cases? I would like to avoid creating replicas for each algorithm and the base class. Since we usually just forward pass input arguments to the model, I believe the interface isn't necessarily cluttered at all.

@dufourc1
Copy link
Member

The type hints for the Explainer class will be ugly, but since the user has to give an explanation algorithm to the Explainer, I tend to agree with rusty1s that they can probably share the same Explainer.

Maybe we can have two classes of ExplainerAlgorithm, one for the heterogeneous and the other for the homogeneous graphs ? I'm guessing the heterogeneous case will have to have quite a lot of utilities functions that the homogeneous case will never need.

@dufourc1 dufourc1 changed the title [Explainability]: explain suppor for heterogenous graphs. [Explainability]: explain support for heterogenous graphs. Nov 21, 2022
@wsad1
Copy link
Member Author

wsad1 commented Nov 22, 2022

Yeah having Explainer support both seems reasonable now. But we'll have some if conditions checking if input is of type dictionary or tensor

class Explainer():
    def __call__(x: Union[Tensor, Dict[NodeType, Tensor]], edge_index: Union[Tensor,Dict[EdgeType, Tensor]],   *, target, 
                   target_idx)-> Union[HeteroExplanation, Explanation]:
          ....

    def _threshold(self, explanation: Union[Explanation, HeteroExplanation])->Union[Explanation, HeteroExplanation]:
        if isinstanc(expalnation, Explanation):
            return _threshold_explanation(explanation)
       else:
             return _threshold_hetero_explantion(explanation)

Maybe we can have two classes of ExplainerAlgorithm, one for the heterogeneous and the other for the homogeneous graphs

If we are unifying everything behind the Explainer interface then we should be able to do the same for ExplainerAlgorithm. Some ExplainerAlgorithms will support explaining both homo and hetero graphs, other won't. We could add a new config variable ModelConfig.model_type to indicate the type of model being explained. This config would be set internally in Explainer.__call__ and ExpalinerAlgorithm.supports would check this to see it supports explaining the kind of model.

@dufourc1
Copy link
Member

Do we need the new config type (apart from checking if the ExplainerAlgorithm supports the kind of explanation)? Can't we infer the heterogeneous vs homogeneous from the x and edge type ?

@rusty1s
Copy link
Member

rusty1s commented Nov 22, 2022

Yes, we don‘t need new configs for this IMO.

wsad1 added a commit that referenced this issue Dec 10, 2022
Starts heterogeneous explanations using the new `Explainer` framework.
Creates `HeterogeneousExplanation` and extends `Explainer`,
`ExplainerAlgorithm`, and `DummyExplainer` to handle heterogeneous
graphs. Tests and functionalities are partially complete, looking to get
some initial validation before continuing.

Todo
- Heterogeneous explanation tests
- Add and test thresholding for heterogeneous explanations
- Finish some heterogeneous explanation methods
- Extend GNNExplainer (maybe in separate PR)

Closes #6014

Co-authored-by: Jinu Sunil <jinu.sunil@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants