mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
Update saving and loading docs
This commit is contained in:
parent
8aaed8bea7
commit
4f396236f6
|
@ -233,4 +233,4 @@ p
|
||||||
+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,
|
||||||
| see the documentation on
|
| see the documentation on
|
||||||
| #[+a("/docs/usage/saving-loading") saving and loading models].
|
| #[+a("/docs/usage/saving-loading#models") saving and loading models].
|
||||||
|
|
|
@ -10,6 +10,27 @@ include _spacy-101/_serialization
|
||||||
| overview of the changes, see #[+a("/docs/usage/v2#incompat") this table]
|
| overview of the changes, see #[+a("/docs/usage/v2#incompat") this table]
|
||||||
| and the notes on #[+a("/docs/usage/v2#migrating-saving-loading") migrating].
|
| and the notes on #[+a("/docs/usage/v2#migrating-saving-loading") migrating].
|
||||||
|
|
||||||
|
| save it locally by calling #[+api("doc#to_disk") #[code Doc.to_disk()]],
|
||||||
|
| and load it again via #[+api("doc#from_disk") #[code Doc.from_disk()]].
|
||||||
|
| This will overwrite the existing object and return it.
|
||||||
|
|
||||||
|
+code.
|
||||||
|
import spacy
|
||||||
|
from spacy.tokens import Span
|
||||||
|
|
||||||
|
text = u'Netflix is hiring a new VP of global policy'
|
||||||
|
|
||||||
|
nlp = spacy.load('en')
|
||||||
|
doc = nlp(text)
|
||||||
|
assert len(doc.ents) == 0 # Doc has no entities
|
||||||
|
doc.ents += ((Span(doc, 0, 1, label=doc.vocab.strings[u'ORG'])) # add entity
|
||||||
|
doc.to_disk('/path/to/doc') # save Doc to disk
|
||||||
|
|
||||||
|
new_doc = nlp(text)
|
||||||
|
assert len(new_doc.ents) == 0 # new Doc has no entities
|
||||||
|
new_doc = new_doc.from_disk('path/to/doc') # load from disk and overwrite
|
||||||
|
assert len(new_doc.ents) == 1 # entity is now recognised!
|
||||||
|
assert [(ent.text, ent.label_) for ent in new_doc.ents] == [(u'Netflix', u'ORG')]
|
||||||
|
|
||||||
+h(2, "models") Saving models
|
+h(2, "models") Saving models
|
||||||
|
|
||||||
|
@ -46,13 +67,16 @@ p
|
||||||
+aside-code("meta.json", "json").
|
+aside-code("meta.json", "json").
|
||||||
{
|
{
|
||||||
"name": "example_model",
|
"name": "example_model",
|
||||||
"lang": "en",
|
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"spacy_version": ">=2.0.0,<3.0.0",
|
"spacy_version": ">=2.0.0,<3.0.0",
|
||||||
"description": "Example model for spaCy",
|
"description": "Example model for spaCy",
|
||||||
"author": "You",
|
"author": "You",
|
||||||
"email": "you@example.com",
|
"email": "you@example.com",
|
||||||
"license": "CC BY-SA 3.0"
|
"license": "CC BY-SA 3.0",
|
||||||
|
"setup": {
|
||||||
|
"lang": "en",
|
||||||
|
"pipeline": ["token_vectors", "tagger"]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+code(false, "bash").
|
+code(false, "bash").
|
||||||
|
@ -71,10 +95,10 @@ p This command will create a model package directory that should look like this:
|
||||||
|
|
||||||
p
|
p
|
||||||
| You can also find templates for all files in our
|
| You can also find templates for all files in our
|
||||||
| #[+src(gh("spacy-dev-resouces", "templates/model")) spaCy dev resources].
|
| #[+src(gh("spacy-dev-resources", "templates/model")) spaCy dev resources].
|
||||||
| If you're creating the package manually, keep in mind that the directories
|
| If you're creating the package manually, keep in mind that the directories
|
||||||
| need to be named according to the naming conventions of
|
| need to be named according to the naming conventions of
|
||||||
| #[code [language]_[name]] and #[code [language]_[name]-[version]]. The
|
| #[code lang_name] and #[code lang_name-version].
|
||||||
| #[code lang] setting in the meta.json is also used to create the
|
| #[code lang] setting in the meta.json is also used to create the
|
||||||
| respective #[code Language] class in spaCy, which will later be returned
|
| respective #[code Language] class in spaCy, which will later be returned
|
||||||
| by the model's #[code load()] method.
|
| by the model's #[code load()] method.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user