赞
踩
pip install spacy
python -m spacy download en
import spacy
spacy_en = spacy.load("en_core_web_sm")
def tokenize_en(text):
return [tok.text for tok in spacy_en.tokenizer(text)]
print(tokenize_en("Hello, my name is tom."))
运行结果:
['Hello', ',', 'my', 'name', 'is', 'tom', '.']
python -m spacy download zh_core_web_sm
import spacy
spacy_zh = spacy.load("zh_core_web_sm")
def tokenize_zh(text):
return [tok.text for tok in spacy_zh.tokenizer(text)]
print(tokenize_zh("你好,我的名字叫汤姆"))
运行结果:
['你好', ',', '我', '的', '名字', '叫', '汤姆']
官网上提供有三个中文模型:
zh_core_web_sm
zh_core_web_md
zh_core_web_lg
安装方式:
python -m spacy download zh_core_web_sm
python -m spacy download zh_core_web_md
python -m spacy download zh_core_web_lg
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。