class_docstr: A `NamespaceSwappingField` is used to map tokens in one namespace to tokens in another namespace.
  It is used by seq2seq models with a copy mechanism that copies tokens from the source
  sentence into the target sentence.
  
  # Parameters
  
  source_tokens : `List[Token]`
      The tokens from the source sentence.
  target_namespace : `str`
      The namespace that the tokens from the source sentence will be mapped to.
class_docstr_tok: ["A","`","NamespaceSwappingField","`","is","used","to","map","tokens","in","one","namespace","to","tokens","in","another","namespace",".","It","is","used","by","seq2seq","models","with","a","copy","mechanism","that","copies","tokens","from","the","source","sentence","into","the","target","sentence",".","#","Parameters","source_tokens",":","`","List","[","Token","]","`","The","tokens","from","the","source","sentence",".","target_namespace",":","`","str","`","The","namespace","that","the","tokens","from","the","source","sentence","will","be","mapped","to","."]
code: def index(self, vocab: Vocabulary):
      self._mapping_array = [
          vocab.get_token_index(x.ensure_text(), self._target_namespace)
          for x in self._source_tokens
      ]
  
file_path: allennlp/allennlp/data/fields/namespace_swapping_field.py
imports: from typing import Dict, List, Any
  import torch
  from allennlp.common.util import pad_sequence_to_length
  from allennlp.data.vocabulary import Vocabulary
  from allennlp.data.tokenizers import Token
  from allennlp.data.fields.field import Field
label_desc: Use image node_id 2 for calling the NamespaceSwappingField obj's underlying member method code with example usage: obj.index(vocab) without return types