Text interpretation need not be done for every prediction. Can you share the code snippet maybe that would help.
@hafidz How did you obtain text attention scores and their corresponding mapping? I am getting index out of bounds when I compare the output of interp.intrinsic_attention()
txt = " Valar Morghulis - All men must serve"
x = interp.intrinsic_attention(txt)
returns a tuple of actual text and tensor of attention scores
(Text xxbos xxmaj xxunk xxmaj xxunk - xxmaj all men must serve, tensor([0.5078, 0.2553, 0.4090, 0.0895, 0.3499, 0.2155, 0.1322, 0.4119, 0.6209, 0.8082, 1.0000], device='cuda:0'))
x is of object Text and x is a tensor. Let’s say want to get top 5 attention words.
How do we tokenize Text object?
At first I thought I would use spacy.tokenize but there was length mismatch between words and their scores. After gong through fastai library , the
intrinsic_attention function uses split() to tokenise, even this is leading to length mismatch. Link to show_intrinsic_attention
show_piece_attn(text.text.split(), to_np(attn), **kwargs)
I am not sure how to proceed.
Can anyone help me.