(task_name, model_cls, dataset_fn, hparams=None, hparams_map=None,
            num_epochs=100, checkpoint=None,
            use_iob_metrics=True, early_stopping=None)
return best_cp
Train a model on a dataset. Saves model and hyperparams so that training
    can be easily resumed
    Parameters:
        task_name: Name of the task like NER1 etc. More like a unique identifier
        model_cls: Model class name. Should inherit from sequence_tagging.Tagger class
        dataset_fn: Dataset function. Must return a dict. See data/conll.py
        hparams: Hyperparameters defined for the particular model. Not required when
                resuming training
        hparams_map: mapping between model classes and hparams. Only used of hparams is
                None
        num_epochs: Set to 100. With early stopping set number of epochs will usually
                be lower. Set PREFS.early_stopping to desired criteria
        checkpoint: Saved checkpoint number (train iteration). Used to resume training
        use_iob_metrics: If True then adds IOB metrics (precision/recall/F1) to Evaluator
        early_stopping: Early stopping criteria. Should be of the form
                        [lowest/highest]_[window_Size]_[metric] where metric is one of
                        loss, acc, acc-seq, precision, recall, F1. Default is picked
                        from PREFS.early_stopping
Train a model on a dataset. Saves model and hyperparams so that training
    can be easily resumed
    Parameters:
        task_name: Name of the task like NER1 etc. More like a unique identifier
        model_cls: Model class name. Should inherit from sequence_tagging.Tagger class
        dataset_fn: Dataset function. Must return a dict. See data/conll.py
        hparams: Hyperparameters defined for the particular model. Not required when
                resuming training
        hparams_map: mapping between model classes and hparams. Only used of hparams is
                None
        num_epochs: Set to 100. With early stopping set number of epochs will usually
                be lower. Set PREFS.early_stopping to desired criteria
        checkpoint: Saved checkpoint number (train iteration). Used to resume training
        use_iob_metrics: If True then adds IOB metrics (precision/recall/F1) to Evaluator
        early_stopping: Early stopping criteria. Should be of the form
                        [lowest/highest]_[window_Size]_[metric] where metric is one of
                        loss, acc, acc-seq, precision, recall, F1. Default is picked
                        from PREFS.early_stopping
Train a model on a dataset . Saves model and hyperparams so that training can be easily resumed Parameters : task_name : Name of the task like NER1 etc . More like a unique identifier model_cls : Model class name . Should inherit from sequence_tagging . Tagger class dataset_fn : Dataset function . Must return a dict . See data / conll . py hparams : Hyperparameters defined for the particular model . Not required when resuming training hparams_map : mapping between model classes and hparams . Only used of hparams is None num_epochs : Set to 100 . With early stopping set number of epochs will usually be lower . Set PREFS . early_stopping to desired criteria checkpoint : Saved checkpoint number ( train iteration ) . Used to resume training use_iob_metrics : If True then adds IOB metrics ( precision / recall / F1 ) to Evaluator early_stopping : Early stopping criteria . Should be of the form [ lowest / highest ] _ [ window_Size ] _ [ metric ] where metric is one of loss acc acc - seq precision recall F1 . Default is picked from PREFS . early_stopping
def train(task_name, model_cls, dataset_fn, hparams=None, hparams_map=None,
            num_epochs=100, checkpoint=None,
            use_iob_metrics=True, early_stopping=None):
    """
    Train a model on a dataset. Saves model and hyperparams so that training
    can be easily resumed
    Parameters:
        task_name: Name of the task like NER1 etc. More like a unique identifier
        model_cls: Model class name. Should inherit from sequence_tagging.Tagger class
        dataset_fn: Dataset function. Must return a dict. See data/conll.py
        hparams: Hyperparameters defined for the particular model. Not required when
                resuming training
        hparams_map: mapping between model classes and hparams. Only used of hparams is
                None
        num_epochs: Set to 100. With early stopping set number of epochs will usually
                be lower. Set PREFS.early_stopping to desired criteria
        checkpoint: Saved checkpoint number (train iteration). Used to resume training
        use_iob_metrics: If True then adds IOB metrics (precision/recall/F1) to Evaluator
        early_stopping: Early stopping criteria. Should be of the form
                        [lowest/highest]_[window_Size]_[metric] where metric is one of
                        loss, acc, acc-seq, precision, recall, F1. Default is picked
                        from PREFS.early_stopping
    """
    early_stopping=early_stopping or PREFS.early_stopping

    # Create or load the model
    if checkpoint is None:
        if hparams is None:
            hparams = hparams_map[model_cls]
        dataset = dataset_fn(hparams.batch_size)
        model = model_cls.create(task_name, hparams, vocabs=dataset['vocabs'], 
                                overwrite=PREFS.overwrite_model_dir)
    else:
        model, hparams_loaded = model_cls.load(task_name, checkpoint)
        if hparams is None:
            hparams = hparams_loaded
        dataset = dataset_fn(hparams.batch_size)
    
    train_iter, validation_iter, _ = dataset['iters']
    _, _, tag_vocab = dataset['vocabs']

    metrics = [BasicMetrics(output_vocab=tag_vocab)]
    if use_iob_metrics:
        metrics += [IOBMetrics(tag_vocab=tag_vocab)]

    # Setup evaluator on the validation dataset
    evaluator = Evaluator(validation_iter, *metrics)

    # Setup trainer
    trainer = Trainer(task_name, model, hparams, train_iter, evaluator)

    # Start training
    best_cp, _ = trainer.train(num_epochs, early_stopping=early_stopping)

    return best_cp
def train ( task_name , model_cls , dataset_fn , hparams = None , hparams_map = None , num_epochs = 100 , checkpoint = None , use_iob_metrics = True , early_stopping = None ) : early_stopping = early_stopping or PREFS . early_stopping # Create or load the model if checkpoint is None : if hparams is None : hparams = hparams_map [ model_cls ] dataset = dataset_fn ( hparams . batch_size ) model = model_cls . create ( task_name , hparams , vocabs = dataset [ 'vocabs' ] , overwrite = PREFS . overwrite_model_dir ) else : model , hparams_loaded = model_cls . load ( task_name , checkpoint ) if hparams is None : hparams = hparams_loaded dataset = dataset_fn ( hparams . batch_size ) train_iter , validation_iter , _ = dataset [ 'iters' ] _ , _ , tag_vocab = dataset [ 'vocabs' ] metrics = [ BasicMetrics ( output_vocab = tag_vocab ) ] if use_iob_metrics : metrics += [ IOBMetrics ( tag_vocab = tag_vocab ) ] # Setup evaluator on the validation dataset evaluator = Evaluator ( validation_iter , * metrics ) # Setup trainer trainer = Trainer ( task_name , model , hparams , train_iter , evaluator ) # Start training best_cp , _ = trainer . train ( num_epochs , early_stopping = early_stopping ) return best_cp