0

I am trying to get the saliency score for sentiment analysis task. Every time I run the code I get different saliency scores. Should this be the case? I am attaching my code for more reference.

from allennlp.predictors.predictor import Predictor
import nltk
from allennlp.interpret.saliency_interpreters import SmoothGradient


data = "purchase costume year old grandson halloween arrive one week earlier expect happy grandson absolutely love glad order larger size size barely fit material durable well make think wear many time play since halloween happy purchase worth dollars spend"

words = nltk.word_tokenize(data)

predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/stanford-sentiment-treebank-roberta.2021-03-11.tar.gz")
predicted = predictor.predict(words)
saliency_scores = SmoothGradient(predictor).saliency_interpret_from_json({'sentence':words})

Every time I print saliency scores for the same data the values keep changing. Also the tokens that the model generates are distorted, for example halloween breaks into hall, ow and een. How can I fix this? Any help would be appreciated.

1 Answers1

1

The SmoothGradient interpreter adds random noise to embeddings. It is by design not deterministic. For details, you might have to read the paper: https://arxiv.org/abs/1706.03825

If you need deterministic results, try SimpleGradient instead.

Dirk Groeneveld
  • 2,547
  • 2
  • 22
  • 23