Significant changes just pushed

I’ve just pushed changes based on my recent work in NLP. I haven’t had time to thoroughly test whether they’ve broken any of the lessons, so apologies in advance if you find anything not working. Please either let me know here of problems, or if you know how to fix them feel free to send a PR (and let us know here that you’ve fixed it).

One key change is that metrics now take pytorch tensors/variables, not numpy arrays. The reason is that (to my surprise!) calculating accuracy was taking a significant percentage of training time. Moving it from numpy to pytorch as fixed that problem.

The other key changes are around the NLP modules. They are designed to continue to work much the same way as before, but there have been internal changes. (FYI, you’ll see significant overlap between fastai.nlp and fastai.text. fastai.nlp is the old module that’s designed to work with torchtext. fastai.text is a new module designed to replace torchtext. You should stick with fastai.nlp since the new module isn’t documented, unless you’re interested in getting involved in development of this module.)


Hi Jeremy

I’m wanting to work with the new code in the fastai.text namespace as it seems more friendly for both multi-class and multi-label problems.

In the .nlp namespace there exists a helper method to build the DataLoaders that was heavily dependenent on torchtext. In the .text namepace, there exists just a constructor that accepts the dataloaders as arguments. My question is:

What should these datasets/dataloaders look like and is there a recommended way to build them?

(attached is what I did for the toxic comp. using the nlp namespace; any feedback and what is good, bad, or could be improved would be appreciated in addition to how to translate these to something that will work with the text namespace).

I’m also going to submit a PR for a def text_labels_from_dataframes() once I get things working as is (I still find working with dataframes so much more pleasant and flexible than the reading files approach).


@wgpubs I plan to release fastai.text in the next week or so I’ll be providing some documentation and sample scripts then. If you haven’t seen something by this time next week, feel free to ping me.

1 Like

Looking forward to an update on this. Currently working on the Toxic challenge. Having issues with loading the data to torchtext.

check out my gist @hafidz

I would love to get feedback on this, but this is my attempt to create a multi-label friendly dataset using torchtext and fastai for that competition.

@wgpubs Are you referring to this gist ->

Sorry had to clarify since I think I’ve seen other gist from you before in other threads.

Yah that is it

Great! Thanks for this. I have been also working on toxic comment like you and @hafidz and struggling to create a dataset for multi-lable data frames.

Currently getting this error when trying to fit the model @wgpubs Tried to construct a tensor from a int sequence, but found an item of type float at index (0)

Any ideas?

@jeremy … ping!

Finding some free time today to work on the new fastai.text package so if you have anything w/r/t building the datasets/dataloaders great … if not, no problem.


If you can post a gist of your actual code that would help. lmk.

Sure. Here’s the gist

More details available in the link I sent earlier. Didn’t want to hijack this thread, thats why i created another one.

Thanks in advance!

Documentation and sample scripts would be very welcome! I’ve not quite been able to assemble what is needed.