class_docstr: Base Class for implementing AdaptiveModel with frameworks like PyTorch and ONNX.
class_docstr_tok: ["Base","Class","for","implementing","AdaptiveModel","with","frameworks","like","PyTorch","and","ONNX","."]
docstr: Populates prediction head with information coming from tasks.
  
  :param tasks: A dictionary where the keys are the names of the tasks and the values are the details of the task (e.g. label_list, metric, tensor name)
  :param require_labels: If True, an error will be thrown when a task is not supplied with labels)
  :return:
code: def connect_heads_with_processor(self, tasks, require_labels=True):
      """
      Populates prediction head with information coming from tasks.
  
      :param tasks: A dictionary where the keys are the names of the tasks and the values are the details of the task (e.g. label_list, metric, tensor name)
      :param require_labels: If True, an error will be thrown when a task is not supplied with labels)
      :return:
      """
  
      # Drop the next sentence prediction head if it does not appear in tasks. This is triggered by the interaction
      # setting the argument BertStyleLMProcessor(next_sent_pred=False)
      if "nextsentence" not in tasks:
          idx = None
          for i, ph in enumerate(self.prediction_heads):
              if ph.task_name == "nextsentence":
                  idx = i
          if idx is not None:
              logger.info(
                  "Removing the NextSentenceHead since next_sent_pred is set to False in the BertStyleLMProcessor"
              )
              del self.prediction_heads[i]
  
      for head in self.prediction_heads:
          head.label_tensor_name = tasks[head.task_name][
              "label_tensor_name"
          ]
          label_list = tasks[head.task_name]["label_list"]
          if not label_list and require_labels:
              raise Exception(
                  f"The task '{head.task_name}' is missing a valid set of labels"
              )
          label_list = tasks[head.task_name]["label_list"]
          head.label_list = label_list
          if "RegressionHead" in str(type(head)):
              # This needs to be explicitly set because the regression label_list is being hijacked to store
              # the scaling factor and the mean
              num_labels = 1
          else:
              num_labels = len(label_list)
          head.metric = tasks[head.task_name]["metric"]
  
imports: import copy
  import json
  import logging
  import os
  from pathlib import Path
  import multiprocessing
  import numpy
  import torch
  from torch import nn
  from transformers import AutoConfig
  from transformers.convert_graph_to_onnx import convert, quantize
  from farm.data_handler.processor import Processor
  from farm.modeling.language_model import LanguageModel
  from farm.modeling.prediction_head import PredictionHead, pick_single_fn
  from farm.utils import MLFlowLogger, stack
  import farm.conversion.transformers
label_desc: Use image node_id 6 for calling the BaseAdaptiveModel obj's underlying member method code with example usage: obj.connect_heads_with_processor(tasks, require_labels) without return types