custom-architectures section

This commit is contained in:
svlandeg 2020-09-02 11:14:06 +02:00
parent 3d9ae9286f
commit 6fd7f140ec
1 changed files with 32 additions and 2 deletions

View File

@ -669,7 +669,7 @@ def custom_logger(log_path):
#### Example: Custom batch size schedule {#custom-code-schedule}
For example, let's say you've implemented your own batch size schedule to use
You can also implement your own batch size schedule to use
during training. The `@spacy.registry.schedules` decorator lets you register
that function in the `schedules` [registry](/api/top-level#registry) and assign
it a string name:
@ -806,7 +806,37 @@ def filter_batch(size: int) -> Callable[[Iterable[Example]], Iterator[List[Examp
### Defining custom architectures {#custom-architectures}
<!-- TODO: this should probably move to new section on models -->
Built-in pipeline components such as the tagger or named entity recognizer are
constructed with default neural network [models](/api/architectures).
You can change the model architecture
entirely by implementing your own custom models and providing those in the config
when creating the pipeline component. See the
documentation on
[layers and model architectures](/usage/layers-architectures) for more details.
```python
### functions.py
from typing import List
from thinc.types import Floats2d
from thinc.api import Model
import spacy
from spacy.tokens import Doc
@spacy.registry.architectures("custom_neural_network.v1")
def MyModel(output_width: int) -> Model[List[Doc], List[Floats2d]]:
# ...
```
```ini
### config.cfg (excerpt)
[components.tagger]
factory = "tagger"
[components.tagger.model]
@architectures = "custom_neural_network.v1"
output_width = 512
```
## Internal training API {#api}