2018-01-06-inroduction-for-spacy

spaCy是一款强大的自然语言处理工具包,支持词性标注、命名实体识别、依存句法分析等功能,适用于多种操作系统。本文介绍如何通过pip或conda安装spaCy,并提供英语等多语言模型的下载指南,涵盖词典、语法、实体识别及词向量等功能。
titlecategorylayouttagsdate
spaCy的简易教程
nlp
post
spacy
nlp
2018-01-06 14:30:24

spaCy是一个NLP工具包用于完成NLP领域的很多任务比如词性标注,命名实体识别,依存句法分析,归一化,停用词,判断是否词语等,支持Unix/Linux,macOS/os X和Windows操作系统,可以通过pip,conda方式安装。

pip:

pip install -U spacy

conda:

conda install -c conda-forge spacy

支持的语言:

|NAME |LANGUAGE |TYPE |--|--| |en_core_web_sm |English |Vocabulary, syntax, entities| |en_core_web_md |English |Vocabulary, syntax, entities, vectors| |en_core_web_lg |English |Vocabulary, syntax, entities, vectors| |en_vectors_web_lg |English |Word vectors| |de_core_news_sm| German |Vocabulary, syntax, entities| |es_core_news_sm| Spanish |Vocabulary, syntax, entities| |es_core_news_md| Spanish |Vocabulary, syntax, entities, vectors| |pt_core_news_sm| Portuguese| Vocabulary, syntax, entities| |fr_core_news_sm| French |Vocabulary, syntax, entities| |fr_core_news_md| French |Vocabulary, syntax, entities, vectors| |it_core_news_sm| Italian |Vocabulary, syntax, entities| |nl_core_news_sm| Dutch |Vocabulary, syntax, entities| |xx_ent_wiki_sm |Multi-language |Named entities|

语言模型

语言模型的安装:

#命令行
python -m spacy download xx #xx表示上面表格中的的NAME
#pip
pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_md-1.2.0/en_core_web_md-1.2.0.tar.gz
#本地文件
pip install /Users/you/en_core_web_md-1.2.0.tar.gz

安装语言模型之后就可以在代码中使用了:

import spacy
nlp = spacy.load('en')                       # load model with shortcut link "en"
nlp = spacy.load('en_core_web_sm')           # load model package "en_core_web_sm"
nlp = spacy.load('/path/to/en_core_web_sm')  # load package from a directory

doc = nlp(u'This is a sentence.')

安装中如果遇到问题参考链接

用法

词性标注

doc = nlp(u'Apple is looking at buying U.K. startup for $1 billion')

for token in doc:
    print(token.text, token.lemma_, token.pos_, token.tag_, token.dep_,
          token.shape_, token.is_alpha, token.is_stop)

依存树

doc = nlp(u'Autonomous cars shift insurance liability toward manufacturers')
for token in doc:
    print(token.text, token.dep_, token.head.text, token.head.pos_,
          [child for child in token.children])

命名实体识别:

doc = nlp(u'Apple is looking at buying U.K. startup for $1 billion')

for ent in doc.ents:
    print(ent.text, ent.start_char, ent.end_char, ent.label_)

标签化:

for token in doc:
    print(token.text)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值