Beispiel #1
0
def get_prediction(sentence):
    sentence = Datasets.normalize_string(sentence)
    sentence = tokenizer.tokenize(sentence)
    sentence = tokenizer.convert_tokens_to_ids(sentence)    
    sentence = [vocab['[CLS]']] + sentence + [vocab['[SEP]']]
    
    output = model(torch.tensor(sentence).unsqueeze(0))
    output_softmax = softmax(output)[0]
    max_out = label_list[output_softmax.argmax()]
    argidx = output_softmax.argsort(descending=True)
    result = {label_list[i]: round(output_softmax[i].item(), 3) for i in range(len(label_list))}
    sorted_result = {label_list[i]: round(output_softmax[i].item(), 3) for i in argidx}
    return max_out, result, sorted_result