mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 18:26:30 +03:00
* Move to fixing up ent_strings and dep_strings passing
This commit is contained in:
parent
31fad99518
commit
9061bbaf61
|
@ -213,10 +213,6 @@ def train(Language, train_loc, model_dir, n_iter=15, feat_set=u'basic', seed=0,
|
||||||
if n_sents > 0:
|
if n_sents > 0:
|
||||||
gold_tuples = gold_tuples[:n_sents]
|
gold_tuples = gold_tuples[:n_sents]
|
||||||
nlp = Language()
|
nlp = Language()
|
||||||
ent_strings = [None] * (max(nlp.entity.moves.label_ids.values()) + 1)
|
|
||||||
for label, i in nlp.entity.moves.label_ids.items():
|
|
||||||
if i >= 0:
|
|
||||||
ent_strings[i] = label
|
|
||||||
|
|
||||||
print "Itn.\tUAS\tNER F.\tTag %"
|
print "Itn.\tUAS\tNER F.\tTag %"
|
||||||
for itn in range(n_iter):
|
for itn in range(n_iter):
|
||||||
|
@ -229,12 +225,11 @@ def train(Language, train_loc, model_dir, n_iter=15, feat_set=u'basic', seed=0,
|
||||||
for tokens in sents:
|
for tokens in sents:
|
||||||
gold = GoldParse(tokens, annot_tuples)
|
gold = GoldParse(tokens, annot_tuples)
|
||||||
nlp.tagger(tokens)
|
nlp.tagger(tokens)
|
||||||
nlp.entity.train(tokens, gold, force_gold=force_gold)
|
nlp.parser.train(tokens, gold, force_gold=force_gold)
|
||||||
#nlp.parser.train(tokens, gold, force_gold=force_gold)
|
#nlp.entity.train(tokens, gold, force_gold=force_gold)
|
||||||
nlp.tagger.train(tokens, gold.tags)
|
nlp.tagger.train(tokens, gold.tags)
|
||||||
|
|
||||||
nlp.entity(tokens)
|
#nlp.entity(tokens)
|
||||||
tokens._ent_strings = tuple(ent_strings)
|
|
||||||
nlp.parser(tokens)
|
nlp.parser(tokens)
|
||||||
scorer.score(tokens, gold, verbose=False)
|
scorer.score(tokens, gold, verbose=False)
|
||||||
print '%d:\t%.3f\t%.3f\t%.3f' % (itn, scorer.uas, scorer.ents_f, scorer.tags_acc)
|
print '%d:\t%.3f\t%.3f\t%.3f' % (itn, scorer.uas, scorer.ents_f, scorer.tags_acc)
|
||||||
|
@ -244,7 +239,7 @@ def train(Language, train_loc, model_dir, n_iter=15, feat_set=u'basic', seed=0,
|
||||||
nlp.tagger.model.end_training()
|
nlp.tagger.model.end_training()
|
||||||
|
|
||||||
|
|
||||||
def evaluate(Language, dev_loc, model_dir, gold_preproc=False, verbose=False):
|
def evaluate(Language, dev_loc, model_dir, gold_preproc=False, verbose=True):
|
||||||
assert not gold_preproc
|
assert not gold_preproc
|
||||||
nlp = Language()
|
nlp = Language()
|
||||||
gold_tuples = read_docparse_file(dev_loc)
|
gold_tuples = read_docparse_file(dev_loc)
|
||||||
|
@ -260,12 +255,13 @@ def evaluate(Language, dev_loc, model_dir, gold_preproc=False, verbose=False):
|
||||||
train_loc=("Training file location",),
|
train_loc=("Training file location",),
|
||||||
dev_loc=("Dev. file location",),
|
dev_loc=("Dev. file location",),
|
||||||
model_dir=("Location of output model directory",),
|
model_dir=("Location of output model directory",),
|
||||||
n_sents=("Number of training sentences", "option", "n", int)
|
n_sents=("Number of training sentences", "option", "n", int),
|
||||||
|
verbose=("Verbose error reporting", "flag", "v", bool),
|
||||||
)
|
)
|
||||||
def main(train_loc, dev_loc, model_dir, n_sents=0):
|
def main(train_loc, dev_loc, model_dir, n_sents=0, verbose=False):
|
||||||
train(English, train_loc, model_dir,
|
train(English, train_loc, model_dir,
|
||||||
gold_preproc=False, force_gold=False, n_sents=n_sents)
|
gold_preproc=False, force_gold=False, n_sents=n_sents)
|
||||||
scorer = evaluate(English, dev_loc, model_dir, gold_preproc=False, verbose=False)
|
scorer = evaluate(English, dev_loc, model_dir, gold_preproc=False, verbose=verbose)
|
||||||
print 'POS', scorer.tags_acc
|
print 'POS', scorer.tags_acc
|
||||||
print 'UAS', scorer.uas
|
print 'UAS', scorer.uas
|
||||||
print 'LAS', scorer.las
|
print 'LAS', scorer.las
|
||||||
|
|
Loading…
Reference in New Issue
Block a user