@plac.annotations(<EOL>lang=("<STR_LIT>", "<STR_LIT>", "<STR_LIT:l>", 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(lang="<STR_LIT>", output_dir=None, n_iter=<NUM_LIT>):
nlp = spacy.blank(lang)<EOL>tagger = nlp.create_pipe("<STR_LIT>")<EOL>for tag, values in TAG_MAP.items():<EOL><INDENT>tagger.add_label(tag, values)<EOL><DEDENT>nlp.add_pipe(tagger)<EOL>optimizer = nlp.begin_training()<EOL>for i 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>test_text = "<STR_LIT>"<EOL>doc = nlp(test_text)<EOL>print("<STR_LIT>", [(t.text, t.tag_, t.pos_) for t in doc])<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>doc = nlp2(test_text)<EOL>print("<STR_LIT>", [(t.text, t.tag_, t.pos_) for t in doc])<EOL><DEDENT>
Create a new model, set up the pipeline and train the tagger. In order to
    train the tagger with a custom tag map, we're creating a new Language
    instance with a custom vocab.