def predict_section(classifier, sentence): """ Given an input section :param classifier Classifier to use for prediction :param sentence Sentence to run prediction on :return Return predicted section """ feature_vector = build_feature_vector(sentence) return classifier.predict(feature_vector)
def build_classifier(): """Build and pickle the classifier.""" classes = sections feature_data = [(tag, build_feature_vector(s)) for (tag, s) in queries] classifier = MultiClassPerceptron(classes, feature_list, feature_data, train_test_ratio=1) classifier.train() with open("classifier.pik", 'wb') as f: pickle.dump(classifier, f, pickle.HIGHEST_PROTOCOL)