Get list of classes from Text Data Block


I’m trying to pull the list of classes out of my text learner to feed into the sklearn classification report. In fastai1, I just used learn.classes, but I’m having troubles finding the equivalent in fastai2.

Since my dataset is multi-label, I’ve had to use build my data block using TextBlock (MultiCategoryBlock) instead of the TextDataLoader. Hence, I’m not able to use learn.dls.categorize.vocab.

Is there a way to extract a unique list of classes from the MultiCategoryBlock?

Thanks in advance everyone!


1 Like

Oh my goodness. I even did vars(learn.dls) to see all the member functions and I just glossed right over multi_categorize. Thank you so much, I feel like an idiot for wasting your time.


Sorry to bug ya again. I didn’t want to create a new topic for this in case it was an easy fix, but I’m having troubles exporting and loading the learner .pkl on a different PC.

I’m training and using learn.export() to export to a .pkl file and then importing on a PC that has the same version of fastai2, fastcore, and torch. The only difference is going from python 3.7.11 to 3.7.9.

I have exported vision learners and imported on this other PC many times with success, it’s just the text learners that I’ve exported that crash. I’m getting this specifically:

Process finished with exit code -1073741676 (0xC0000094)

When trying to call load_learner() with a text classifier model (both single label and multi-label). Have you seen this before?