class_docstr: Poly-encoder Agent.
  
  Equivalent of bert_ranker/polyencoder and biencoder_multiple_output but does not
  rely on an external library (hugging face).
class_docstr_tok: ["Poly-encoder","Agent",".","Equivalent","of","bert_ranker\/polyencoder","and","biencoder_multiple_output","but","does","not","rely","on","an","external","library","(","hugging","face",")","."]
docstr: Resize the token embeddings when adding extra special tokens.
  
  H/t TransformerGenerator._resize_token_embeddings for inspiration.
docstr_tok: ["Resize","the","token","embeddings","when","adding","extra","special","tokens",".","H\/t","TransformerGenerator._resize_token_embeddings","for","inspiration","."]
code: def _resize_token_embeddings(self, state_dict, msg=None):
      """
      Resize the token embeddings when adding extra special tokens.
  
      H/t TransformerGenerator._resize_token_embeddings for inspiration.
      """
      # map extra special tokens carefully
      new_size = self.model.encoder_ctxt.embeddings.weight.size()[0]
      orig_size = state_dict["encoder_ctxt.embeddings.weight"].size()[0]
      logging.info(
          f"Resizing token embeddings from {orig_size} to {new_size}"
      )
      if new_size <= orig_size:
          # new size should be greater than original size,
          # as we are adding special tokens
          raise RuntimeError(msg)
  
      for emb_weights in [
          "encoder_ctxt.embeddings.weight",
          "encoder_cand.embeddings.weight",
      ]:
          # get new_embs
          old_embs = state_dict[emb_weights]
          new_embs = recursive_getattr(self.model, emb_weights).to(
              old_embs.device
          )
          # copy over old weights
          new_embs.data[:orig_size, :] = old_embs.data[:orig_size, :]
          # reset in state dict
          state_dict[emb_weights] = new_embs
  
      return state_dict
  
imports: from parlai.core.params import ParlaiParser
  from typing import Any, Dict, Optional, Tuple
  import torch
  from parlai.core.opt import Opt
  from parlai.core.torch_ranker_agent import TorchRankerAgent
  from parlai.core.torch_agent import Batch
  from parlai.utils.misc import recursive_getattr
  from parlai.utils.logging import logging
  from .biencoder import AddLabelFixedCandsTRA
  from .modules import BasicAttention, MultiHeadAttention, TransformerEncoder
  from .transformer import TransformerRankerAgent
label_desc: Use image node_id 17 for calling the PolyencoderAgent obj's underlying member method code with example usage: obj._resize_token_embeddings(state_dict, msg) and returns: state_dict