class_docstr: Multitask Model class which acts as wrapper for creating custom multitask models.
  
  Takes different tasks as input, parameter sharing is done by objects in flair,
  i.e. creating a Embedding Layer and passing it to two different Models, will
  result in a hard parameter-shared embedding layer. The abstract class takes care
  of calling the correct forward propagation and loss function of the respective
  model.
class_docstr_tok: ["Multitask","Model","class","which","acts","as","wrapper","for","creating","custom","multitask","models",".","Takes","different","tasks","as","input",",","parameter","sharing","is","done","by","objects","in","flair",",","i.e",".","creating","a","Embedding","Layer","and","passing","it","to","two","different","Models",",","will","result","in","a","hard","parameter-shared","embedding","layer",".","The","abstract","class","takes","care","of","calling","the","correct","forward","propagation","and","loss","function","of","the","respective","model","."]
docstr: Instantiates the MultiTaskModel.
  
  Args:
      models: The child models used during multitask training.
      task_ids: If given, add each corresponding model a specified task id. Otherwise, tasks get the ids 'Task_0', 'Task_1', ...
      loss_factors: If given, weight the losses of teh corresponding models during training.
      use_all_tasks: If True, each sentence will be trained on all tasks parallel, otherwise each epoch 1 task will be sampled to train the sentence on.
docstr_tok: ["Instantiates","the","MultiTaskModel",".","Args",":","models",":","The","child","models","used","during","multitask","training",".","task_ids",":","If","given",",","add","each","corresponding","model","a","specified","task","id",".","Otherwise",",","tasks","get","the","ids","'Task_0","'",",","'Task_1","'",",","...","loss_factors",":","If","given",",","weight","the","losses","of","teh","corresponding","models","during","training",".","use_all_tasks",":","If","True",",","each","sentence","will","be","trained","on","all","tasks","parallel",",","otherwise","each","epoch","1","task","will","be","sampled","to","train","the","sentence","on","."]
code: def __init__(
      self,
      models: List[flair.nn.Classifier],
      task_ids: Optional[List[str]] = None,
      loss_factors: Optional[List[float]] = None,
      use_all_tasks: bool = False,
  ) -> None:
      """Instantiates the MultiTaskModel.
  
      Args:
          models: The child models used during multitask training.
          task_ids: If given, add each corresponding model a specified task id. Otherwise, tasks get the ids 'Task_0', 'Task_1', ...
          loss_factors: If given, weight the losses of teh corresponding models during training.
          use_all_tasks: If True, each sentence will be trained on all tasks parallel, otherwise each epoch 1 task will be sampled to train the sentence on.
      """
      super().__init__()
  
      task_ids_internal: List[str] = (
          task_ids
          if task_ids
          else [f"Task_{i}" for i in range(len(models))]
      )
  
      self.tasks: Dict[str, flair.nn.Classifier] = {}
      self.loss_factors: Dict[str, float] = {}
      self.use_all_tasks = use_all_tasks
  
      if not loss_factors:
          loss_factors = [1.0] * len(models)
  
      for task_id, model, loss_factor in zip(
          task_ids_internal, models, loss_factors
      ):
          self.add_module(task_id, model)
          self.tasks[task_id] = model
          self.loss_factors[task_id] = loss_factor
  
          # the multi task model has several labels
          self._label_type = model.label_type
      self.to(flair.device)
  
imports: import logging
  import random
  import typing
  from pathlib import Path
  from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  import flair.nn
  from flair.data import DT, Corpus, Sentence
  from flair.file_utils import cached_path
  from flair.nn import Classifier
  from flair.training_utils import Result
label_desc: Use image node_id 1 to create a new MultitaskModel object from inherited base classes: flair.nn with example: obj = MultitaskModel(models, task_ids, loss_factors, use_all_tasks)