code: def create_taskmodel(task, encoder, **taskmodel_kwargs) -> Taskmodel:
      """Creates, initializes and returns the task model for a given task type and encoder.
  
      Args:
          task (Task): Task object associated with the taskmodel being created.
          encoder (JiantTransformersModel): Transformer w/o heads
              (embedding layer + self-attention layer).
          **taskmodel_kwargs: Additional args for taskmodel setup
  
      Raises:
          KeyError if task does not have valid TASK_TYPE.
  
      Returns:
          Taskmodel
  
      """
      head_kwargs = {}
      head_kwargs["hidden_size"] = encoder.get_hidden_size()
      head_kwargs[
          "hidden_dropout_prob"
      ] = encoder.get_hidden_dropout_prob()
      head_kwargs["vocab_size"] = encoder.config.vocab_size
      head_kwargs["model_arch"] = ModelArchitectures(
          encoder.config.model_type
      )
  
      if hasattr(encoder, "hidden_act"):
          head_kwargs["hidden_act"] = encoder.config.hidden_act
      if hasattr(encoder, "layer_norm_eps"):
          head_kwargs["layer_norm_eps"] = encoder.config.layer_norm_eps
  
      head = JiantHeadFactory()(task, **head_kwargs)
  
      taskmodel = JiantTaskModelFactory()(
          task, encoder, head, **taskmodel_kwargs
      )
      return taskmodel
  
imports: from dataclasses import dataclass
  from typing import Any
  from typing import Dict
  from typing import List
  import torch
  import torch.nn
  import transformers
  import warnings
  import jiant.proj.main.components.container_setup
  import jiant.proj.main.modeling.primary
  import jiant.utils.python.strings
  from jiant.proj.main.modeling.heads import JiantHeadFactory
  from jiant.proj.main.modeling.taskmodels import JiantTaskModelFactory, Taskmodel, MLMModel
  from jiant.shared.model_resolution import ModelArchitectures
  from jiant.tasks.core import Task
label_desc: Use image node_id 8 for calling a global function with example usage: create_taskmodel(task, encoder) and returns: taskmodel