Created
May 8, 2021 11:32
-
-
Save prakhar21/d6fecb5e50614b882f9c935f0836f1da to your computer and use it in GitHub Desktop.
q_a_transformer_interpret.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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