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: Splits a batch of sentences to its respective model.
  
  If single sentence is assigned to several tasks (i.e. same corpus but different tasks), then the model
  assignment for this batch is randomly chosen.
  
  Args:
      sentences: batch of sentences
      all_tasks: use all tasks of each sentence. If deactivated, a random task will be sampled
  
  Returns: Key-value pairs as (task_id, list of sentences ids in batch)
docstr_tok: ["Splits","a","batch","of","sentences","to","its","respective","model",".","If","single","sentence","is","assigned","to","several","tasks","(","i.e",".","same","corpus","but","different","tasks",")",",","then","the","model","assignment","for","this","batch","is","randomly","chosen",".","Args",":","sentences",":","batch","of","sentences","all_tasks",":","use","all","tasks","of","each","sentence",".","If","deactivated",",","a","random","task","will","be","sampled","Returns",":","Key-value","pairs","as","(","task_id",",","list","of","sentences","ids","in","batch",")"]
code: def split_batch_to_task_ids(
      sentences: Union[List[Sentence], Sentence],
      all_tasks: bool = False,
  ) -> Dict:
      """Splits a batch of sentences to its respective model.
  
      If single sentence is assigned to several tasks (i.e. same corpus but different tasks), then the model
      assignment for this batch is randomly chosen.
  
      Args:
          sentences: batch of sentences
          all_tasks: use all tasks of each sentence. If deactivated, a random task will be sampled
  
      Returns: Key-value pairs as (task_id, list of sentences ids in batch)
      """
      batch_to_task_mapping: Dict[str, List[int]] = {}
      for sentence_id, sentence in enumerate(sentences):
          if all_tasks:
              multitask_ids = sentence.get_labels("multitask_id")
          else:
              multitask_ids = [
                  random.choice(sentence.get_labels("multitask_id"))
              ]
          for multitask_id in multitask_ids:
              if multitask_id.value in batch_to_task_mapping:
                  batch_to_task_mapping[multitask_id.value].append(
                      sentence_id
                  )
              elif multitask_id.value not in batch_to_task_mapping:
                  batch_to_task_mapping[multitask_id.value] = [
                      sentence_id
                  ]
      return batch_to_task_mapping
  
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 6 for calling the MultitaskModel obj's underlying member method code with example usage: obj.split_batch_to_task_ids(sentences, all_tasks) and returns: batch_to_task_mapping