mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 02:06:31 +03:00
Add quickstart widget to models and update docs
Add global variable for models and generate all model listings programmatically
This commit is contained in:
parent
a87da31271
commit
cc569a348d
|
@ -80,6 +80,36 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
"QUICKSTART_MODELS": [
|
||||||
|
{ "id": "lang", "title": "Language", "options": [
|
||||||
|
{ "id": "en", "title": "English", "checked": true },
|
||||||
|
{ "id": "de", "title": "German" },
|
||||||
|
{ "id": "fr", "title": "French" }]
|
||||||
|
},
|
||||||
|
{ "id": "load", "title": "Loading style", "options": [
|
||||||
|
{ "id": "spacy", "title": "Use spacy.load()", "checked": true, "help": "Use spaCy's built-in loader to load the model by name." },
|
||||||
|
{ "id": "module", "title": "Import as module", "help": "Import the model explicitly as a Python module." }]
|
||||||
|
},
|
||||||
|
{ "id": "config", "title": "Options", "multiple": true, "options": [
|
||||||
|
{ "id": "example", "title": "Show usage example" }]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
"MODELS": {
|
||||||
|
"en": [
|
||||||
|
{ "id": "en_core_web_sm", "lang": "English", "feats": [1, 1, 1, 1], "size": "50 MB", "license": "CC BY-SA", "def": true },
|
||||||
|
{ "id": "en_core_web_md", "lang": "English", "feats": [1, 1, 1, 1], "size": "1 GB", "license": "CC BY-SA" },
|
||||||
|
{ "id": "en_depent_web_md", "lang": "English", "feats": [1, 1, 1, 0], "size": "328 MB", "license": "CC BY-SA" },
|
||||||
|
{ "id": "en_vectors_glove_md", "lang": "English", "feats": [1, 0, 0, 1], "size": "727 MB", "license": "CC BY-SA" }
|
||||||
|
],
|
||||||
|
"de": [
|
||||||
|
{ "id": "de_core_news_md", "lang": "German", "feats": [1, 1, 1, 1], "size": "645 MB", "license": "CC BY-SA" }
|
||||||
|
],
|
||||||
|
"fr": [
|
||||||
|
{ "id": "fr_depvec_web_lg", "lang": "French", "feats": [1, 1, 0, 1], "size": "1.33 GB", "license": "CC BY-NC" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
|
||||||
"ALPHA": true,
|
"ALPHA": true,
|
||||||
"V_CSS": "1.6",
|
"V_CSS": "1.6",
|
||||||
"V_JS": "1.2",
|
"V_JS": "1.2",
|
||||||
|
|
|
@ -44,7 +44,8 @@
|
||||||
|
|
||||||
"models": {
|
"models": {
|
||||||
"title": "Models",
|
"title": "Models",
|
||||||
"next": "lightning-tour"
|
"next": "lightning-tour",
|
||||||
|
"quickstart": true
|
||||||
},
|
},
|
||||||
|
|
||||||
"lightning-tour": {
|
"lightning-tour": {
|
||||||
|
|
|
@ -19,9 +19,6 @@ p
|
||||||
| View model releases
|
| View model releases
|
||||||
|
|
||||||
+table(["Name", "Language", "Voc", "Dep", "Ent", "Vec", "Size", "License"])
|
+table(["Name", "Language", "Voc", "Dep", "Ent", "Vec", "Size", "License"])
|
||||||
+model-row("en_core_web_sm", "English", [1, 1, 1, 1], "50 MB", "CC BY-SA", true)
|
for models, lang in MODELS
|
||||||
+model-row("en_core_web_md", "English", [1, 1, 1, 1], "1 GB", "CC BY-SA")
|
for model, i in models
|
||||||
+model-row("en_depent_web_md", "English", [1, 1, 1, 0], "328 MB", "CC BY-SA")
|
+model-row(model.id, model.lang, model.feats, model.size, model.license, model.def || models.length == 1, i == 0)
|
||||||
+model-row("en_vectors_glove_md", "English", [1, 0, 0, 1], "727 MB", "CC BY-SA")
|
|
||||||
+model-row("de_core_news_md", "German", [1, 1, 1, 1], "645 MB", "CC BY-SA", true, true)
|
|
||||||
+model-row("fr_depvec_web_lg", "French", [1, 1, 0, 1], "1.33 GB", "CC BY-NC", true, true)
|
|
||||||
|
|
|
@ -8,28 +8,26 @@ p
|
||||||
| other module. They're versioned and can be defined as a dependency in your
|
| other module. They're versioned and can be defined as a dependency in your
|
||||||
| #[code requirements.txt]. Models can be installed from a download URL or
|
| #[code requirements.txt]. Models can be installed from a download URL or
|
||||||
| a local directory, manually or via #[+a("https://pypi.python.org/pypi/pip") pip].
|
| a local directory, manually or via #[+a("https://pypi.python.org/pypi/pip") pip].
|
||||||
| Their data can be located anywhere on your file system. To make a model
|
| Their data can be located anywhere on your file system.
|
||||||
| available to spaCy, all you need to do is create a "shortcut link", an
|
|
||||||
| internal alias that tells spaCy where to find the data files for a specific
|
|
||||||
| model name.
|
|
||||||
|
|
||||||
+aside-code("Quickstart").
|
+aside("Important note")
|
||||||
# Install spaCy and download English model
|
| If you're upgrading to spaCy v1.7.x or v2.x, you need to
|
||||||
pip install spacy
|
| #[strong download the new models]. If you've trained statistical models
|
||||||
python -m spacy download en
|
| that use spaCy's annotations, you should #[strong retrain your models]
|
||||||
|
| after updating spaCy. If you don't retrain, you may suffer train/test
|
||||||
|
| skew, which might decrease your accuracy.
|
||||||
|
|
||||||
# Usage in Python
|
+quickstart(QUICKSTART_MODELS, "Quickstart", "Install a default model, get the code to load it from within spaCy and an example to test it. For more options, see the section on available models below.")
|
||||||
import spacy
|
- var examples = {en: "This is a sentence.", de: "Dies ist ein Satz.", fr: "C'est une phrase."}
|
||||||
nlp = spacy.load('en')
|
for models, lang in MODELS
|
||||||
doc = nlp(u'This is a sentence.')
|
- var package = (models.length == 1) ? models[0] : models.find(function(m) { return m.def })
|
||||||
|
+qs({lang: lang}) python -m spacy download #{lang}
|
||||||
+infobox("Important note")
|
+qs({lang: lang}, "divider")
|
||||||
| Due to improvements in the English lemmatizer in v1.7.0, you need to
|
+qs({lang: lang, load: "module"}, "python") import #{package.id}
|
||||||
| #[strong download the new English models]. The German model is still
|
+qs({lang: lang, load: "module"}, "python") nlp = #{package.id}.load()
|
||||||
| compatible. If you've trained statistical models that use spaCy's
|
+qs({lang: lang, load: "spacy"}, "python") nlp = spacy.load('#{lang}')
|
||||||
| annotations, you should #[strong retrain your models after updating spaCy].
|
+qs({lang: lang, config: "example"}, "python") doc = nlp(u"#{examples[lang]}")
|
||||||
| If you don't retrain your models, you may suffer train/test skew, which
|
+qs({lang: lang, config: "example"}, "python") print([(w.text, w.pos_) for w in doc])
|
||||||
| might decrease your accuracy.
|
|
||||||
|
|
||||||
+h(2, "available") Available models
|
+h(2, "available") Available models
|
||||||
|
|
||||||
|
@ -53,15 +51,14 @@ include _models-list
|
||||||
| #[code spacy.load('en')] or #[code spacy.load('de')].
|
| #[code spacy.load('en')] or #[code spacy.load('de')].
|
||||||
|
|
||||||
p
|
p
|
||||||
| The easiest way to download a model is via spaCy's #[code download]
|
| The easiest way to download a model is via spaCy's
|
||||||
| command. It takes care of finding the best-matching model compatible with
|
| #[+api("cli#download") #[code download]] command. It takes care of
|
||||||
| your spaCy installation.
|
| finding the best-matching model compatible with your spaCy installation.
|
||||||
|
|
||||||
|
- var models = Object.keys(MODELS).map(function(lang) { return "python -m spacy download " + lang })
|
||||||
+code(false, "bash").
|
+code(false, "bash").
|
||||||
# out-of-the-box: download best-matching default model
|
# out-of-the-box: download best-matching default model
|
||||||
python -m spacy download en
|
#{Object.keys(MODELS).map(function(l) {return "python -m spacy download " + l}).join('\n')}
|
||||||
python -m spacy download de
|
|
||||||
python -m spacy download fr
|
|
||||||
|
|
||||||
# download best-matching version of specific model for your spaCy installation
|
# download best-matching version of specific model for your spaCy installation
|
||||||
python -m spacy download en_core_web_md
|
python -m spacy download en_core_web_md
|
||||||
|
@ -72,8 +69,8 @@ p
|
||||||
p
|
p
|
||||||
| The download command will #[+a("#download-pip") install the model] via
|
| The download command will #[+a("#download-pip") install the model] via
|
||||||
| pip, place the package in your #[code site-packages] directory and create
|
| pip, place the package in your #[code site-packages] directory and create
|
||||||
| a #[+a("#usage") shortcut link] that lets you load the model by name. The
|
| a #[+a("#usage") shortcut link] that lets you load the model by a custom
|
||||||
| shortcut link will be the same as the model name used in
|
| name. The shortcut link will be the same as the model name used in
|
||||||
| #[code spacy.download].
|
| #[code spacy.download].
|
||||||
|
|
||||||
+code(false, "bash").
|
+code(false, "bash").
|
||||||
|
@ -103,9 +100,9 @@ p
|
||||||
|
|
||||||
p
|
p
|
||||||
| By default, this will install the model into your #[code site-packages]
|
| By default, this will install the model into your #[code site-packages]
|
||||||
| directory. You can then create a #[+a("#usage") shortcut link] for your
|
| directory. You can then use #[code spacy.load()] to load it via its
|
||||||
| model to load it via #[code spacy.load()], or #[+a("usage-import") import it]
|
| package name, create a #[+a("#usage-link") shortcut link] to assign it a
|
||||||
| as a Python module.
|
| custom name, or #[+a("usage-import") import it] explicitly as a module.
|
||||||
|
|
||||||
+h(3, "download-manual") Manual download and installation
|
+h(3, "download-manual") Manual download and installation
|
||||||
|
|
||||||
|
@ -133,13 +130,39 @@ p
|
||||||
|
|
||||||
+h(2, "usage") Using models with spaCy
|
+h(2, "usage") Using models with spaCy
|
||||||
|
|
||||||
|
p
|
||||||
|
| To load a model, use #[+api("spacy#load") #[code spacy.load()]] with the
|
||||||
|
| model's shortcut link, package name or a path to the data directory:
|
||||||
|
|
||||||
|
+code.
|
||||||
|
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/model') # load model from a directory
|
||||||
|
|
||||||
|
doc = nlp(u'This is a sentence.')
|
||||||
|
|
||||||
|
+aside("Tip: Preview model info")
|
||||||
|
| You can use the #[+api("cli#info") #[code info]] command or
|
||||||
|
| #[+api("spacy#info") #[code spacy.info()]] method to print a model's meta data
|
||||||
|
| before loading it. Each #[code Language] object with a loaded model also
|
||||||
|
| exposes the model's meta data as the attribute #[code meta]. For example,
|
||||||
|
| #[code nlp.meta['version']] will return the model's version.
|
||||||
|
|
||||||
|
+h(3, "usage-link") Using custom shortcut links
|
||||||
|
|
||||||
p
|
p
|
||||||
| While previous versions of spaCy required you to maintain a data directory
|
| While previous versions of spaCy required you to maintain a data directory
|
||||||
| containing the models for each installation, you can now choose how and
|
| containing the models for each installation, you can now choose
|
||||||
| where you want to keep your data files. To load the models conveniently
|
| #[strong how and where you want to keep your data]. For example, you could
|
||||||
| from within spaCy, you can use the #[code spacy.link] command to create a
|
| download all models manually and put them into a local directory.
|
||||||
| symlink. This lets you set up custom shortcut links for models so you can
|
| Whenever your spaCy projects need a models, you create a shortcut link to
|
||||||
| load them by name.
|
| tell spaCy to load it from there. This means you'll never end up with
|
||||||
|
| duplicate data.
|
||||||
|
|
||||||
|
p
|
||||||
|
| The #[+api("cli#link") #[code link]] command will create a symlink
|
||||||
|
| in the #[code spacy/data] directory.
|
||||||
|
|
||||||
+code(false, "bash").
|
+code(false, "bash").
|
||||||
python -m spacy link [package name or path] [shortcut] [--force]
|
python -m spacy link [package name or path] [shortcut] [--force]
|
||||||
|
@ -157,33 +180,13 @@ p
|
||||||
# set up shortcut link to load local model as "my_amazing_model"
|
# set up shortcut link to load local model as "my_amazing_model"
|
||||||
python -m spacy link /Users/you/model my_amazing_model
|
python -m spacy link /Users/you/model my_amazing_model
|
||||||
|
|
||||||
+h(3, "usage-loading") Loading models
|
+infobox("Important note")
|
||||||
|
| In order to create a symlink, your user needs the required permissions.
|
||||||
p
|
| If you've installed spaCy to a system directory and don't have admin
|
||||||
| To load a model, use #[code spacy.load()] with the model's shortcut link.
|
| privileges, the #[code spacy link] command may fail. The easiest solution
|
||||||
|
| is to re-run the command as admin, or use a #[code virtualenv]. For more
|
||||||
+code.
|
| info on this, see the
|
||||||
import spacy
|
| #[+a("/docs/usage/troubleshooting#symlink-privilege") troubleshooting guide].
|
||||||
nlp = spacy.load('en_default')
|
|
||||||
doc = nlp(u'This is a sentence.')
|
|
||||||
|
|
||||||
p
|
|
||||||
| You can also use the #[info] command or #[code info()] method to print a model's meta data
|
|
||||||
| before loading it. Each #[code Language] object returned by #[code spacy.load()]
|
|
||||||
| also exposes the model's meta data as the attribute #[code meta].
|
|
||||||
|
|
||||||
+code(false, "bash").
|
|
||||||
python -m spacy info en
|
|
||||||
# model meta data
|
|
||||||
|
|
||||||
+code.
|
|
||||||
import spacy
|
|
||||||
spacy.info('en_default')
|
|
||||||
# model meta data
|
|
||||||
|
|
||||||
nlp = spacy.load('en_default')
|
|
||||||
print(nlp.meta['version'])
|
|
||||||
# 1.2.0
|
|
||||||
|
|
||||||
+h(3, "usage-import") Importing models as modules
|
+h(3, "usage-import") Importing models as modules
|
||||||
|
|
||||||
|
@ -204,9 +207,9 @@ p
|
||||||
| If you've trained your own model, for example for
|
| If you've trained your own model, for example for
|
||||||
| #[+a("/docs/usage/adding-languages") additional languages] or
|
| #[+a("/docs/usage/adding-languages") additional languages] or
|
||||||
| #[+a("/docs/usage/train-ner") custom named entities], you can save its
|
| #[+a("/docs/usage/train-ner") custom named entities], you can save its
|
||||||
| state using the #[code Language.save_to_directory()] method. To make the
|
| state using the #[+api("language#to_disk") #[code Language.to_disk()]]
|
||||||
| model more convenient to deploy, we recommend wrapping it as a Python
|
| method. To make the model more convenient to deploy, we recommend
|
||||||
| package.
|
| wrapping it as a Python package.
|
||||||
|
|
||||||
+infobox("Saving and loading models")
|
+infobox("Saving and loading models")
|
||||||
| For more information and a detailed guide on how to package your model,
|
| For more information and a detailed guide on how to package your model,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user