diff --git a/website/usage/_training/_ner.jade b/website/usage/_training/_ner.jade index ed58c4c6f..12f92dbce 100644 --- a/website/usage/_training/_ner.jade +++ b/website/usage/_training/_ner.jade @@ -24,6 +24,58 @@ p | #[strong experiment on your own data] to find a solution that works best | for you. ++h(3, "example-train-ner") Updating the Named Entity Recognizer + +p + | This example shows how to update spaCy's entity recognizer + | with your own examples, starting off with an existing, pre-trained + | model, or from scratch using a blank #[code Language] class. To do + | this, you'll need #[strong example texts] and the + | #[strong character offsets] and #[strong labels] of each entity contained + | in the texts. + + +github("spacy", "examples/training/train_ner.py") + ++h(4) Step by step guide + ++list("numbers") + +item + | #[strong Reformat the training data] to match spaCy's + | #[+a("/api/annotation#json-input") JSON format]. The built-in + | #[+api("goldparse#biluo_tags_from_offsets") #[code biluo_tags_from_offsets]] + | function can help you with this. + + +item + | #[strong Load the model] you want to start with, or create an + | #[strong empty model] using + | #[+api("spacy#blank") #[code spacy.blank]] with the ID of your + | language. If you're using a blank model, don't forget to add the + | entity recognizer to the pipeline. If you're using an existing model, + | make sure to disable all other pipeline components during training + | using #[+api("language#disable_pipes") #[code nlp.disable_pipes]]. + | This way, you'll only be training the entity recognizer. + + +item + | #[strong Shuffle and loop over] the examples and create a + | #[code Doc] and #[code GoldParse] object for each example. + + +item + | For each example, #[strong update the model] + | by calling #[+api("language#update") #[code nlp.update]], which steps + | through the words of the input. At each word, it makes a + | #[strong prediction]. It then consults the annotations provided on the + | #[code GoldParse] instance, to see whether it was + | right. If it was wrong, it adjusts its weights so that the correct + | action will score higher next time. + + +item + | #[strong Save] the trained model using + | #[+api("language#to_disk") #[code nlp.to_disk]]. + + +item + | #[strong Test] the model to make sure the entities in the training + | data are recognised correctly. + +h(3, "example-new-entity-type") Training an additional entity type p @@ -38,22 +90,22 @@ p +github("spacy", "examples/training/train_new_entity_type.py") -p Training a new entity type requires the following steps: ++h(4) Step by step guide +list("numbers") +item - | Create #[+api("doc") #[code Doc]] and - | #[+api("goldparse") #[code GoldParse]] objects for + | Create #[code Doc] and #[code GoldParse] objects for | #[strong each example in your training data]. +item | #[strong Load the model] you want to start with, or create an | #[strong empty model] using - | #[+api("spacy#blank") #[code spacy.blank()]] with the ID of your - | language. If you're using an existing model, make sure to disable - | all other pipeline components during training using - | #[+api("language#disable_pipes") #[code nlp.disable_pipes]]. This way, - | you'll only be training the entity recognizer. + | #[+api("spacy#blank") #[code spacy.blank]] with the ID of your + | language. If you're using a blank model, don't forget to add the + | entity recognizer to the pipeline. If you're using an existing model, + | make sure to disable all other pipeline components during training + | using #[+api("language#disable_pipes") #[code nlp.disable_pipes]]. + | This way, you'll only be training the entity recognizer. +item | #[strong Add the new entity label] to the entity recognizer using the @@ -66,28 +118,14 @@ p Training a new entity type requires the following steps: | #[+api("language#update") #[code nlp.update]], which steps through | the words of the input. At each word, it makes a | #[strong prediction]. It then consults the annotations provided on the - | #[+api("goldparse") #[code GoldParse]] instance, to see whether it was - | right. If it was wrong, it adjusts its weights so that the correct - | action will score higher next time. + | #[code GoldParse] instance, to see whether it was right. If it was + | wrong, it adjusts its weights so that the correct action will score + | higher next time. +item | #[strong Save] the trained model using - | #[+api("language#to_disk") #[code nlp.to_disk()]]. + | #[+api("language#to_disk") #[code nlp.to_disk]]. +item - | #[strong Test] the model to make sure the new entity is recognized + | #[strong Test] the model to make sure the new entity is recognised | correctly. - -+h(3, "example-ner-from-scratch") Example: Training an NER system from scratch - -p - | This example is written to be self-contained and reasonably transparent. - | To achieve that, it duplicates some of spaCy's internal functionality. - | Specifically, in this example, we don't use spaCy's built-in - | #[+api("language") #[code Language]] class to wire together the - | #[+api("vocab") #[code Vocab]], #[+api("tokenizer") #[code Tokenizer]] - | and #[+api("entityrecognizer") #[code EntityRecognizer]]. Instead, we - | write our own simle #[code Pipeline] class, so that it's easier to see - | how the pieces interact. - -+github("spacy", "examples/training/train_ner_standalone.py") diff --git a/website/usage/examples.jade b/website/usage/examples.jade index 5dfeaf2a7..914ecafde 100644 --- a/website/usage/examples.jade +++ b/website/usage/examples.jade @@ -61,6 +61,15 @@ include ../_includes/_mixins +github("spacy", "examples/phrase_matcher.py") +section("training") + +h(3, "training-ner") Training spaCy's Named Entity Recognizer + + p + | This example shows how to update spaCy's entity recognizer + | with your own examples, starting off with an existing, pre-trained + | model, or from scratch using a blank #[code Language] class. + + +github("spacy", "examples/training/train_ner.py") + +h(3, "new-entity-type") Training an additional entity type p @@ -71,15 +80,6 @@ include ../_includes/_mixins +github("spacy", "examples/training/train_new_entity_type.py") - +h(3, "ner-standalone") Training an NER system from scratch - - p - | This example is written to be self-contained and reasonably - | transparent. To achieve that, it duplicates some of spaCy's internal - | functionality. - - +github("spacy", "examples/training/train_ner_standalone.py") - +h(3, "textcat") Training spaCy's text classifier +tag-new(2)