Shai
(Shai H)
July 11, 2018, 6:14am
1
Hi,
I’m training ULMFiT text classification models for a few topics. They seem to be performing quite well on the validation data, so I’d like to wrap them in a small webapp that’d get a new text document as input and will output the models’ prediction. However, I’m can’t call the models’ forward function on a new tensor variable.
The code I’m using (this is reusing the validation data, just to mock a new document):
m = get_rnn_classifer(bptt, 20*70, c, vs, emb_sz=em_sz, n_hid=nh, n_layers=nl, pad_token=1,
layers=[em_sz*3, 50, c], drops=[dps[4], 0.1],
dropouti=dps[0], wdrop=dps[1], dropoute=dps[2], dropouth=dps[3])
opt_fn = partial(optim.Adam, betas=(0.7, 0.99))
learn = RNN_Learner(md, TextModel(to_gpu(m)), opt_fn=opt_fn)
learn.reg_fn = partial(seq2seq_reg, alpha=2, beta=1)
learn.clip=25.
learn.metrics = [accuracy]
lr=3e-3
lrm = 2.6
lrs = np.array([lr/(lrm**4), lr/(lrm**3), lr/(lrm**2), lr/lrm, lr])
wd = 1e-7
wd = 0
learn.load_encoder('lm1_enc')
learn.load('clas_final')
idx = np.array(val_clas[i])[None]
idx = np.transpose(idx)
tensorIdx = VV(idx)
m.forward(tensorIdx)
but I get the following error message:
AttributeError: 'MultiBatchRNN' object has no attribute 'hidden'
Samuel
(Samuel)
July 11, 2018, 2:18pm
2
Please see
I’ve been trying to do (true/false) classification with ULMFit and I’ve had some trouble working out how to predict on just normal text (not loaded from a dataset). Or rather - I can get it to do something, but the predictions seem wrong.
So I thought I’d take the first row of the validation set and try to get it to predict the same result manually.
Here’s what I’m aiming for:
preds = learn.predict()
preds[0]
array([ 0.88123, -0.47445], dtype=float32)
Here’s my code:
# get the first row of…
I am using ULMfit for a regression task. After finetuning, and training the classifier, I want to make predictions on new data (that has been preprocessed the same way as the training data.)
I am trying to figure out which function to use:
I see: learn.predict, learn.predict_array, learn.predict_dl, learn.predict_with_targs.
Seems like most of these works with the dataset used to init RNN_Learner().
However, the size of the predicted array (from learn.predict) is larger than the size of the …
nickl
(Nick)
July 11, 2018, 10:48pm
3
To solve that AttributeError: 'MultiBatchRNN' object has no attribute 'hidden'
error I think you need to do learn.reset()
before the m.forward.
Some examples don’t have that, but they call learn.predict()
(which runs predictions against the validation set) calls reset() internally.
1 Like
Shai
(Shai H)
July 12, 2018, 5:26am
4
Thanks so much @Samuel and @nickl !
solved the problem by starting the inference part with:
m.eval()
m.reset()
1 Like
athena
(Apoorva Mehta)
July 12, 2018, 3:43pm
5
I just wanted to ask if ULMFiT can be used for classification of sentences based on my tags like experience, quotation, motivation, etc ?
Samuel
(Samuel)
July 13, 2018, 1:16am
6
@athena : Sure, as long as you have a training dataset.