Load_learner on text data - None type not subscriptable

Thanks a bunch ! So this is how I got this working -
given a sentence x which I want to run inference on with a pre-trained model,

  1. cast is as a data frame df = pandas.DataFrame({‘text’ : x, ‘labels’ : ‘0’}). ‘labels’ is set to a dummy value
  2. tmplist=TextList.from_df(tra, ‘.’, cols=[‘text’], vocab=vocab) ## where the vocab is something I have already saved, and now load using Vocab.load(path)
  3. Convert tmp list to data bunch using your split_none suggestion
    db = tmplist.split_none().label_from_df(cols = ‘label’).databunch()
  4. db.train_dl = db.train_dl.new(shuffle=False). ## This I believe prevents shuffling of trains data as per How to set shuffle=False of train and val?
  5. classifier = load_learner(path, ‘xyz.pkl’, test = db) ## where xyz.pkl is the saved trained learner object
  6. preds = classifier.get_preds(ds_type=DatasetType.Test,ordered = True) ## ordered = True is important, otherwise the test data gets shuffled
  7. Also , another thing is this doesn’t work on inference for only one sample, because creating the data bunch object drops the last sample by default
    Closing this topic
2 Likes