Closed robinvanschaik closed 3 years ago
Hah. I finally found my mistake. The sanity checks in this colab helped me.
sentence = Sentence("Hallo wereld. Waar is mijn order? Ik heb tot nu toe nog niks ontvangen?")
tokenized_sentence = [sentence.to_tokenized_string()]
# Returns
# ['Hallo wereld . Waar is mijn order ? Ik heb tot nu toe nog niks ontvangen ?']
I would pass this sentence into the raw_input
parameter of VisualizationDataRecord
.
However, this is just a a list containing one element. Passing the actual tokens via:
all_tokens = flair_model_wrapper.tokenizer.convert_ids_to_tokens(input_ids[0])
# Returns the following:
['▁Hallo',
'▁wereld',
'▁',
'.',
'▁Waar',
'▁is',
'▁mijn',
'▁order',
'▁?',
'▁Ik',
'▁heb',
'▁tot',
'▁nu',
'▁toe',
'▁nog',
'▁niks',
'▁ontvangen',
'▁?']
Hi all,
I have fine-tuned a 9-class text classifier by making use of Flair and made use of these multilingual sentence-embeddings. I am getting good performance, but I would like to incorporate model transparency for debugging & explainability towards other stakeholders.
I have managed to create a wrapper for my Flair model & reworked the forward method in order to utilize the LayerIntegratedGradients method of Captum. Similar to the BERT tutorial that is provided by Captum. However, I recognize I may have Frankenstein'd this.
In my Forward method I return the logits as suggested here and calculate the probability outside the forward function.
I am getting close to an output, but visualising word importance feature is throwing me off. It seems in my case to return either all green / all red word importances. I have also noticed that the attribution score can change immensely if I crank up the number of steps from 50, to 200 to 7000.
To calculate the attributions across word I make use of the following function:
But I am unsure if I missed out on anything regarding calculating the attributions or other obvious mistakes.
For transparency's sake, here is the code I have so far.