def begin_training(self, get_gold_tuples=None, sgd=None, component_cfg=None, **cfg):
if get_gold_tuples is None:<EOL><INDENT>get_gold_tuples = lambda: []<EOL><DEDENT>else:<EOL><INDENT>for _, annots_brackets in get_gold_tuples():<EOL><INDENT>for annots, _ in annots_brackets:<EOL><INDENT>for word in annots[<NUM_LIT:1>]:<EOL><INDENT>_ = self.vocab[word]  <EOL><DEDENT><DEDENT><DEDENT><DEDENT>if cfg.get("<STR_LIT>", -<NUM_LIT:1>) >= <NUM_LIT:0>:<EOL><INDENT>util.use_gpu(cfg["<STR_LIT>"])<EOL>if self.vocab.vectors.data.shape[<NUM_LIT:1>] >= <NUM_LIT:1>:<EOL><INDENT>self.vocab.vectors.data = Model.ops.asarray(self.vocab.vectors.data)<EOL><DEDENT><DEDENT>link_vectors_to_models(self.vocab)<EOL>if self.vocab.vectors.data.shape[<NUM_LIT:1>]:<EOL><INDENT>cfg["<STR_LIT>"] = self.vocab.vectors.name<EOL><DEDENT>if sgd is None:<EOL><INDENT>sgd = create_default_optimizer(Model.ops)<EOL><DEDENT>self._optimizer = sgd<EOL>if component_cfg is None:<EOL><INDENT>component_cfg = {}<EOL><DEDENT>for name, proc in self.pipeline:<EOL><INDENT>if hasattr(proc, "<STR_LIT>"):<EOL><INDENT>kwargs = component_cfg.get(name, {})<EOL>kwargs.update(cfg)<EOL>proc.begin_training(<EOL>get_gold_tuples,<EOL>pipeline=self.pipeline,<EOL>sgd=self._optimizer,<EOL>**kwargs<EOL>)<EOL><DEDENT><DEDENT>return self._optimizer<EOL>
Allocate models, pre-process training data and acquire a trainer and
        optimizer. Used as a contextmanager.

        get_gold_tuples (function): Function returning gold data
        component_cfg (dict): Config parameters for specific components.
        **cfg: Config parameters.
        RETURNS: An optimizer.

        DOCS: https://spacy.io/api/language#begin_training