安装stanfordnlp以及简单使用

请注意:不是stanfordcorenlp
如果直接在CMD下,pip install stanfordnlp,我遇到了这个错误:在这里插入图片描述
于是我直接下载torch也遇到了错误,所以我在conda下,建立了一个虚拟环境,
conda create -n pytorch python=3.6 //创建虚拟环境
activate pytorch // 激活虚拟环境
conda install torch // 安装torch
由于我的电脑配置不高,没有下载GPU版本,经过一段时间的等待,下载完成之后。
pip install stanfordnlp (这里纯属试一下为什么一般的cmd不行, 然后就成功了)

stanfordnlp的起步很简单,官网也有相关的教程https://stanfordnlp.github.io/stanfordnlp/installation_usage.html#getting-started

import stanfordnlp
sentence = ""  # 句子
stanfordnlp.download("en")  # 你要下载的语言

然后会提示你是否下载语料包,输入y,然后定义语料包保存路径
经过一段时间的等待(反正我是等了很久)。
之后使用只需要:

import stanfordnlp
sentence = ""  # 句子
nlp = stanfordnlp.Pipeline(lang='en')
doc = nlp(sentence)
print(doc.sentences[0].print_dependencies())

# 如果要输出pos结果
print(word.upos for sent in doc.sentences for word in sent.words)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值