For a loaded learner, where are the list of labels stored?

When I load a learner saved to disk, where are the list of string labels associated with each class stored?

I want to take the Tensor of probabilities returned as the third element by learn.predict, and view probability of each label e.g.

Label X: 0.3
Label Y: 0.4
Label Z: 0.3

I know the information must be accessible, because the first element returned by learn.predict is the string label associated with the most probable class. But I can’t seem to find the other ones contains the list of classes.


is there a way to rename the labels after we export the learner?

All data and documentation point to this answer, yet the learner doesn’t have a data attribute, and if it’s dl instead of data, then that one doesn’t have classes.

What’s the preferred way of finding the classes now? The API is not easy to follow nowadays.

In particular, I noticed after days that cnn_learner trained on URLS.FOOD is outputting what seems like 22 classes based on the layer shapes instead of 101, and I was trying to figure out why that is but all references in old discussions (as well as little/no references in the docs) discuss nonexisting attributes for dealing with the categories.


I think you are mixing two versions of fastai. fastai v1’s Learner has a data attribute.

Fastai v2 is still under development and the documentation is not ready yet (the README begins with : “NB: This is still in early development. Use v1 unless you want to contribute to the next version of fastai” so don’t say you have not been warned).


But still, how to get classes in fastai2 learner? :slight_smile:

dls.vocab is where it lives.


ah thanks!
found it in learn.dls.vocab[1]