Provides an interpretation of classification based on input sensitivity. This was designed for AWD-LSTM only for the moment, because Transformer already has its own attentional model.
Calculate the intrinsic attention of the input w.r.t to an output
class_id, or the classification given by the model if
None. For reference, see the Sequential Jacobian session at https://www.cs.toronto.edu/~graves/preprint.pdf
Create a tabulation showing the first
k texts in top_losses along with their prediction, actual,loss, and probability of actual class.
max_len is the maximum number of tokens displayed.
Let's show how
TextClassificationInterpretation can be used once we train a text classification model.
imdb = untar_data(URLs.IMDB_SAMPLE)
data_lm = (TextList.from_csv(imdb, 'texts.csv', cols='text') .split_by_rand_pct() .label_for_lm() .databunch()) data_lm.save()
|0||! ! ! xxmaj finally this was directed by the guy who did xxmaj big xxmaj xxunk ? xxmaj must be a replay of xxmaj jonestown - hollywood style . xxmaj xxunk ! xxbos xxmaj this is a extremely well - made film . xxmaj the acting , script and camera - work are all first - rate . xxmaj the music is good , too , though it is|
|1||) . xxmaj all in all , we were very disappointed at this xxmaj spike xxmaj lee effort ! ! xxbos a really great movie and true story . xxmaj dan xxmaj jansen the xxmaj greatest xxunk ever . a touching and beautiful movie the whole family can enjoy . xxmaj the story of xxmaj jane xxmaj xxunk battle with cancer and xxmaj dan xxmaj jansen love for his sister|
|2||just typical folks ) in everyday settings in order to create xxunk involving and realistic films . \n \n xxmaj in this case , the film is about xxmaj french and xxmaj german coal miners , so appropriately , the people in the roles seem like miners -- not actors . xxmaj the central conflict as the film begins is that there is a huge mine xxunk on the|
|3||here that xxunk banning ... which is a shame because i never would have sat through it where it not for the fact that it 's on ' the xxunk list ' . xxmaj the plot actually gives the film a decent base - or at least more of a decent base than most xxunk films - and it follows an actress who is kidnapped and dragged off into the|
|4||xxmaj at the same time , the xxmaj john xxmaj holmes character shows a very clever hustler who is able to pass through the xxunk and xxunk situations almost xxunk . xxmaj the movie deserves being watched more than once . xxmaj the seventies ambiance xxunk and full of drugs is amazing . xxbos xxmaj if you loved xxmaj long xxmaj way xxmaj round you will enjoy this nearly as|
learn = language_model_learner(data_lm, AWD_LSTM) learn.fit_one_cycle(2, 1e-2) learn.save('mini_train_lm') learn.save_encoder('mini_train_encoder')
data_clas = (TextList.from_csv(imdb, 'texts.csv', cols='text', vocab=data_lm.vocab) .split_from_df(col='is_valid') .label_from_df(cols='label') .databunch(bs=42))
learn = text_classifier_learner(data_clas, AWD_LSTM) learn.load_encoder('mini_train_encoder') learn.fit_one_cycle(2, slice(1e-3,1e-2)) learn.save('mini_train_clas')
interp = TextClassificationInterpretation.from_learner(learn)
interp.show_intrinsic_attention("I really like this movie, it is amazing!")