Modules needed for DotProdNB

Hello, everyone! Hope it is the right place to ask this question.

I’m trying to replicate the code from Lecture 11 Embeddings (Practical Machine Learning for Coders) and stuck at part where Jeremy talks about DotProdNB algorithm. Can anyone please provide me the list of modules (and fastai version) that I need to import in order to run the following:

sl = 2000
md = TextClassifierData.from_bow(trn_term_doc, trn_y, val_term_doc, val_y, sl)

learner = md.dotprod_nb_learner()
learner.fit(0.02, 1, wds=1e-6, cycle_len=1)

So, to run the above code you need the fastai.nlp module from this repository: https://github.com/anandsaha/fastai.part1.v2

However, I was not able to run it using cuda (in Google Colab), facing following error:
“Runtimeerror: expected object of device type cuda but got device type cpu for argument #3 ‘index’ in call to _th_index_select”

So, I modified the the script slightly (deleted to_gpu() in two spots).

Then following error appeared:
“indexerror: invalid index of a 0-dim tensor. use tensor.item() to convert a 0-dim tensor to a python number”

Found solution here:

After all I managed to get the same results as Jeremy :slight_smile: