lstm = LSTM(emb.output, args.l2, args.hidden, num_words + 1, num_tags, args.num_features) emb.load(directory_model, varlist) lstm.load(directory_model, varlist) classify = th.function( inputs = [x], outputs = [lstm.y_pred, lstm.p_y_given_x]) print('#words: {}, #tags : {}, #hidden : {}, embedding size: {} '.format(\ len(reader.word_dict), len(reader.tag_dict), args.hidden, args.num_features)) print('>>> READY') while True: sent = input() coded = reader.codify_string(sent) coded_tags, probilities = classify(coded) tags = [reader.reverse_tag_dict[t] for t in coded_tags] sent = sent.split(' ') p = lambda s: ' '.join(["{:>14}".format(x) for x in s]) c = lambda x: x if ' O' in x else colored(x, 'green') cp = lambda s: ' '.join([c("{:>14}".format(x)) for x in s]) print('[INPUT] ' + p(sent)) print('[CODED] ' + p(coded)) print('[ TAG ] ' + p(coded_tags)) print('[UNTAG] ' + cp(tags)) print('[PROBS]') probs = [sorted([(p, reader.reverse_tag_dict[i]) for i,p in enumerate(w)])[-5:][::-1] for w in probilities] for w, p in zip(sent, probs):