POS tagging using nltk takes time

﹥>﹥吖頭↗ 提交于 2019-12-12 02:48:56

问题


I am trying to get POS tags using nltk, i think it should take less then or around 1 sencond for processing small text. But 2-3 sentence it takes 20-25 second.

import nltk,re, time
def findPos( text):
    start_time = time.time()
    try:
        tokens = nltk.word_tokenize(text)
        pos_tags = nltk.pos_tag(tokens)
        print [ x[0] for x in pos_tags if x[1] == "NN" or "NNP"]
    except Exception:
        import traceback
        traceback.format_exc()
    print("--- %s seconds ---" % (time.time() - start_time))

findPos(raw_input())

Any suggestion how to reduce time ere?

来源:https://stackoverflow.com/questions/33558836/pos-tagging-using-nltk-takes-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!