Open ceferisbarov opened 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 😄
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?
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
analyze
function and analyzers to accept this format orfrom transformers_interpret import SequenceClassificationExplainer
cls_explainer = SequenceClassificationExplainer(
model,
tokenizer)
word_attributions = cls_explainer("I love you, I like you")
Sorry to hear @adrhill, hope you've recovered by now
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?
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.
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?
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?
Hi @ceferisbarov, I hope #176 clears up how to use the package. Existing analyzers should support anything that takes an input and is differentiable.
Transformers.jl models require
NamedTuple
input. ExplainableAI.jl analyzers require a derivative ofAbstractArray
. 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.