def classify():
idxs = [stoi[w.text] if stoi[w.text] > 0 else 0 for w in spacy_tok(text.lower())]
if -1 in idxs:
raise ValueError(f'stoi bug: {list(zip(idxs, spacy_tok(text.lower())))}')
preds = model(to_gpu(V(T([idxs])).transpose(0, 1)))[0]
top_i = preds.topk(1)[1].item()
if print_res:
print(f'\'{text}\' - {s_lbls[top_i]} ({top_i})')
return top_i
test_df = pd.read_csv(c_path / 'test.tsv', sep='\t')
test_phrases = test_df['Phrase']
sub = pd.read_csv(c_path / 'sampleSubmission.csv')
sub['Sentiment'] = [classify(learn.model, test_phrases[i], print_res=False) for i in range(len(test_phrases))]
sub.to_csv("submission.csv", index=False)
When trying to implement the above inference module on CPU, I am raised with an Implement error.
@sgugger Any help would be greatly appreciated. Thanks.