docstr: This model allows to create asymmetric SentenceTransformer models, that apply different models depending on the specified input key.
  
  In the below example, we create two different Dense models for 'query' and 'doc'. Text that is passed as {'query': 'My query'} will
  be passed along along the first Dense model, and text that will be passed as {'doc': 'My document'} will use the other Dense model.
  
  Note, that when you call encode(), that only inputs of the same type can be encoded. Mixed-Types cannot be encoded.
  
  Example::
      word_embedding_model = models.Transformer(model_name)
      pooling_model = models.Pooling(word_embedding_model.get_word_embedding_dimension())
      asym_model = models.Asym({'query': [models.Dense(word_embedding_model.get_word_embedding_dimension(), 128)], 'doc': [models.Dense(word_embedding_model.get_word_embedding_dimension(), 128)]})
      model = SentenceTransformer(modules=[word_embedding_model, pooling_model, asym_model])
  
      model.encode([{'query': 'Q1'}, {'query': 'Q2'}]
      model.encode([{'doc': 'Doc1'}, {'doc': 'Doc2'}]
  
      #You can train it with InputExample like this. Note, that the order must always be the same:
      train_example = InputExample(texts=[{'query': 'Train query'}, {'doc': 'Document'}], label=1)
  
  
  :param sub_modules: Dict in the format str -> List[models]. The models in the specified list will be applied for input marked with the respective key.
  :param allow_empty_key: If true, inputs without a key can be processed. If false, an exception will be thrown if no key is specified.
docstr_tok: ["This","model","allows","to","create","asymmetric","SentenceTransformer","models",",","that","apply","different","models","depending","on","the","specified","input","key",".","In","the","below","example",",","we","create","two","different","Dense","models","for","'query","'","and","'doc","'",".","Text","that","is","passed","as","{","'query","'",":","'My","query","'","}","will","be","passed","along","along","the","first","Dense","model",",","and","text","that","will","be","passed","as","{","'doc","'",":","'My","document","'","}","will","use","the","other","Dense","model",".","Note",",","that","when","you","call","encode","(",")",",","that","only","inputs","of","the","same","type","can","be","encoded",".","Mixed-Types","can","not","be","encoded",".","Example",":",":","word_embedding_model","=","models.Transformer","(","model_name",")","pooling_model","=","models.Pooling","(","word_embedding_model.get_word_embedding_dimension","(",")",")","asym_model","=","models.Asym","(","{","'query","'",":","[","models.Dense","(","word_embedding_model.get_word_embedding_dimension","(",")",",","128",")","]",",","'doc","'",":","[","models.Dense","(","word_embedding_model.get_word_embedding_dimension","(",")",",","128",")","]","}",")","model","=","SentenceTransformer","(","modules=","[","word_embedding_model",",","pooling_model",",","asym_model","]",")","model.encode","(","[","{","'query","'",":","'Q1","'","}",",","{","'query","'",":","'Q2","'","}","]","model.encode","(","[","{","'doc","'",":","'Doc1","'","}",",","{","'doc","'",":","'Doc2","'","}","]","#","You","can","train","it","with","InputExample","like","this",".","Note",",","that","the","order","must","always","be","the","same",":","train_example","=","InputExample","(","texts=","[","{","'query","'",":","'Train","query","'","}",",","{","'doc","'",":","'Document","'","}","]",",","label=1",")",":","param","sub_modules",":","Dict","in","the","format","str","-",">","List","[","models","]",".","The","models","in","the","specified","list","will","be","applied","for","input","marked","with","the","respective","key",".",":","param","allow_empty_key",":","If","true",",","inputs","without","a","key","can","be","processed",".","If","false",",","an","exception","will","be","thrown","if","no","key","is","specified","."]
code: def __init__(
      self,
      sub_modules: Dict[str, List[nn.Module]],
      allow_empty_key: bool = True,
  ):
      """
      This model allows to create asymmetric SentenceTransformer models, that apply different models depending on the specified input key.
  
      In the below example, we create two different Dense models for 'query' and 'doc'. Text that is passed as {'query': 'My query'} will
      be passed along along the first Dense model, and text that will be passed as {'doc': 'My document'} will use the other Dense model.
  
      Note, that when you call encode(), that only inputs of the same type can be encoded. Mixed-Types cannot be encoded.
  
      Example::
          word_embedding_model = models.Transformer(model_name)
          pooling_model = models.Pooling(word_embedding_model.get_word_embedding_dimension())
          asym_model = models.Asym({'query': [models.Dense(word_embedding_model.get_word_embedding_dimension(), 128)], 'doc': [models.Dense(word_embedding_model.get_word_embedding_dimension(), 128)]})
          model = SentenceTransformer(modules=[word_embedding_model, pooling_model, asym_model])
  
          model.encode([{'query': 'Q1'}, {'query': 'Q2'}]
          model.encode([{'doc': 'Doc1'}, {'doc': 'Doc2'}]
  
          #You can train it with InputExample like this. Note, that the order must always be the same:
          train_example = InputExample(texts=[{'query': 'Train query'}, {'doc': 'Document'}], label=1)
  
  
      :param sub_modules: Dict in the format str -> List[models]. The models in the specified list will be applied for input marked with the respective key.
      :param allow_empty_key: If true, inputs without a key can be processed. If false, an exception will be thrown if no key is specified.
      """
      self.sub_modules = sub_modules
      self.allow_empty_key = allow_empty_key
  
      ordered_dict = OrderedDict()
      for name, models in sub_modules.items():
          if not isinstance(models, List):
              models = [models]
  
          for idx, model in enumerate(models):
              ordered_dict[name + "-" + str(idx)] = model
      super(Asym, self).__init__(ordered_dict)
  
file_path: sentence-transformers/sentence_transformers/models/Asym.py
imports: from torch import Tensor
  from torch import nn
  import os
  import json
  from ..util import import_from_string
  from collections import OrderedDict
  from typing import List, Dict, Union, Tuple
label_desc: Use image node_id 1 to create a new Asym object from inherited base classes: nn with example: obj = Asym(sub_modules, allow_empty_key)