mirror of
https://github.com/explosion/spaCy.git
synced 2025-03-03 19:08:06 +03:00
Improve output on trainer
This commit is contained in:
parent
b438dfd3f3
commit
1224c4d3c6
|
@ -2,6 +2,7 @@ from __future__ import absolute_import
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
import tqdm
|
||||||
from .gold import GoldParse
|
from .gold import GoldParse
|
||||||
from .scorer import Scorer
|
from .scorer import Scorer
|
||||||
from .gold import merge_sents
|
from .gold import merge_sents
|
||||||
|
@ -12,11 +13,12 @@ class Trainer(object):
|
||||||
def __init__(self, nlp, gold_tuples):
|
def __init__(self, nlp, gold_tuples):
|
||||||
self.nlp = nlp
|
self.nlp = nlp
|
||||||
self.gold_tuples = gold_tuples
|
self.gold_tuples = gold_tuples
|
||||||
|
self.nr_epoch = 0
|
||||||
|
|
||||||
def epochs(self, nr_epoch, augment_data=None, gold_preproc=False):
|
def epochs(self, nr_epoch, augment_data=None, gold_preproc=False):
|
||||||
cached_golds = {}
|
cached_golds = {}
|
||||||
def _epoch(indices):
|
def _epoch(indices):
|
||||||
for i in indices:
|
for i in tqdm.tqdm(indices):
|
||||||
raw_text, paragraph_tuples = self.gold_tuples[i]
|
raw_text, paragraph_tuples = self.gold_tuples[i]
|
||||||
if gold_preproc:
|
if gold_preproc:
|
||||||
raw_text = None
|
raw_text = None
|
||||||
|
@ -39,11 +41,12 @@ class Trainer(object):
|
||||||
for itn in range(nr_epoch):
|
for itn in range(nr_epoch):
|
||||||
random.shuffle(indices)
|
random.shuffle(indices)
|
||||||
yield _epoch(indices)
|
yield _epoch(indices)
|
||||||
|
self.nr_epoch += 1
|
||||||
|
|
||||||
def update(self, doc, gold):
|
def update(self, doc, gold):
|
||||||
for process in self.nlp.pipeline:
|
for process in self.nlp.pipeline:
|
||||||
if hasattr(process, 'update'):
|
if hasattr(process, 'update'):
|
||||||
process.update(doc, gold)
|
loss = process.update(doc, gold, itn=self.nr_epoch)
|
||||||
process(doc)
|
process(doc)
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user