def predict(self):
    print('Predicting ...')
    result_folder = '{}/test_result'.format(self.model_folder)
    if (not os.path.exists(result_folder)):
        os.makedirs(result_folder)
    utter_fname = '{}/utter.txt'.format(result_folder)
    if (not os.path.exists(utter_fname)):
        utter_txt = self.test_data.userUtter_txt
        writeTxt(utter_txt, utter_fname, prefix='', delimiter=None)
    print('\ttest_utter={}'.format(utter_fname))
    X_test = self.test_data.userUtter_encodePad
    (tag_probs, intent_probs) = self.model.predict(X_test)
    if self.test_intent_flag:
        assert (self.threshold is not None), 'Argument required: --threshold'
        intent_probs_fname = '{}/intentProb_{}.npz'.format(result_folder, os.path.basename(self.weights_fname).split('_')[0])
        np.savez_compressed(intent_probs_fname, probs=intent_probs)
        print('\tintent_probs={}'.format(intent_probs_fname))
        pred_intent_fname = '{}/intent_{}.pred'.format(result_folder, os.path.basename(self.weights_fname).split('_')[0])
        pred_intent_txt = getActPred(intent_probs, self.threshold, self.id2userIntent)
        writeTxt(pred_intent_txt, pred_intent_fname, prefix='intent-', delimiter=';')
        print('\tintent_pred={}'.format(pred_intent_fname))
        target_intent_fname = '{}/intent_test.target'.format(result_folder)
        target_intent = self.test_data.userIntent_txt
        writeTxt(target_intent, target_intent_fname, prefix='intent-', delimiter=';')
        print('\tintent_target={}'.format(target_intent_fname))
        (preds_indicator, precision, recall, fscore, accuracy_frame) = eval_actPred(intent_probs, self.test_data.userIntent_vecBin, self.threshold)
        print('IntentPred: precision={:.4f}, recall={:.4f}, fscore={:.4f}, accuracy_frame={:.4f}'.format(precision, recall, fscore, accuracy_frame))
    if self.test_tag_flag:
        tag_probs_fname = '{}/tagProb_{}.npz'.format(result_folder, os.path.basename(self.weights_fname).split('_')[0])
        np.savez_compressed(tag_probs_fname, probs=tag_probs)
        print('\ttag_probs={}'.format(tag_probs_fname))
        pred_tag_fname = '{}/tag_{}.pred'.format(result_folder, os.path.basename(self.weights_fname).split('_')[0])
        mask_test = np.zeros_like(X_test)
        mask_test[(X_test != 0)] = 1
        pred_tag_txt = getTagPred(tag_probs, mask_test, self.id2userTag)
        writeTxt(pred_tag_txt, pred_tag_fname, prefix='tag-', delimiter=None)
        print('\ttag_pred={}'.format(pred_tag_fname))
        target_tag_fname = '{}/tag_test.target'.format(result_folder)
        target_tag = self.test_data.userTag_txt
        writeTxt(target_tag, target_tag_fname, prefix='tag-', delimiter=None)
        print('\ttag_target={}'.format(target_tag_fname))
        (precision, recall, fscore, accuracy_frame) = eval_slotTagging(tag_probs, mask_test, self.test_data.userTag_1hotPad, self.userTag2id['tag-O'])
        print('SlotTagging: precision={:.4f}, recall={:.4f}, fscore={:.4f}, accuracy_frame={:.4f}'.format(precision, recall, fscore, accuracy_frame))
def predict(self):
    print('Predicting ...')
    result_folder = '{}/test_result'.format(self.model_folder)
    if (not os.path.exists(result_folder)):
        os.makedirs(result_folder)
    utter_fname = '{}/utter.txt'.format(result_folder)
    if (not os.path.exists(utter_fname)):
        utter_txt = self.test_data.userUtter_txt
        writeTxt(utter_txt, utter_fname, prefix=, delimiter=None)
    print('\ttest_utter={}'.format(utter_fname))
    X_test = self.test_data.userUtter_encodePad
    (tag_probs, intent_probs) = self.model.predict(X_test)
    if self.test_intent_flag:
        assert (self.threshold is not None), 'Argument required: --threshold'
        intent_probs_fname = '{}/intentProb_{}.npz'.format(result_folder, os.path.basename(self.weights_fname).split('_')[0])
        np.savez_compressed(intent_probs_fname, probs=intent_probs)
        print('\tintent_probs={}'.format(intent_probs_fname))
        pred_intent_fname = '{}/intent_{}.pred'.format(result_folder, os.path.basename(self.weights_fname).split('_')[0])
        pred_intent_txt = getActPred(intent_probs, self.threshold, self.id2userIntent)
        writeTxt(pred_intent_txt, pred_intent_fname, prefix='intent-', delimiter=';')
        print('\tintent_pred={}'.format(pred_intent_fname))
        target_intent_fname = '{}/intent_test.target'.format(result_folder)
        target_intent = self.test_data.userIntent_txt
        writeTxt(target_intent, target_intent_fname, prefix='intent-', delimiter=';')
        print('\tintent_target={}'.format(target_intent_fname))
        (preds_indicator, precision, recall, fscore, accuracy_frame) = eval_actPred(intent_probs, self.test_data.userIntent_vecBin, self.threshold)
        print('IntentPred: precision={:.4f}, recall={:.4f}, fscore={:.4f}, accuracy_frame={:.4f}'.format(precision, recall, fscore, accuracy_frame))
    if self.test_tag_flag:
        tag_probs_fname = '{}/tagProb_{}.npz'.format(result_folder, os.path.basename(self.weights_fname).split('_')[0])
        np.savez_compressed(tag_probs_fname, probs=tag_probs)
        print('\ttag_probs={}'.format(tag_probs_fname))
        pred_tag_fname = '{}/tag_{}.pred'.format(result_folder, os.path.basename(self.weights_fname).split('_')[0])
        mask_test = np.zeros_like(X_test)
        mask_test[(X_test != 0)] = 1
        pred_tag_txt = getTagPred(tag_probs, mask_test, self.id2userTag)
        writeTxt(pred_tag_txt, pred_tag_fname, prefix='tag-', delimiter=None)
        print('\ttag_pred={}'.format(pred_tag_fname))
        target_tag_fname = '{}/tag_test.target'.format(result_folder)
        target_tag = self.test_data.userTag_txt
        writeTxt(target_tag, target_tag_fname, prefix='tag-', delimiter=None)
        print('\ttag_target={}'.format(target_tag_fname))
        (precision, recall, fscore, accuracy_frame) = eval_slotTagging(tag_probs, mask_test, self.test_data.userTag_1hotPad, self.userTag2id['tag-O'])
        print('SlotTagging: precision={:.4f}, recall={:.4f}, fscore={:.4f}, accuracy_frame={:.4f}'.format(precision, recall, fscore, accuracy_frame))