Skip to content
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

Compatibility with Transformers.jl #164

Open
ceferisbarov opened this issue Jul 15, 2024 · 8 comments
Open

Compatibility with Transformers.jl #164

ceferisbarov opened this issue Jul 15, 2024 · 8 comments

Comments

@ceferisbarov
Copy link

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
Copy link

pat-alt commented Jul 16, 2024

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

@adrhill
Copy link
Member

adrhill commented Jul 22, 2024

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 Julia-XAI/XAIBase.jl#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
Copy link
Author

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

  • modify the analyze function and analyzers to accept this format or
  • create dedicated classes that accept a model and a tokenizer and handles the process itself.
    SequenceClassificationExplainer is a good example of this interface:
from transformers_interpret import SequenceClassificationExplainer
cls_explainer = SequenceClassificationExplainer(
    model,
    tokenizer)
word_attributions = cls_explainer("I love you, I like you")

@pat-alt
Copy link

pat-alt commented Jul 24, 2024

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

@adrhill
Copy link
Member

adrhill commented Jul 26, 2024

Thanks, things are getting better!

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

@ceferisbarov
Copy link
Author

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
Copy link
Member

adrhill commented Jul 27, 2024

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

@ceferisbarov
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants