class_docstr: This ``Field`` represents a list of string tokens.  Before constructing this object, you need
  to tokenize raw strings using a :class:`~allennlp.data.tokenizers.tokenizer.Tokenizer`.
  
  Because string tokens can be represented as indexed arrays in a number of ways, we also take a
  dictionary of :class:`~allennlp.data.token_indexers.token_indexer.TokenIndexer`
  objects that will be used to convert the tokens into indices.
  Each ``TokenIndexer`` could represent each token as a single ID, or a list of character IDs, or
  something else.
  
  This field will get converted into a dictionary of arrays, one for each ``TokenIndexer``.  A
  ``SingleIdTokenIndexer`` produces an array of shape (num_tokens,), while a
  ``TokenCharactersIndexer`` produces an array of shape (num_tokens, num_characters).
class_docstr_tok: ["This","``","Field","``","represents","a","list","of","string","tokens",".","Before","constructing","this","object",",","you","need","to","tokenize","raw","strings","using","a",":","class",":","`","~allennlp.data.tokenizers.tokenizer.Tokenizer","`",".","Because","string","tokens","can","be","represented","as","indexed","arrays","in","a","number","of","ways",",","we","also","take","a","dictionary","of",":","class",":","`","~allennlp.data.token_indexers.token_indexer.TokenIndexer","`","objects","that","will","be","used","to","convert","the","tokens","into","indices",".","Each","``","TokenIndexer","``","could","represent","each","token","as","a","single","ID",",","or","a","list","of","character","IDs",",","or","something","else",".","This","field","will","get","converted","into","a","dictionary","of","arrays",",","one","for","each","``","TokenIndexer","``",".","A","``","SingleIdTokenIndexer","``","produces","an","array","of","shape","(","num_tokens",",",")",",","while","a","``","TokenCharactersIndexer","``","produces","an","array","of","shape","(","num_tokens",",","num_characters",")","."]
code: def as_tensor(self, padding_lengths, cuda_device=-1):
      tensors = {}
      num_tokens = padding_lengths.get("num_tokens")
      for indexer_name, indexer in list(self._token_indexers.items()):
          if num_tokens is None:
              # The indexers return different lengths.
              # Get the desired_num_tokens for this indexer.
              desired_num_tokens = dict(
                  (
                      indexed_tokens_key,
                      padding_lengths[indexed_tokens_key],
                  )
                  for indexed_tokens_key in self._indexer_name_to_indexed_token[
                      indexer_name
                  ]
              )
          else:
              desired_num_tokens = {indexer_name: num_tokens}
  
          indices_to_pad = dict(
              (
                  indexed_tokens_key,
                  self._indexed_tokens[indexed_tokens_key],
              )
              for indexed_tokens_key in self._indexer_name_to_indexed_token[
                  indexer_name
              ]
          )
          padded_array = indexer.pad_token_sequence(
              indices_to_pad, desired_num_tokens, padding_lengths
          )
          # We use the key of the indexer to recognise what the tensor corresponds to within the
          # field (i.e. the result of word indexing, or the result of character indexing, for
          # example).
          # TODO(mattg): we might someday have a TokenIndexer that needs to use something other
          # than a LongTensor here, and it's not clear how to signal that.  Maybe we'll need to
          # add a class method to TokenIndexer to tell us the type?  But we can worry about that
          # when there's a compelling use case for it.
          indexer_tensors = dict(
              (key, torch.LongTensor(array))
              for key, array in list(padded_array.items())
          )
          if cuda_device > -1:
              for key in list(indexer_tensors.keys()):
                  indexer_tensors[key] = indexer_tensors[key].cuda(
                      cuda_device
                  )
          tensors.update(indexer_tensors)
      return tensors
  
imports: from __future__ import absolute_import
  import textwrap
  from spacy.tokens import Token
  import torch
  from allennlp.common.checks import ConfigurationError
  from allennlp.data.fields.sequence_field import SequenceField
  from allennlp.data.tokenizers.token import Token
  from allennlp.data.token_indexers.token_indexer import TokenIndexer
  from allennlp.data.vocabulary import Vocabulary
  from allennlp.nn import util
label_desc: Use image node_id 6 for calling the TextField obj's underlying member method code with example usage: obj.as_tensor(padding_lengths, cuda_device) and returns: tensors