spacy-自然语言处理框架

Spacy

@(学习笔记)

What’s spaCy ?

spaCy is a free, open-source library for advanced Natural Language Processing (NLP) in Python.

spaCy是一个免费的开源库,用于Python中的高级自然语言处理(NLP)。

What spaCy isn’t ?

  • spaCy is not a platform or “an API”. Unlike a platform, spaCy does not provide a software as a service, or a web application. It’s an open-source library designed to help you build NLP applications, not a consumable service.
  • spaCy is not an out-of-the-box chat bot engine. While spaCy can be used to power conversational applications, it’s not designed specifically for chat bots, and only provides the underlying text processing capabilities.
  • spaCy is not research software. It’s built on the latest research, but it’s designed to get things done. This leads to fairly different design decisions than NLTK or CoreNLP, which were created as platforms for teaching and research. The main difference is that spaCy is integrated and opinionated. spaCy tries to avoid asking the user to choose between multiple algorithms that deliver equivalent functionality. Keeping the menu small lets spaCy deliver generally better performance and developer experience.

它建立在最新研究的基础上,但它的设计是为了完成任务。这导致了与作为教学和研究平台而创建的NLTK或CORENLP相比,设计决策有很大的不同。主要的区别在于spaCy是完整的和固定的。Spacy试图避免要求用户在提供等效功能的多个算法之间进行选择。保持菜单小,让Spacy提供更好的性能和开发人员体验。

  • spaCy is not a company. It’s an open-source library. Our company publishing spaCy and other software is called Explosion AI.

Features

NAMEDESCRIPTION
TokenizationSegmenting text into words, punctuations marks etc.
Part-of-speech (POS) TaggingAssigning word types to tokens, like verb or noun.
Dependency ParsingAssigning syntactic dependency labels, describing the relations between individual tokens, like subject or object.(分配语法依赖标签,描述各个标记之间的关系,如主题或对象)
Lemmatization(词形还原)Assigning the base forms of words. For example, the lemma of “was” is “be”, and the lemma of “rats” is “rat”.
Sentence Boundary Detection (SBD) (句子边界检测)Finding and segmenting individual sentences.(查找和分割单个句子,实际上就是分句)
Named Entity Recognition (NER)Labelling named “real-world” objects, like persons, companies or locations.
SimilarityComparing words, text spans and documents and how similar they are to each other.(比较单词,文本跨度和文档以及它们彼此之间的相似程度。)
Text ClassificationAssigning categories or labels to a whole document, or parts of a document.(为整个文档或文档的某些部分分配类别或标签。)
Rule-based MatchingFinding sequences of tokens based on their texts and linguistic annotations, similar to regular expressions.
Training Updating and improving a statistical model’s predictions.
SerializationSaving objects to files or byte strings.

Architecture

@Architecture

spaCy中的中心数据结构是DocVocab。 Doc对象拥有标记序列及其所有注释。 Vocab对象拥有一组查找表,这些查找表可以跨文档提供公共信息。通过集中字符串,单词向量和词汇属性,我们避免存储此数据的多个副本。这样可以节省内存,并确保只有一个事实来源。

对象容器
  • Doc:用于访问语言注释的容器
  • Span:Doc对象的切片
  • Token:一个单独的标记——例如一个单词、标点符号、空格等
  • Lexeme:词汇表中的一个条目。它是一个没有上下文的单词类型,但是它不是一个单词标记。因此它没有词性标记、依赖解析等
处理管道
  • Language:一个文本处理管道。 通常你会为每次处理加载一次nlp,并在应用程序周围传递实例
  • Pipe:处理管道组件的基类
  • Tagger:在Doc对象上标注部分词性标记
  • DependencyParser:在Doc对象上标注句法依赖
  • EntityRecognizer:在Doc对象上标注命名实体,例如人物、产品等
  • TextCategorizer:为Doc对象分配类别或标签
  • Tokenizer:段文本,通过发现段边界创建Doc对象
  • Lemmatizer:确定单词的基本形式
  • Morphology:根据单词的词性和词性标记,分配语言特征,如引理,名词,动词时态等
  • Matcher:匹配相应的序列,基于模式规则,类似于正则表达式
  • PhraseMatcher:基于短语匹配相应的序列
其他类
  • Vocab:允许你查找Lexeme对象的词汇查找表
  • StringStore:字符串和hash值的映射
  • Vectrors:字符串转化为向量数据的容器类
  • GoldParse:训练标注的集合
  • GoldCorpus:一个标注好的语料库,使用json的格式。管理各种标注

关于spaCy的中文语言和分析模型测试

中文vocab使用的是80余万条新浪新闻(news.vec),通过fasttext生成的300dim的vector。
所有内容均为配合 https://www.jianshu.com/p/9bfbdb5dc487 系列文章。

The relationship between Rasa and Spacy

@rasa 和 spacy的关系

Spacy 的中文模型

  • 方式一:训练自己的模型

    • vocab模型(词向量模型),实际上是转换已有的模型
    • pos模型
    • ner模型
  • 方式二:使用他人的模型

    • 下载模型
      releases 页面下载模型 (New! 为中国地区的用户提供了加速下载的链接)。假设所下载的模型名为 zh_core_web_sm-2.x.x.tar.gz。

    • 安装模型

pip install zh_core_web_sm-2.x.x.tar.gz

为了方便后续在 Rasa NLU 等框架中使用,需要再为这个模型建立一个链接,执行以下命令:

spacy link zh_core_web_sm zh

Reference

  1. Spacy官网
  2. Spacy 官方api
  3. Spacy github
  4. Spacy中文模型一
  5. Spacy中文模型二
  • 3
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值