spaCy/website/usage/_models/_install.jade

184 lines
8.0 KiB
Plaintext
Raw Normal View History

2017-10-03 15:26:20 +03:00
//- 💫 DOCS > USAGE > MODELS > INSTALLATION
2017-03-16 23:53:31 +03:00
+aside("Downloading models in spaCy < v1.7")
| In older versions of spaCy, you can still use the old download commands.
| This will download and install the models into the #[code spacy/data]
| directory.
+code.o-no-block.
python -m spacy.en.download all
python -m spacy.de.download all
python -m spacy.en.download glove
2017-03-17 19:01:16 +03:00
| The old models are also #[+a(gh("spacy") + "/tree/v1.6.0") attached to the v1.6.0 release].
| To download and install them manually, unpack the archive, drop the
2017-05-22 14:55:01 +03:00
| contained directory into #[code spacy/data].
2017-03-16 23:53:31 +03:00
2017-10-03 15:26:20 +03:00
include _install-basics
2017-03-16 23:53:31 +03:00
+h(3, "download-pip") Installation via pip
p
2018-05-07 22:24:35 +03:00
| To download a model directly using #[+a("https://pypi.python.org/pypi/pip") pip],
| point #[code pip install] to the URL or local path of the archive
2017-03-16 23:53:31 +03:00
| file. To find the direct link to a model, head over to the
2017-03-17 00:09:43 +03:00
| #[+a(gh("spacy-models") + "/releases") model releases], right click on the archive
2017-03-16 23:53:31 +03:00
| link and copy it to your clipboard.
+code(false, "bash").
# with external URL
2018-05-07 22:24:35 +03:00
pip install #{gh("spacy-models")}/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz
2017-03-16 23:53:31 +03:00
# with local file
pip install /Users/you/en_core_web_md-1.2.0.tar.gz
p
| By default, this will install the model into your #[code site-packages]
| directory. You can then use #[code spacy.load()] to load it via its
| package name, create a #[+a("#usage-link") shortcut link] to assign it a
2017-11-06 15:20:36 +03:00
| custom name, or #[+a("#usage-import") import it] explicitly as a module.
2017-05-22 19:53:14 +03:00
| If you need to download models as part of an automated process, we
| recommend using pip with a direct link, instead of relying on spaCy's
| #[+api("cli#download") #[code download]] command.
2017-03-16 23:53:31 +03:00
2017-06-04 21:56:58 +03:00
+infobox
| You can also add the direct download link to your application's
2017-06-04 21:56:58 +03:00
| #[code requirements.txt]. For more details,
2017-10-03 15:26:20 +03:00
| see the section on
| #[+a("/models/#production") working with models in production].
2017-03-16 23:53:31 +03:00
+h(3, "download-manual") Manual download and installation
p
| In some cases, you might prefer downloading the data manually, for
| example to place it into a custom directory. You can download the model
2017-03-17 00:09:43 +03:00
| via your browser from the #[+a(gh("spacy-models")) latest releases], or configure
2017-03-16 23:53:31 +03:00
| your own download script using the URL of the archive file. The archive
| consists of a model directory that contains another directory with the
| model data.
+code("Directory structure", "yaml").
└── en_core_web_md-1.2.0.tar.gz # downloaded archive
├── meta.json # model meta data
├── setup.py # setup file for pip installation
2017-06-04 21:44:59 +03:00
└── en_core_web_md # 📦 model package
2017-03-16 23:53:31 +03:00
├── __init__.py # init for pip installation
├── meta.json # model meta data
└── en_core_web_md-1.2.0 # model data
p
2017-06-04 21:44:59 +03:00
| You can place the #[strong model package directory] anywhere on your
2018-05-07 22:24:35 +03:00
| local file system. To use it with spaCy, assign it a name by
2017-06-04 21:44:59 +03:00
| creating a #[+a("#usage") shortcut link] for the data directory.
2017-03-16 23:53:31 +03:00
2017-10-03 15:26:20 +03:00
+h(3, "usage") Using models with spaCy
2017-03-16 23:53:31 +03:00
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
2017-06-04 21:44:59 +03:00
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/en_core_web_sm') # load package from a directory
doc = nlp(u'This is a sentence.')
2017-05-22 14:55:01 +03:00
+infobox("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
2017-03-16 23:53:31 +03:00
p
| While previous versions of spaCy required you to maintain a data directory
| containing the models for each installation, you can now choose
| #[strong how and where you want to keep your data]. For example, you could
| download all models manually and put them into a local directory.
| Whenever your spaCy projects need a models, you create a shortcut link to
| 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.
2017-03-16 23:53:31 +03:00
2017-05-22 19:53:14 +03:00
+aside("Why does spaCy use symlinks?")
| Symlinks were originally introduced to maintain backwards compatibility,
| as older versions expected model data to live within #[code spacy/data].
| However, we decided to keep using them in v2.0 instead of opting for
| a config file. There'll always be a need for assigning and saving custom
| model names or IDs. And your system already comes with a native solution
| to mapping unicode aliases to file paths: symbolic links.
+code(false, "bash", "$").
python -m spacy link [package name or path] [shortcut] [--force]
2017-03-16 23:53:31 +03:00
p
2017-06-04 14:55:00 +03:00
| The first argument is the #[strong package name] (if the model was
| installed via pip), or a local path to the the #[strong model package].
| The second argument is the internal name you want to use for the model.
| Setting the #[code --force] flag will overwrite any existing links.
2017-03-16 23:53:31 +03:00
+code("Examples", "bash").
2017-03-17 01:23:35 +03:00
# set up shortcut link to load installed package as "en_default"
python -m spacy link en_core_web_md en_default
2017-03-16 23:53:31 +03:00
2017-03-17 00:09:43 +03:00
# set up shortcut link to load local model as "my_amazing_model"
python -m spacy link /Users/you/model my_amazing_model
2017-03-16 23:53:31 +03:00
+infobox("Important note", "⚠️")
2017-05-22 19:53:14 +03:00
| In order to create a symlink, your user needs the #[strong required permissions].
| If you've installed spaCy to a system directory and don't have admin
| 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
| info on this, see the
2017-10-03 15:26:20 +03:00
| #[+a("/usage/#symlink-privilege") troubleshooting guide].
2017-03-16 23:53:31 +03:00
+h(3, "usage-import") Importing models as modules
p
2017-05-22 19:53:14 +03:00
| If you've installed a model via spaCy's downloader, or directly via pip,
| you can also #[code import] it and then call its #[code load()] method
| with no arguments:
2017-03-16 23:53:31 +03:00
💫 Interactive code examples, spaCy Universe and various docs improvements (#2274) * Integrate Python kernel via Binder * Add live model test for languages with examples * Update docs and code examples * Adjust margin (if not bootstrapped) * Add binder version to global config * Update terminal and executable code mixins * Pass attributes through infobox and section * Hide v-cloak * Fix example * Take out model comparison for now * Add meta text for compat * Remove chart.js dependency * Tidy up and simplify JS and port big components over to Vue * Remove chartjs example * Add Twitter icon * Add purple stylesheet option * Add utility for hand cursor (special cases only) * Add transition classes * Add small option for section * Add thumb object for small round thumbnail images * Allow unset code block language via "none" value (workaround to still allow unset language to default to DEFAULT_SYNTAX) * Pass through attributes * Add syntax highlighting definitions for Julia, R and Docker * Add website icon * Remove user survey from navigation * Don't hide GitHub icon on small screens * Make top navigation scrollable on small screens * Remove old resources page and references to it * Add Universe * Add helper functions for better page URL and title * Update site description * Increment versions * Update preview images * Update mentions of resources * Fix image * Fix social images * Fix problem with cover sizing and floats * Add divider and move badges into heading * Add docstrings * Reference converting section * Add section on converting word vectors * Move converting section to custom section and fix formatting * Remove old fastText example * Move extensions content to own section Keep weird ID to not break permalinks for now (we don't want to rewrite URLs if not absolutely necessary) * Use better component example and add factories section * Add note on larger model * Use better example for non-vector * Remove similarity in context section Only works via small models with tensors so has always been kind of confusing * Add note on init-model command * Fix lightning tour examples and make excutable if possible * Add spacy train CLI section to train * Fix formatting and add video * Fix formatting * Fix textcat example description (resolves #2246) * Add dummy file to try resolve conflict * Delete dummy file * Tidy up [ci skip] * Ensure sufficient height of loading container * Add loading animation to universe * Update Thebelab build and use better startup message * Fix asset versioning * Fix typo [ci skip] * Add note on project idea label
2018-04-29 03:06:46 +03:00
+code-exec.
import en_core_web_sm
2017-03-16 23:53:31 +03:00
💫 Interactive code examples, spaCy Universe and various docs improvements (#2274) * Integrate Python kernel via Binder * Add live model test for languages with examples * Update docs and code examples * Adjust margin (if not bootstrapped) * Add binder version to global config * Update terminal and executable code mixins * Pass attributes through infobox and section * Hide v-cloak * Fix example * Take out model comparison for now * Add meta text for compat * Remove chart.js dependency * Tidy up and simplify JS and port big components over to Vue * Remove chartjs example * Add Twitter icon * Add purple stylesheet option * Add utility for hand cursor (special cases only) * Add transition classes * Add small option for section * Add thumb object for small round thumbnail images * Allow unset code block language via "none" value (workaround to still allow unset language to default to DEFAULT_SYNTAX) * Pass through attributes * Add syntax highlighting definitions for Julia, R and Docker * Add website icon * Remove user survey from navigation * Don't hide GitHub icon on small screens * Make top navigation scrollable on small screens * Remove old resources page and references to it * Add Universe * Add helper functions for better page URL and title * Update site description * Increment versions * Update preview images * Update mentions of resources * Fix image * Fix social images * Fix problem with cover sizing and floats * Add divider and move badges into heading * Add docstrings * Reference converting section * Add section on converting word vectors * Move converting section to custom section and fix formatting * Remove old fastText example * Move extensions content to own section Keep weird ID to not break permalinks for now (we don't want to rewrite URLs if not absolutely necessary) * Use better component example and add factories section * Add note on larger model * Use better example for non-vector * Remove similarity in context section Only works via small models with tensors so has always been kind of confusing * Add note on init-model command * Fix lightning tour examples and make excutable if possible * Add spacy train CLI section to train * Fix formatting and add video * Fix formatting * Fix textcat example description (resolves #2246) * Add dummy file to try resolve conflict * Delete dummy file * Tidy up [ci skip] * Ensure sufficient height of loading container * Add loading animation to universe * Update Thebelab build and use better startup message * Fix asset versioning * Fix typo [ci skip] * Add note on project idea label
2018-04-29 03:06:46 +03:00
nlp = en_core_web_sm.load()
2017-03-16 23:53:31 +03:00
doc = nlp(u'This is a sentence.')
2017-05-22 19:53:14 +03:00
p
| How you choose to load your models ultimately depends on personal
| preference. However, #[strong for larger code bases], we usually recommend
| native imports, as this will make it easier to integrate models with your
| existing build process, continuous integration workflow and testing
| framework. It'll also prevent you from ever trying to load a model that
| is not installed, as your code will raise an #[code ImportError]
| immediately, instead of failing somewhere down the line when calling
| #[code spacy.load()].
2017-06-04 21:56:58 +03:00
+infobox
2017-10-03 15:26:20 +03:00
| For more details, see the section on
| #[+a("/models/#production") working with models in production].
2017-06-04 21:56:58 +03:00
2017-10-03 15:26:20 +03:00
+h(3, "own-models") Using your own models
2017-03-16 23:53:31 +03:00
p
| If you've trained your own model, for example for
2017-10-03 15:26:20 +03:00
| #[+a("/usage/adding-languages") additional languages] or
| #[+a("/usage/training#ner") custom named entities], you can save its
| state using the #[+api("language#to_disk") #[code Language.to_disk()]]
| method. To make the model more convenient to deploy, we recommend
| wrapping it as a Python package.
+infobox("Saving and loading models")
| For more information and a detailed guide on how to package your model,
| see the documentation on
2017-10-03 15:26:20 +03:00
| #[+a("/usage/training#saving-loading") saving and loading models].