From 4d896171ae43a4faba1b3c5cf480e641beb84cf3 Mon Sep 17 00:00:00 2001 From: ines Date: Thu, 26 Oct 2017 16:11:20 +0200 Subject: [PATCH] Use plac annotations for arguments --- examples/training/train_parser.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/training/train_parser.py b/examples/training/train_parser.py index d2c15c4c2..ad39ab7c3 100644 --- a/examples/training/train_parser.py +++ b/examples/training/train_parser.py @@ -13,6 +13,7 @@ Last updated for: spaCy 2.0.0a18 """ from __future__ import unicode_literals, print_function +import plac import random from pathlib import Path @@ -36,15 +37,12 @@ TRAIN_DATA = [ ] +@plac.annotations( + model=("Model name. Defaults to blank 'en' model.", "option", "m", str), + output_dir=("Optional output directory", "option", "o", Path), + n_iter=("Number of training iterations", "option", "n", int)) def main(model=None, output_dir=None, n_iter=1000): - """Load the model, set up the pipeline and train the parser. - - model (unicode): Model name to start off with. If None, a blank English - Language class is created. - output_dir (unicode / Path): Optional output directory. If None, no model - will be saved. - n_iter (int): Number of iterations during training. - """ + """Load the model, set up the pipeline and train the parser.""" if model is not None: nlp = spacy.load(model) # load existing spaCy model print("Loaded model '%s'" % model) @@ -100,7 +98,6 @@ def main(model=None, output_dir=None, n_iter=1000): if __name__ == '__main__': - import plac plac.call(main) # expected result: