2017-05-17 10:00:11 +00:00
|
|
|
|
//- 💫 DOCS > USAGE > SPACY 101
|
|
|
|
|
|
|
|
|
|
include ../../_includes/_mixins
|
|
|
|
|
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+h(2, "features") Features
|
|
|
|
|
|
2017-05-26 11:17:48 +00:00
|
|
|
|
+under-construction
|
|
|
|
|
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+aside
|
|
|
|
|
| If one of spaCy's functionalities #[strong needs a model], it means that
|
|
|
|
|
| you need to have one our the available
|
|
|
|
|
| #[+a("/docs/usage/models") statistical models] installed. Models are used
|
|
|
|
|
| to #[strong predict] linguistic annotations – for example, if a word is
|
|
|
|
|
| a verb or a noun.
|
|
|
|
|
|
|
|
|
|
+table(["Name", "Description", "Needs model"])
|
|
|
|
|
+row
|
|
|
|
|
+cell #[strong Tokenization]
|
2017-05-28 14:41:01 +00:00
|
|
|
|
+cell Segmenting text into words, punctuations marks etc.
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+cell #[+procon("con")]
|
|
|
|
|
|
|
|
|
|
+row
|
2017-05-28 14:41:01 +00:00
|
|
|
|
+cell #[strong Part-of-speech] (POS) #[strong Tagging]
|
|
|
|
|
+cell Assigning word types to tokens, like verb or noun.
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+cell #[+procon("pro")]
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[strong Dependency Parsing]
|
|
|
|
|
+cell
|
2017-05-28 14:41:01 +00:00
|
|
|
|
| Assigning syntactic dependency labels, i.e. the relations between
|
|
|
|
|
| individual tokens.
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+cell #[+procon("pro")]
|
|
|
|
|
|
|
|
|
|
+row
|
2017-05-28 14:41:01 +00:00
|
|
|
|
+cell #[strong Sentence Boundary Detection] (SBD)
|
|
|
|
|
+cell Finding and segmenting individual sentences.
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+cell #[+procon("pro")]
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[strong Named Entity Recongition] (NER)
|
|
|
|
|
+cell
|
2017-05-28 14:41:01 +00:00
|
|
|
|
| Labelling named "real-world" objects, like persons, companies or
|
|
|
|
|
| locations.
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+cell #[+procon("pro")]
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[strong Rule-based Matching]
|
|
|
|
|
+cell
|
2017-05-28 14:41:01 +00:00
|
|
|
|
| Finding sequences of tokens based on their texts and linguistic
|
|
|
|
|
| annotations, similar to regular expressions.
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+cell #[+procon("con")]
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[strong Similarity]
|
|
|
|
|
+cell
|
2017-05-28 14:41:01 +00:00
|
|
|
|
| Comparing words, text spans and documents and how similar they
|
|
|
|
|
| are to each other.
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+cell #[+procon("pro")]
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[strong Training]
|
2017-05-28 14:41:01 +00:00
|
|
|
|
+cell Updating and improving a statistical model's predictions.
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+cell #[+procon("neutral")]
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[strong Serialization]
|
2017-05-28 14:41:01 +00:00
|
|
|
|
+cell Saving objects to files or byte strings.
|
2017-05-23 21:38:33 +00:00
|
|
|
|
+cell #[+procon("neutral")]
|
|
|
|
|
|
2017-05-23 21:37:51 +00:00
|
|
|
|
+h(2, "annotations") Linguistic annotations
|
|
|
|
|
|
|
|
|
|
p
|
2017-05-28 14:41:01 +00:00
|
|
|
|
| spaCy provides a variety of linguistic annotations to give you
|
|
|
|
|
| #[strong insights into a text's grammatical structure]. This includes the
|
|
|
|
|
| word types, like the parts of speech, and how the words are related to
|
|
|
|
|
| each other. For example, if you're analysing text, it makes a huge
|
|
|
|
|
| difference whether a noun is the subject of a sentence, or the object –
|
|
|
|
|
| or whether "google" is used as a verb, or refers to the website or
|
|
|
|
|
| company in a specific context.
|
2017-05-23 21:37:51 +00:00
|
|
|
|
|
|
|
|
|
p
|
|
|
|
|
| Once you've downloaded and installed a #[+a("/docs/usage/models") model],
|
|
|
|
|
| you can load it via #[+api("spacy#load") #[code spacy.load()]]. This will
|
|
|
|
|
| return a #[code Language] object contaning all components and data needed
|
|
|
|
|
| to process text. We usually call it #[code nlp]. Calling the #[code nlp]
|
|
|
|
|
| object on a string of text will return a processed #[code Doc]:
|
|
|
|
|
|
|
|
|
|
+code.
|
|
|
|
|
import spacy
|
|
|
|
|
|
|
|
|
|
nlp = spacy.load('en')
|
|
|
|
|
doc = nlp(u'Apple is looking at buying U.K. startup for $1 billion')
|
|
|
|
|
|
2017-05-25 09:17:21 +00:00
|
|
|
|
p
|
|
|
|
|
| Even though a #[code Doc] is processed – e.g. split into individual words
|
|
|
|
|
| and annotated – it still holds #[strong all information of the original text],
|
|
|
|
|
| like whitespace characters. This way, you'll never lose any information
|
|
|
|
|
| when processing text with spaCy.
|
|
|
|
|
|
2017-05-23 21:37:51 +00:00
|
|
|
|
+h(3, "annotations-token") Tokenization
|
|
|
|
|
|
|
|
|
|
include _spacy-101/_tokenization
|
|
|
|
|
|
2017-05-26 10:46:29 +00:00
|
|
|
|
+infobox
|
2017-05-27 22:03:31 +00:00
|
|
|
|
| To learn more about how spaCy's tokenization rules work in detail,
|
|
|
|
|
| how to #[strong customise and replace] the default tokenizer and how to
|
|
|
|
|
| #[strong add language-specific data], see the usage guides on
|
|
|
|
|
| #[+a("/docs/usage/adding-languages") adding languages] and
|
2017-05-26 10:46:29 +00:00
|
|
|
|
| #[+a("/docs/usage/customizing-tokenizer") customising the tokenizer].
|
2017-05-23 21:37:51 +00:00
|
|
|
|
|
|
|
|
|
+h(3, "annotations-pos-deps") Part-of-speech tags and dependencies
|
|
|
|
|
+tag-model("dependency parse")
|
|
|
|
|
|
|
|
|
|
include _spacy-101/_pos-deps
|
|
|
|
|
|
2017-05-26 10:46:29 +00:00
|
|
|
|
+infobox
|
|
|
|
|
| To learn more about #[strong part-of-speech tagging] and rule-based
|
|
|
|
|
| morphology, and how to #[strong navigate and use the parse tree]
|
|
|
|
|
| effectively, see the usage guides on
|
|
|
|
|
| #[+a("/docs/usage/pos-tagging") part-of-speech tagging] and
|
|
|
|
|
| #[+a("/docs/usage/dependency-parse") using the dependency parse].
|
|
|
|
|
|
2017-05-23 21:37:51 +00:00
|
|
|
|
+h(3, "annotations-ner") Named Entities
|
|
|
|
|
+tag-model("named entities")
|
|
|
|
|
|
|
|
|
|
include _spacy-101/_named-entities
|
|
|
|
|
|
2017-05-26 10:46:29 +00:00
|
|
|
|
+infobox
|
|
|
|
|
| To learn more about entity recognition in spaCy, how to
|
2017-05-27 23:30:12 +00:00
|
|
|
|
| #[strong add your own entities] to a document and how to
|
|
|
|
|
| #[strong train and update] the entity predictions of a model, see the
|
|
|
|
|
| usage guides on
|
|
|
|
|
| #[+a("/docs/usage/entity-recognition") named entity recognition] and
|
|
|
|
|
| #[+a("/docs/usage/training-ner") training the named entity recognizer].
|
2017-05-26 10:46:29 +00:00
|
|
|
|
|
2017-05-23 21:37:51 +00:00
|
|
|
|
+h(2, "vectors-similarity") Word vectors and similarity
|
|
|
|
|
+tag-model("vectors")
|
|
|
|
|
|
|
|
|
|
include _spacy-101/_similarity
|
|
|
|
|
|
|
|
|
|
include _spacy-101/_word-vectors
|
|
|
|
|
|
2017-05-26 10:46:29 +00:00
|
|
|
|
+infobox
|
|
|
|
|
| To learn more about word vectors, how to #[strong customise them] and
|
|
|
|
|
| how to load #[strong your own vectors] into spaCy, see the usage
|
|
|
|
|
| guide on
|
|
|
|
|
| #[+a("/docs/usage/word-vectors-similarities") using word vectors and semantic similarities].
|
|
|
|
|
|
2017-05-23 21:37:51 +00:00
|
|
|
|
+h(2, "pipelines") Pipelines
|
|
|
|
|
|
2017-05-24 17:25:13 +00:00
|
|
|
|
include _spacy-101/_pipelines
|
|
|
|
|
|
2017-05-26 10:46:29 +00:00
|
|
|
|
+infobox
|
|
|
|
|
| To learn more about #[strong how processing pipelines work] in detail,
|
|
|
|
|
| how to enable and disable their components, and how to
|
|
|
|
|
| #[strong create your own], see the usage guide on
|
|
|
|
|
| #[+a("/docs/usage/language-processing-pipeline") language processing pipelines].
|
|
|
|
|
|
2017-05-28 16:29:16 +00:00
|
|
|
|
+h(2, "vocab") Vocab, hashes and lexemes
|
2017-05-26 10:45:01 +00:00
|
|
|
|
|
2017-05-28 14:37:14 +00:00
|
|
|
|
include _spacy-101/_vocab
|
2017-05-26 10:45:01 +00:00
|
|
|
|
|
2017-05-24 17:24:40 +00:00
|
|
|
|
+h(2, "serialization") Serialization
|
|
|
|
|
|
|
|
|
|
include _spacy-101/_serialization
|
|
|
|
|
|
2017-05-26 10:46:29 +00:00
|
|
|
|
+infobox
|
|
|
|
|
| To learn more about #[strong serialization] and how to
|
|
|
|
|
| #[strong save and load your own models], see the usage guide on
|
|
|
|
|
| #[+a("/docs/usage/saving-loading") saving, loading and data serialization].
|
|
|
|
|
|
2017-05-25 09:18:02 +00:00
|
|
|
|
+h(2, "training") Training
|
|
|
|
|
|
|
|
|
|
include _spacy-101/_training
|
|
|
|
|
|
2017-05-17 10:00:11 +00:00
|
|
|
|
+h(2, "architecture") Architecture
|
|
|
|
|
|
2017-05-26 11:17:48 +00:00
|
|
|
|
+under-construction
|
|
|
|
|
|
2017-05-17 10:00:11 +00:00
|
|
|
|
+image
|
|
|
|
|
include ../../assets/img/docs/architecture.svg
|
|
|
|
|
.u-text-right
|
|
|
|
|
+button("/assets/img/docs/architecture.svg", false, "secondary").u-text-tag View large graphic
|
2017-05-23 21:17:25 +00:00
|
|
|
|
|
|
|
|
|
+table(["Name", "Description"])
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("language") #[code Language]]
|
|
|
|
|
+cell
|
|
|
|
|
| A text-processing pipeline. Usually you'll load this once per
|
|
|
|
|
| process as #[code nlp] and pass the instance around your application.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("doc") #[code Doc]]
|
|
|
|
|
+cell A container for accessing linguistic annotations.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("span") #[code Span]]
|
|
|
|
|
+cell A slice from a #[code Doc] object.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("token") #[code Token]]
|
|
|
|
|
+cell
|
|
|
|
|
| An individual token — i.e. a word, punctuation symbol, whitespace,
|
|
|
|
|
| etc.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("lexeme") #[code Lexeme]]
|
|
|
|
|
+cell
|
|
|
|
|
| An entry in the vocabulary. It's a word type with no context, as
|
|
|
|
|
| opposed to a word token. It therefore has no part-of-speech tag,
|
|
|
|
|
| dependency parse etc.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("vocab") #[code Vocab]]
|
|
|
|
|
+cell
|
|
|
|
|
| A lookup table for the vocabulary that allows you to access
|
|
|
|
|
| #[code Lexeme] objects.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[code Morphology]
|
|
|
|
|
+cell
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("stringstore") #[code StringStore]]
|
|
|
|
|
+cell Map strings to and from integer IDs.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("tokenizer") #[code Tokenizer]]
|
|
|
|
|
+cell
|
|
|
|
|
| Segment text, and create #[code Doc] objects with the discovered
|
|
|
|
|
| segment boundaries.
|
|
|
|
|
|
2017-05-28 14:41:01 +00:00
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("matcher") #[code Matcher]]
|
|
|
|
|
+cell
|
|
|
|
|
| Match sequences of tokens, based on pattern rules, similar to
|
|
|
|
|
| regular expressions.
|
|
|
|
|
|
|
|
|
|
+h(3, "architecture-pipeline") Pipeline components
|
|
|
|
|
|
|
|
|
|
+table(["Name", "Description"])
|
2017-05-23 21:17:25 +00:00
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("tagger") #[code Tagger]]
|
|
|
|
|
+cell Annotate part-of-speech tags on #[code Doc] objects.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("dependencyparser") #[code DependencyParser]]
|
|
|
|
|
+cell Annotate syntactic dependencies on #[code Doc] objects.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("entityrecognizer") #[code EntityRecognizer]]
|
|
|
|
|
+cell
|
|
|
|
|
| Annotate named entities, e.g. persons or products, on #[code Doc]
|
|
|
|
|
| objects.
|
|
|
|
|
|
2017-05-28 14:41:01 +00:00
|
|
|
|
+h(3, "architecture-other") Other classes
|
|
|
|
|
|
|
|
|
|
+table(["Name", "Description"])
|
2017-05-23 21:17:25 +00:00
|
|
|
|
+row
|
2017-05-28 14:41:01 +00:00
|
|
|
|
+cell #[+api("binder") #[code Binder]]
|
2017-05-23 21:17:25 +00:00
|
|
|
|
+cell
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("goldparse") #[code GoldParse]]
|
|
|
|
|
+cell Collection for training annotations.
|
|
|
|
|
|
|
|
|
|
+row
|
|
|
|
|
+cell #[+api("goldcorpus") #[code GoldCorpus]]
|
|
|
|
|
+cell
|
|
|
|
|
| An annotated corpus, using the JSON file format. Manages
|
|
|
|
|
| annotations for tagging, dependency parsing and NER.
|