Applying ULMfit on custom data

machine_learning
nlp

#1

I was trying to apply the following code

and I was successful running the code in its own but when I switched in my data there seems to be this error coming up. Any assistance will be appreciated.

data_lm_lab = TextLMDataBunch.from_csv('', 'text_data.csv')

learn = language_model_learner(data_lm_lab, pretrained_model=URLs.WT103, drop_mult=0.7)

learn.fit_one_cycle(1, 1e-2)

learn.save_encoder('ft_enc')

This is what the data looks like

Screenshot%20from%202018-12-07%2016-13-18

I get the following error

> /usr/local/lib/python3.6/dist-packages/fastai/basic_train.py in validate(model, dl, loss_func, cb_handler, pbar, average, n_batch)
>      55             if n_batch and (len(nums)>=n_batch): break
>      56         nums = np.array(nums, dtype=np.float32)
> ---> 57         if average: return (to_np(torch.stack(val_losses)) * nums).sum() / nums.sum()
>      58         else:       return val_losses
>      59 
> 
> RuntimeError: expected a non-empty list of Tensors

#2

Hi @m_jahangeer

Could you also share a sample of your dataset? It will help in solving this issue.

Regards,
Prateek


#3

Thanks mate heres a sample dataset

ulmfit.csv (48.3 KB)


#4

Hi @m_jahangeer

The code is working fine with your sample dataset. You can refer to the attached notebook.

ULMFiT_Text_Classification.zip (4.7 KB)


#5

Thanks a lot mate, but if I may what version of the fast ai library are you using?


#6

Never mind mate, Thanks a lot I got it to work, Many thanks mate.