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: Evaluates the model. Returns a Result object containing evaluation results and a loss value.
  
  Args:
      data_points: batch of sentences
      gold_label_type: if evaluate_all is False, specify the task to evaluate by the task_id.
      out_path: if not None, predictions will be created and saved at the respective file.
      main_evaluation_metric: Specify which metric to highlight as main_score
      evaluate_all: choose if all tasks should be evaluated, or a single one, depending on gold_label_type
      **evalargs: arguments propagated to :meth:`flair.nn.Model.evaluate`
  
  Returns: Tuple of Result object and loss value (float)
docstr_tok: ["Evaluates","the","model",".","Returns","a","Result","object","containing","evaluation","results","and","a","loss","value",".","Args",":","data_points",":","batch","of","sentences","gold_label_type",":","if","evaluate_all","is","False",",","specify","the","task","to","evaluate","by","the","task_id",".","out_path",":","if","not","None",",","predictions","will","be","created","and","saved","at","the","respective","file",".","main_evaluation_metric",":","Specify","which","metric","to","highlight","as","main_score","evaluate_all",":","choose","if","all","tasks","should","be","evaluated",",","or","a","single","one",",","depending","on","gold_label_type","*","*","evalargs",":","arguments","propagated","to",":","meth",":","`","flair.nn.Model.evaluate","`","Returns",":","Tuple","of","Result","object","and","loss","value","(","float",")"]
code: def evaluate(  # type: ignore[override]
      self,
      data_points,
      gold_label_type: str,
      out_path: Optional[Union[str, Path]] = None,
      main_evaluation_metric: Tuple[str, str] = (
          "micro avg",
          "f1-score",
      ),
      evaluate_all: bool = True,
      **evalargs,
  ) -> Result:
      """Evaluates the model. Returns a Result object containing evaluation results and a loss value.
  
      Args:
          data_points: batch of sentences
          gold_label_type: if evaluate_all is False, specify the task to evaluate by the task_id.
          out_path: if not None, predictions will be created and saved at the respective file.
          main_evaluation_metric: Specify which metric to highlight as main_score
          evaluate_all: choose if all tasks should be evaluated, or a single one, depending on gold_label_type
          **evalargs: arguments propagated to :meth:`flair.nn.Model.evaluate`
  
      Returns: Tuple of Result object and loss value (float)
      """
      if not evaluate_all:
          if gold_label_type not in self.tasks:
              raise ValueError(
                  "evaluating a single task on a multitask model requires 'gold_label_type' to be a valid task."
              )
          data = [
              dp
              for dp in data_points
              if any(
                  label.value == gold_label_type
                  for label in dp.get_labels("multitask_id")
              )
          ]
          return self.tasks[gold_label_type].evaluate(
              data,
              gold_label_type=self.tasks[gold_label_type].label_type,
              out_path=out_path,
              main_evaluation_metric=main_evaluation_metric,
              **evalargs,
          )
  
      batch_split = self.split_batch_to_task_ids(
          data_points, all_tasks=True
      )
  
      loss = torch.tensor(0.0, device=flair.device)
      main_score = 0.0
      all_detailed_results = ""
      all_classification_report: Dict[str, Dict[str, Any]] = {}
  
      for task_id, split in batch_split.items():
          result = self.tasks[task_id].evaluate(
              data_points=[data_points[i] for i in split],
              gold_label_type=self.tasks[task_id].label_type,
              out_path=f"{out_path}_{task_id}.txt"
              if out_path is not None
              else None,
              main_evaluation_metric=main_evaluation_metric,
              **evalargs,
          )
  
          log.info(
              f"{task_id} - {self.tasks[task_id]._get_name()} - "
              f"loss: {result.loss} - {main_evaluation_metric[1]} "
              f"({main_evaluation_metric[0]})  {round(result.main_score, 4)}"
          )
  
          loss += result.loss
          main_score += result.main_score
          all_detailed_results += (
              50 * "-"
              + "\n\n"
              + task_id
              + " - "
              + "Label type: "
              + self.tasks[task_id].label_type
              + "\n\n"
              + result.detailed_results
          )
          all_classification_report[
              task_id
          ] = result.classification_report
  
      scores = {"loss": loss.item() / len(batch_split)}
  
      return Result(
          main_score=main_score / len(batch_split),
          detailed_results=all_detailed_results,
          scores=scores,
          classification_report=all_classification_report,
      )
  
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 7 for calling the MultitaskModel obj's underlying member method code with example usage: obj.evaluate(data_points, gold_label_type, out_path, main_evaluation_metric, evaluate_all) and returns: Result, self