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

Support for Longformer #130

Open
mpafla opened this issue Mar 27, 2023 · 0 comments
Open

Support for Longformer #130

mpafla opened this issue Mar 27, 2023 · 0 comments

Comments

@mpafla
Copy link

mpafla commented Mar 27, 2023

I am trying to get word attributions running for the Longformer model.

from transformers import AutoTokenizer, AutoModelForQuestionAnswering
from transformers_interpret import QuestionAnsweringExplainer


question = "How many programming languages does BLOOM support?"
context = "BLOOM has 176 billion parameters and can generate text in 46 languages natural languages and 13 programming languages."

tokenizer = AutoTokenizer.from_pretrained("valhalla/longformer-base-4096-finetuned-squadv1")
model = AutoModelForQuestionAnswering.from_pretrained("valhalla/longformer-base-4096-finetuned-squadv1")

qa_explainer = QuestionAnsweringExplainer(
    model,
    tokenizer,
)

word_attributions = qa_explainer(
    question,
    context,
)

print(word_attributions)
print(qa_explainer.predicted_answer)
qa_explainer.visualize("bert_qa_viz.html")

With this code I get the following error.
AssertionError: There should be exactly three separator tokens: 2 in every sample for questions answering. You might also consider to set `global_attention_mask` manually in the forward function to avoid this error.

Is this expected? How do I get the word attributions for the Longformer model (if I can)?

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

1 participant