The interpretation of text classification throws an error when used on a pretrained network

#21

Mikonapoli. Thanks for doing the work

0 Likes

#22

Hi, is there any docs about TextClassificationInterpretation? I can’t find in https://docs.fast.ai/. Thanks a lot!

0 Likes

#23

No, this is a new experimental feature developed by @herrmann

1 Like

(Bobak Farzin) #24

May I add this to the docs in the text.learner section? Mirroring the vision.learner?
A small example might be helpful there.

0 Likes

#25

By all means! Any PR to make the docs better is more than welcome.

1 Like

(Bobak Farzin) #26

PR is out there!

0 Likes

#27

Hi,
I’ve wrote a method called show_top_losses() to enhance TextClassificationInterpretation inspired by plot_top_losses in vision.learn.
This method can creates a tabulation showing the first k texts in top_losses along with their prediction, actual, loss, and probability of actual class.
like this: (on my own dataset)


my code:

    def show_top_losses(self, k:int)->None:
        table_header = ['Text', 'Prediction', 'Actual', 'Loss', 'Probability']
        table_data = []
        tl_val,tl_idx = self.top_losses()
        for i,idx in enumerate(tl_idx):
            tx,cl = self.data.dl(self.ds_type).dataset[idx]
            cl = cl.data
            classes = self.data.classes
            tmp = (self.cut_by_line(tx.text), f'{classes[self.pred_class[idx]]}', f'{classes[cl]}', f'{self.losses[idx]:.2f}', f'{self.probs[idx][cl]:.2f}')
            table_data.append(tmp)
            k -= 1
            if k==0: break
        print(tabulate(table_data, headers=table_header, tablefmt='orgtbl'))

    def cut_by_line(self,text):
        res = ""
        width = 80
        lines = len(text) // width
        if lines == 0:
            res += text
        else:
            for i in range(lines):
                res += text[i * width:(i + 1) * width] + '\n'
            res += text[(range(lines)[-1] + 1) * width:]
        return res

I thought it is useful to me. May I add this to awd_lstm.py@sgugger

3 Likes

Is there any method like plot_top_losses for text
#28

That looks useful, don’t hesitate to suggest a PR with it!

1 Like

#29

thanks! PR is here :laughing:

2 Likes

(Bobak Farzin) #30

Thank you. I will definitely use this!

1 Like