mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 09:26:27 +03:00
Improve simple training example in v3 migration (#6438)
* Create the examples once * Use the examples in the initialization * Provide the batch size * Fix `begin_training` migration example
This commit is contained in:
parent
079f6ea474
commit
1442d2f213
|
@ -969,18 +969,18 @@ The [`Language.update`](/api/language#update),
|
||||||
raw text and a dictionary of annotations.
|
raw text and a dictionary of annotations.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
### Training loop {highlight="11"}
|
### Training loop {highlight="5-8,12"}
|
||||||
TRAIN_DATA = [
|
TRAIN_DATA = [
|
||||||
("Who is Shaka Khan?", {"entities": [(7, 17, "PERSON")]}),
|
("Who is Shaka Khan?", {"entities": [(7, 17, "PERSON")]}),
|
||||||
("I like London.", {"entities": [(7, 13, "LOC")]}),
|
("I like London.", {"entities": [(7, 13, "LOC")]}),
|
||||||
]
|
]
|
||||||
nlp.initialize()
|
examples = []
|
||||||
|
for text, annots in TRAIN_DATA:
|
||||||
|
examples.append(Example.from_dict(nlp.make_doc(text), annots))
|
||||||
|
nlp.initialize(lambda: examples)
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
random.shuffle(TRAIN_DATA)
|
random.shuffle(examples)
|
||||||
for batch in minibatch(TRAIN_DATA):
|
for batch in minibatch(examples, size=8):
|
||||||
examples = []
|
|
||||||
for text, annots in batch:
|
|
||||||
examples.append(Example.from_dict(nlp.make_doc(text), annots))
|
|
||||||
nlp.update(examples)
|
nlp.update(examples)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -995,7 +995,7 @@ network,
|
||||||
setting up the label scheme.
|
setting up the label scheme.
|
||||||
|
|
||||||
```diff
|
```diff
|
||||||
- nlp.initialize(examples)
|
- nlp.begin_training()
|
||||||
+ nlp.initialize(lambda: examples)
|
+ nlp.initialize(lambda: examples)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user