Julia-XAI / ExplainableAI.jl

Explainable AI in Julia.
MIT License
109 stars 2 forks source link

Compatibility with Transformers.jl #164

Open ceferisbarov opened 4 months ago

ceferisbarov commented 4 months ago

Transformers.jl models require NamedTuple input. ExplainableAI.jl analyzers require a derivative of AbstractArray. We can solve this by modifying XAIBase.jl and ExplainableAI.jl to support the Transformers.jl interface. I can start working on a PR if the maintainers are interested.

pat-alt commented 4 months ago

@adrhill this is related to https://github.com/JuliaTrustworthyAI/CounterfactualExplanations.jl/pull/413 and perhaps a good first step towards integrating our systems a bit more 😄

adrhill commented 4 months ago

Sorry for the late answer @ceferisbarov, @pat-alt, I caught a bad case of COVID and spent last week recovering from it! We should absolutely make this package compatible with Transformers.jl.

ExplainableAI.jl analyzers require a derivative of AbstractArray.

This constraint is not intended. I dug into it and comes from overly strict type annotations in the XAIBase interface. I've opened a more specific issue in https://github.com/Julia-XAI/XAIBase.jl/issues/18.

I'll leave this issue open to track compatibility of ExplainableAI.jl with Transformers.jl. Do you have some specific use case you expected to work that you could share?

ceferisbarov commented 4 months ago

I hope you are doing better now!

Here is an example:

using Transformers
using Transformers.TextEncoders
using Transformers.HuggingFace

using ExplainableAI

classifier = hgf"gtfintechlab/FOMC-RoBERTa:ForSequenceClassification"

encoder = hgf"gtfintechlab/FOMC-RoBERTa"[1]

analyzer = IntegratedGradients(classifier)

input = encode(encoder, "Hello, world!")

expl = analyze(input, analyzer)

input variable is a NamedTuple. We can either

pat-alt commented 4 months ago

Sorry to hear @adrhill, hope you've recovered by now

adrhill commented 3 months ago

Thanks, things are getting better!

I'm addressing this issue by updating the ecosystem interface in https://github.com/Julia-XAI/XAIBase.jl/pull/20. Since this will already be a breaking change, is there anything else you'd like to see changed @ceferisbarov?

ceferisbarov commented 3 months ago

That was quick, thanks! I don't have anything else to add.

I can use the new version and give feedback if I face any issues. Please, let me know if I can help in any other way.

adrhill commented 3 months ago

I just merged PR #166, which includes the changes from https://github.com/Julia-XAI/XAIBase.jl/pull/20. Could you try out whether things now work for you on the main branch?

ceferisbarov commented 3 months ago

Sorry, I am having laptop issues, so I won't be able to try it this week.

To be clear, I am supposed to create a new analyzer, since the existing ones do not support Transformer models, right?

adrhill commented 1 month ago

Hi @ceferisbarov, I hope #176 clears up how to use the package. Existing analyzers should support anything that takes an input and is differentiable.