class_docstr: PyTorch implementation containing all the modelling needed for your NLP task. Combines 2 language
  models for representation of 2 sequences and a prediction head. Allows for gradient flow back to the 2 language model components.
class_docstr_tok: ["PyTorch","implementation","containing","all","the","modelling","needed","for","your","NLP","task",".","Combines","2","language","models","for","representation","of","2","sequences","and","a","prediction","head",".","Allows","for","gradient","flow","back","to","the","2","language","model","components","."]
docstr: Load a (downstream) model from huggingface's transformers format. Use cases:
   - continue training in FARM (e.g. take a squad QA model and fine-tune on your own data)
   - compare models without switching frameworks
   - use model directly for inference
  
  :param model_name_or_path1: local path of a saved model or name of a public one for Question Encoder
                                        Exemplary public names:
                                        - facebook/dpr-question_encoder-single-nq-base
                                        - deepset/bert-large-uncased-whole-word-masking-squad2
  :param model_name_or_path2: local path of a saved model or name of a public one for Context/Passage Encoder
                                Exemplary public names:
                                - facebook/dpr-ctx_encoder-single-nq-base
                                - deepset/bert-large-uncased-whole-word-masking-squad2
  :param device: "cpu" or "cuda"
  :param task_type: 'text_similarity'
                    More tasks coming soon ...
  :param processor: populates prediction head with information coming from tasks
  :type processor: Processor
  :return: AdaptiveModel
docstr_tok: ["Load","a","(","downstream",")","model","from","huggingface","'s","transformers","format",".","Use","cases",":","-","continue","training","in","FARM","(","e.g",".","take","a","squad","QA","model","and","fine-tune","on","your","own","data",")","-","compare","models","without","switching","frameworks","-","use","model","directly","for","inference",":","param","model_name_or_path1",":","local","path","of","a","saved","model","or","name","of","a","public","one","for","Question","Encoder","Exemplary","public","names",":","-","facebook\/dpr-question_encoder-single-nq-base","-","deepset\/bert-large-uncased-whole-word-masking-squad2",":","param","model_name_or_path2",":","local","path","of","a","saved","model","or","name","of","a","public","one","for","Context\/Passage","Encoder","Exemplary","public","names",":","-","facebook\/dpr-ctx_encoder-single-nq-base","-","deepset\/bert-large-uncased-whole-word-masking-squad2",":","param","device",":","``","cpu","''","or","``","cuda","''",":","param","task_type",":","'text_similarity'","More","tasks","coming","soon","...",":","param","processor",":","populates","prediction","head","with","information","coming","from","tasks",":","type","processor",":","Processor",":","return",":","AdaptiveModel"]
code: def convert_from_transformers(
      cls,
      model_name_or_path1,
      model_name_or_path2,
      device,
      task_type,
      processor=None,
      similarity_function="dot_product",
  ):
      """
      Load a (downstream) model from huggingface's transformers format. Use cases:
       - continue training in FARM (e.g. take a squad QA model and fine-tune on your own data)
       - compare models without switching frameworks
       - use model directly for inference
  
      :param model_name_or_path1: local path of a saved model or name of a public one for Question Encoder
                                            Exemplary public names:
                                            - facebook/dpr-question_encoder-single-nq-base
                                            - deepset/bert-large-uncased-whole-word-masking-squad2
      :param model_name_or_path2: local path of a saved model or name of a public one for Context/Passage Encoder
                                    Exemplary public names:
                                    - facebook/dpr-ctx_encoder-single-nq-base
                                    - deepset/bert-large-uncased-whole-word-masking-squad2
      :param device: "cpu" or "cuda"
      :param task_type: 'text_similarity'
                        More tasks coming soon ...
      :param processor: populates prediction head with information coming from tasks
      :type processor: Processor
      :return: AdaptiveModel
      """
      lm1 = LanguageModel.load(
          pretrained_model_name_or_path=model_name_or_path1,
          language_model_class="DPRQuestionEncoder",
      )
      lm2 = LanguageModel.load(
          pretrained_model_name_or_path=model_name_or_path2,
          language_model_class="DPRContextEncoder",
      )
      prediction_head = TextSimilarityHead(
          similarity_function=similarity_function
      )
      # TODO Infer type of head automatically from config
      if task_type == "text_similarity":
          bi_adaptive_model = cls(
              language_model1=lm1,
              language_model2=lm2,
              prediction_heads=[prediction_head],
              embeds_dropout_prob=0.1,
              lm1_output_types=["per_sequence"],
              lm2_output_types=["per_sequence"],
              device=device,
          )
      else:
          raise NotImplementedError(
              f"Huggingface's transformer models of type {task_type} are not supported yet for BiAdaptive Models"
          )
  
      if processor:
          bi_adaptive_model.connect_heads_with_processor(
              processor.tasks
          )
  
      return bi_adaptive_model
  
imports: import copy
  import json
  import logging
  import os
  from argparse import Namespace
  from pathlib import Path
  import multiprocessing
  import numpy
  import torch
  from torch import nn
  from farm.data_handler.processor import TextSimilarityProcessor
  from farm.data_handler.data_silo import DataSilo
  from farm.modeling.language_model import LanguageModel
  from farm.modeling.prediction_head import PredictionHead, TextSimilarityHead
  from farm.modeling.tokenization import Tokenizer
  from farm.utils import MLFlowLogger, stack
label_desc: Use image node_id 13 for calling the BiAdaptiveModel obj's underlying member method code with example usage: obj.convert_from_transformers(cls, model_name_or_path1, model_name_or_path2, device, task_type, processor, similarity_function) and returns: bi_adaptive_model