@plac.annotations(<EOL>model=("<STR_LIT>", "<STR_LIT>", "<STR_LIT:m>", str),<EOL>output_dir=("<STR_LIT>", "<STR_LIT>", "<STR_LIT:o>", Path),<EOL>n_iter=("<STR_LIT>", "<STR_LIT>", "<STR_LIT:n>", int),<EOL>)<EOL>def main(model=None, output_dir=None, n_iter=<NUM_LIT:15>):
if model is not None:<EOL><INDENT>nlp = spacy.load(model)  <EOL>print("<STR_LIT>" % model)<EOL><DEDENT>else:<EOL><INDENT>nlp = spacy.blank("<STR_LIT>")  <EOL>print("<STR_LIT>")<EOL><DEDENT>if "<STR_LIT>" in nlp.pipe_names:<EOL><INDENT>nlp.remove_pipe("<STR_LIT>")<EOL><DEDENT>parser = nlp.create_pipe("<STR_LIT>")<EOL>nlp.add_pipe(parser, first=True)<EOL>for text, annotations in TRAIN_DATA:<EOL><INDENT>for dep in annotations.get("<STR_LIT>", []):<EOL><INDENT>parser.add_label(dep)<EOL><DEDENT><DEDENT>other_pipes = [pipe for pipe in nlp.pipe_names if pipe != "<STR_LIT>"]<EOL>with nlp.disable_pipes(*other_pipes):  <EOL><INDENT>optimizer = nlp.begin_training()<EOL>for itn in range(n_iter):<EOL><INDENT>random.shuffle(TRAIN_DATA)<EOL>losses = {}<EOL>batches = minibatch(TRAIN_DATA, size=compounding(<NUM_LIT>, <NUM_LIT>, <NUM_LIT>))<EOL>for batch in batches:<EOL><INDENT>texts, annotations = zip(*batch)<EOL>nlp.update(texts, annotations, sgd=optimizer, losses=losses)<EOL><DEDENT>print("<STR_LIT>", losses)<EOL><DEDENT><DEDENT>test_model(nlp)<EOL>if output_dir is not None:<EOL><INDENT>output_dir = Path(output_dir)<EOL>if not output_dir.exists():<EOL><INDENT>output_dir.mkdir()<EOL><DEDENT>nlp.to_disk(output_dir)<EOL>print("<STR_LIT>", output_dir)<EOL>print("<STR_LIT>", output_dir)<EOL>nlp2 = spacy.load(output_dir)<EOL>test_model(nlp2)<EOL><DEDENT>
Load the model, set up the pipeline and train the parser.