使用

import stanfordnlp
# stanfordnlp.download('zh') 从网络上下载模型文件,超级慢

zh_nlp = stanfordnlp.Pipeline(lang='zh', models_dir=r"D:\Data\NLP\model\stanfordnlp")

text = "清华大学是一所中国的一流大学。"

zh_doc = zh_nlp(text)

for i, sent in enumerate(zh_doc.sentences):
    print("[Sentence {}]".format(i+1))
    for word in sent.words:
        print("{:12s}\t{:12s}\t{:6s}\t{:d}\t{:12s}".format(\
              word.text, word.lemma, word.pos, word.governor, word.dependency_relation))
    print("")

首先应该先下载模型,然而如果是直接运行stanfordnlp.download('zh')命令,那么下载速度实在是太慢了,后来把它的源码下载下来,找到了对应了文件下载地址,然后使用Chrome下载,发现速度有所提升但是也很慢,最后尝试了一下先使用Xshell登录代理浏览器下载模型,然后使用Xftp将模型传输到本地,结果速度变快了好多,尤其是代理浏览器下载模型的速度超级快,达80M/s,太惊人了。

评论




博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议

本站使用 Volantis 作为主题,总访问量为
载入天数...载入时分秒...
冀ICP备20001334号