Changes to explainer constructor
In previous versions the constructor for explainers allowed for text to passed along with the model and tokenizer, text could also be passed to the explainer instance and would replace the text passed in the constructor. This behavior was confusing and also didn't work with integrating into future explainers. This version changes that behavior so that only the model and tokenizer are passed to the constructor and text is always passed to the instance.
Old
python
cls_explainer = SequenceClassificationExplainer(
"I love you, I like you",
model,
tokenizer)
cls_explainer("I hate you, I loathe you") overwrites intial text
New
python
cls_explainer = SequenceClassificationExplainer(
model,
tokenizer)
cls_explainer("I love you, I like you")
Question Answering Explainer (Experimental release)
This release adds an initial implementation of an explainer for question-answering models from the Huggingface library called the `QuestionAnsweringExplainer`. This explainer is still somewhat experimental and has not been tested with a wide range of models and architectures.
I'm still figuring some things out such as the default embeddings to explain attributions for. In some cases I can get the average attributions for three embedding types combined (word, position, token type) while in others this is not possible so I currently default to word attributions. While this was fine for the classification explainer, position ids and token type ids play a big role in calculating attributions for question-answering models.
How to create a QA explainer
python
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,
)
Getting word attributions
python
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,
)
`word_attributions` are a dict with two keys `start` and `end` the values for each key are a list of tuples. The values in `start` are the word attributions for the predicted start position from the `context` and the values in `end` are for the predicted end position.
We can get the text span for the predicted answer with
python
>>> qa_explainer.predicted_answer
'usage of machines to process and understand human language'
Like the classification explainer attributions can be visualized with
python
qa_explainer.visualize("bert_qa_viz.html")
This will create a table of two rows, the first for start position attributions and the second for end position attributions.
**Please report any bugs or quirks you find with this new explainer. Thanks**