Skip to content

Instantly share code, notes, and snippets.

@prakhar21
Created May 8, 2021 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prakhar21/d6fecb5e50614b882f9c935f0836f1da to your computer and use it in GitHub Desktop.
Save prakhar21/d6fecb5e50614b882f9c935f0836f1da to your computer and use it in GitHub Desktop.
q_a_transformer_interpret.py
from transformers import AutoModelForQuestionAnswering, AutoTokenizer
from transformers_interpret import QuestionAnsweringExplainer
tokenizer = AutoTokenizer.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
model = AutoModelForQuestionAnswering.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
qa_explainer = QuestionAnsweringExplainer(
model,
tokenizer,
)
context = """
In Artificial Intelligence and machine learning, Natural Language Processing relates to the usage of machines to process and understand human language.
Many researchers currently work in this space.
"""
word_attributions = qa_explainer(
"What is natural language processing ?",
context,
)
html = qa_explainer.visualize()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment