seqlearn

来源:互联网 发布:python 查看变量大小 编辑:程序博客网 时间:2024/06/18 14:39

https://github.com/larsmans/seqlearn

"""Generic sequence prediction script using CoNLL format."""from __future__ import print_functionimport fileinputfrom glob import globimport sysfrom seqlearn.datasets import load_conllfrom seqlearn.evaluation import bio_f_scorefrom seqlearn.perceptron import StructuredPerceptronfrom sklearn.metrics import accuracy_scorefrom sklearn.externals import joblibif __name__ == "__main__":    X_train, y_train, lengths_train = load_conll(sys.argv[1], features, 100000, True)    #describe(X_train, lengths_train)    X_test, y_test, lengths_test = load_conll(sys.argv[2], features, 100000, True)    #describe(X_test, lengths_test)    clf = StructuredPerceptron(verbose=True, max_iter=5)    print("Training %s" % clf)    clf.fit(X_train, y_train, lengths_train)    joblib.dump(clf, 'trunk.pkl')    import time    xclf = joblib.load('trunk.pkl')    start = time.time()    y_pred = xclf.predict(X_test, lengths_test)    end = time.time()    print((end-start)*1000)    print("Accuracy: %.3f" % (100 * accuracy_score(y_test, y_pred)))

CoNLL format

load_conll

ref : http://larsmans.github.io/seqlearn/reference.html

StructuredPerceptron

joblib

0 0
原创粉丝点击