spaCy/website/api/_top-level/_spacy.jade

160 lines
5.2 KiB
Plaintext
Raw Normal View History

2017-10-03 12:27:22 +00:00
//- 💫 DOCS > API > TOP-LEVEL > SPACY
2017-10-03 12:27:22 +00:00
+h(3, "spacy.load") spacy.load
+tag function
2017-05-20 23:12:43 +00:00
+tag-model
p
2017-10-03 12:27:22 +00:00
| Load a model via its #[+a("/usage/models#usage") shortcut link],
| the name of an installed
2017-10-03 12:27:22 +00:00
| #[+a("/usage/training#models-generating") model package], a unicode
| path or a #[code Path]-like object. spaCy will try resolving the load
2017-05-27 22:32:43 +00:00
| argument in this order. If a model is loaded from a shortcut link or
| package name, spaCy will assume it's a Python package and import it and
| call the model's own #[code load()] method. If a model is loaded from a
| path, spaCy will assume it's a data directory, read the language and
| pipeline settings off the meta.json and initialise the #[code Language]
| class. The data will be loaded in via
| #[+api("language#from_disk") #[code Language.from_disk()]].
+aside-code("Example").
nlp = spacy.load('en') # shortcut link
nlp = spacy.load('en_core_web_sm') # package
nlp = spacy.load('/path/to/en') # unicode path
nlp = spacy.load(Path('/path/to/en')) # pathlib Path
2017-05-27 22:32:43 +00:00
nlp = spacy.load('en', disable=['parser', 'tagger'])
+table(["Name", "Type", "Description"])
+row
+cell #[code name]
+cell unicode or #[code Path]
+cell Model to load, i.e. shortcut link, package name or path.
2017-05-23 21:14:02 +00:00
+row
2017-05-26 10:43:16 +00:00
+cell #[code disable]
+cell list
+cell
| Names of pipeline components to
2017-10-03 12:27:22 +00:00
| #[+a("/usage/processing-pipelines#disabling") disable].
2017-05-23 21:14:02 +00:00
2017-10-03 12:27:22 +00:00
+row("foot")
+cell returns
+cell #[code Language]
+cell A #[code Language] object with the loaded model.
2017-10-07 01:06:55 +00:00
p
| Essentially, #[code spacy.load()] is a convenience wrapper that reads
| the language ID and pipeline components from a model's #[code meta.json],
| initialises the #[code Language] class, loads in the model data and
| returns it.
+code("Abstract example").
cls = util.get_lang_class(lang) # get language for ID, e.g. 'en'
nlp = cls() # initialise the language
2017-10-07 01:06:55 +00:00
for name in pipeline:
component = nlp.create_pipe(name) # create each pipeline component
nlp.add_pipe(component) # add component to pipeline
nlp.from_disk(model_data_path) # load in model data
2017-11-07 11:00:43 +00:00
+infobox("Changed in v2.0", "⚠️")
2017-11-01 13:13:08 +00:00
| As of spaCy 2.0, the #[code path] keyword argument is deprecated. spaCy
| will also raise an error if no model could be loaded and never just
| return an empty #[code Language] object. If you need a blank language,
| you can use the new function #[+api("spacy#blank") #[code spacy.blank()]]
| or import the class explicitly, e.g.
| #[code from spacy.lang.en import English].
2017-05-26 10:43:16 +00:00
2017-11-01 13:13:08 +00:00
+code-wrapper
+code-new nlp = spacy.load('/model')
+code-old nlp = spacy.load('en', path='/model')
2017-05-26 10:43:16 +00:00
2017-10-03 12:27:22 +00:00
+h(3, "spacy.blank") spacy.blank
+tag function
+tag-new(2)
p
| Create a blank model of a given language class. This function is the
| twin of #[code spacy.load()].
+aside-code("Example").
nlp_en = spacy.blank('en')
nlp_de = spacy.blank('de')
+table(["Name", "Type", "Description"])
+row
+cell #[code name]
+cell unicode
2017-10-30 17:58:55 +00:00
+cell
| #[+a("https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes") ISO code]
| of the language class to load.
2017-10-03 12:27:22 +00:00
+row
+cell #[code disable]
+cell list
+cell
| Names of pipeline components to
| #[+a("/usage/processing-pipelines#disabling") disable].
+row("foot")
+cell returns
+cell #[code Language]
+cell An empty #[code Language] object of the appropriate subclass.
+h(4, "spacy.info") spacy.info
+tag function
p
| The same as the #[+api("cli#info") #[code info] command]. Pretty-print
| information about your installation, models and local setup from within
| spaCy. To get the model meta data as a dictionary instead, you can
| use the #[code meta] attribute on your #[code nlp] object with a
| loaded model, e.g. #[code nlp.meta].
+aside-code("Example").
spacy.info()
spacy.info('en')
spacy.info('de', markdown=True)
+table(["Name", "Type", "Description"])
+row
+cell #[code model]
+cell unicode
+cell A model, i.e. shortcut link, package name or path (optional).
+row
+cell #[code markdown]
+cell bool
+cell Print information as Markdown.
2017-10-03 12:27:22 +00:00
+h(3, "spacy.explain") spacy.explain
+tag function
p
| Get a description for a given POS tag, dependency label or entity type.
| For a list of available terms, see
2017-10-03 12:27:22 +00:00
| #[+src(gh("spacy", "spacy/glossary.py")) #[code glossary.py]].
+aside-code("Example").
2017-10-26 11:04:25 +00:00
spacy.explain(u'NORP')
# Nationalities or religious or political groups
doc = nlp(u'Hello world')
for word in doc:
print(word.text, word.tag_, spacy.explain(word.tag_))
# Hello UH interjection
# world NN noun, singular or mass
+table(["Name", "Type", "Description"])
+row
+cell #[code term]
+cell unicode
+cell Term to explain.
2017-10-03 12:27:22 +00:00
+row("foot")
+cell returns
+cell unicode
+cell The explanation, or #[code None] if not found in the glossary.