class_docstr: A `Field` is some piece of a data instance that ends up as an tensor in a model (either as an
  input or an output).  Data instances are just collections of fields.
  
  Fields go through up to two steps of processing: (1) tokenized fields are converted into token
  ids, (2) fields containing token ids (or any other numeric data) are padded (if necessary) and
  converted into tensors.  The `Field` API has methods around both of these steps, though they
  may not be needed for some concrete `Field` classes - if your field doesn't have any strings
  that need indexing, you don't need to implement `count_vocab_items` or `index`.  These
  methods `pass` by default.
  
  Once a vocabulary is computed and all fields are indexed, we will determine padding lengths,
  then intelligently batch together instances and pad them into actual tensors.
class_docstr_tok: ["A","`","Field","`","is","some","piece","of","a","data","instance","that","ends","up","as","an","tensor","in","a","model","(","either","as","an","input","or","an","output",")",".","Data","instances","are","just","collections","of","fields",".","Fields","go","through","up","to","two","steps","of","processing",":","(","1",")","tokenized","fields","are","converted","into","token","ids",",","(","2",")","fields","containing","token","ids","(","or","any","other","numeric","data",")","are","padded","(","if","necessary",")","and","converted","into","tensors",".","The","`","Field","`","API","has","methods","around","both","of","these","steps",",","though","they","may","not","be","needed","for","some","concrete","`","Field","`","classes","-","if","your","field","does","n't","have","any","strings","that","need","indexing",",","you","do","n't","need","to","implement","`","count_vocab_items","`","or","`","index","`",".","These","methods","`","pass","`","by","default",".","Once","a","vocabulary","is","computed","and","all","fields","are","indexed",",","we","will","determine","padding","lengths",",","then","intelligently","batch","together","instances","and","pad","them","into","actual","tensors","."]
docstr: Takes the output of `Field.as_tensor()` from a list of `Instances` and merges it into
  one batched tensor for this `Field`.  The default implementation here in the base class
  handles cases where `as_tensor` returns a single torch tensor per instance.  If your
  subclass returns something other than this, you need to override this method.
  
  This operation does not modify `self`, but in some cases we need the information
  contained in `self` in order to perform the batching, so this is an instance method, not
  a class method.
docstr_tok: ["Takes","the","output","of","`","Field.as_tensor","(",")","`","from","a","list","of","`","Instances","`","and","merges","it","into","one","batched","tensor","for","this","`","Field","`",".","The","default","implementation","here","in","the","base","class","handles","cases","where","`","as_tensor","`","returns","a","single","torch","tensor","per","instance",".","If","your","subclass","returns","something","other","than","this",",","you","need","to","override","this","method",".","This","operation","does","not","modify","`","self","`",",","but","in","some","cases","we","need","the","information","contained","in","`","self","`","in","order","to","perform","the","batching",",","so","this","is","an","instance","method",",","not","a","class","method","."]
code: def batch_tensors(self, tensor_list: List[DataArray]) -> DataArray:  # type: ignore
      """
      Takes the output of `Field.as_tensor()` from a list of `Instances` and merges it into
      one batched tensor for this `Field`.  The default implementation here in the base class
      handles cases where `as_tensor` returns a single torch tensor per instance.  If your
      subclass returns something other than this, you need to override this method.
  
      This operation does not modify `self`, but in some cases we need the information
      contained in `self` in order to perform the batching, so this is an instance method, not
      a class method.
      """
  
      return torch.stack(tensor_list)
  
file_path: allennlp/allennlp/data/fields/field.py
imports: from copy import deepcopy
  from typing import Dict, Generic, List, TypeVar, Any
  import torch
  from allennlp.data.vocabulary import Vocabulary
label_desc: Use image node_id 7 for calling the Field obj's underlying member method code with example usage: obj.batch_tensors(tensor_list) and returns: torch