class_docstr: A mixin class to support loading pre-trained checkpoints for modules
  that implement the XLNet model.
  
  The XLNet model was proposed in
  `XLNet: Generalized Autoregressive Pretraining for Language Understanding`_
  by `Yang et al.` It is based on the Transformer-XL model, pre-trained on a
  large corpus using a language modeling objective that considers all
  permutations of the input sentence.
  
  The available XLNet models are as follows:
  
    * ``xlnet-based-cased``: 12-layer, 768-hidden, 12-heads. This model is
      trained on full data (different from the one in the paper).
    * ``xlnet-large-cased``: 24-layer, 1024-hidden, 16-heads.
  
  We provide the following XLNet classes:
  
    * :class:`~texar.torch.modules.XLNetEncoder` for text encoding.
    * :class:`~texar.torch.modules.XLNetDecoder` for text generation and
      decoding.
    * :class:`~texar.torch.modules.XLNetClassifier` for text classification
      and sequence tagging.
    * :class:`~texar.torch.modules.XLNetRegressor` for text regression.
  
  .. _`XLNet: Generalized Autoregressive Pretraining for Language Understanding`:
      http://arxiv.org/abs/1906.08237
class_docstr_tok: ["A","mixin","class","to","support","loading","pre-trained","checkpoints","for","modules","that","implement","the","XLNet","model",".","The","XLNet","model","was","proposed","in","`","XLNet",":","Generalized","Autoregressive","Pretraining","for","Language","Understanding","`","_","by","`","Yang","et","al.","`","It","is","based","on","the","Transformer-XL","model",",","pre-trained","on","a","large","corpus","using","a","language","modeling","objective","that","considers","all","permutations","of","the","input","sentence",".","The","available","XLNet","models","are","as","follows",":","*","``","xlnet-based-cased","``",":","12-layer",",","768-hidden",",","12-heads",".","This","model","is","trained","on","full","data","(","different","from","the","one","in","the","paper",")",".","*","``","xlnet-large-cased","``",":","24-layer",",","1024-hidden",",","16-heads",".","We","provide","the","following","XLNet","classes",":","*",":","class",":","`","~texar.torch.modules.XLNetEncoder","`","for","text","encoding",".","*",":","class",":","`","~texar.torch.modules.XLNetDecoder","`","for","text","generation","and","decoding",".","*",":","class",":","`","~texar.torch.modules.XLNetClassifier","`","for","text","classification","and","sequence","tagging",".","*",":","class",":","`","~texar.torch.modules.XLNetRegressor","`","for","text","regression",".","..","_","`","XLNet",":","Generalized","Autoregressive","Pretraining","for","Language","Understanding","`",":","http",":","\/\/arxiv.org\/abs\/1906.08237"]
docstr: Compute the union of the current variables and checkpoint variables.
  Because of the variable scope of the original XLNet and Texar
  implementation, we need to build a assignment map to match the variables.
docstr_tok: ["Compute","the","union","of","the","current","variables","and","checkpoint","variables",".","Because","of","the","variable","scope","of","the","original","XLNet","and","Texar","implementation",",","we","need","to","build","a","assignment","map","to","match","the","variables","."]
code: def _get_assignment_map_from_checkpoint(
      self, tvars, init_checkpoint, scope_name
  ):
      r"""
      Compute the union of the current variables and checkpoint variables.
      Because of the variable scope of the original XLNet and Texar
      implementation, we need to build a assignment map to match the variables.
      """
      assignment_map = {}
      initialized_variable_names = {}
  
      name_to_variable = collections.OrderedDict()
      for var in tvars:
          name = var.name
          m = re.match("^(.*):\\d+$", name)
          if m is not None:
              name = m.group(1)
          name_to_variable[name] = var
  
      init_vars = tf.train.list_variables(init_checkpoint)
  
      for check_name, _ in init_vars:
          check_name_scope = check_name.replace(
              "model/transformer/", scope_name + "/"
          )
          model_name = check_name_scope
          if check_name.startswith("model/lm_loss/bias"):
              model_name = scope_name + "/lm_loss/bias"
          elif check_name.startswith("model/transformer/mask_emb"):
              model_name = check_name_scope.replace(
                  "mask_emb/mask_emb", "mask_emb"
              )
          elif check_name.startswith(
              "model/transformer/word_embedding"
          ):
              model_name = scope_name + "/word_embedder/w"
          elif re.match("model/transformer/r_[r,s,w]_bias", check_name):
              model_name = check_name_scope
          elif re.match("model/transformer/seg_embed", check_name):
              model_name = check_name_scope
          elif re.match(
              "model/transformer/layer_\\d+/rel_attn/[q,k,v,r,o]",
              check_name,
          ):
              model_name = check_name_scope
          elif re.match(
              "model/transformer/layer_\\d+/rel_attn/LayerNorm",
              check_name,
          ):
              model_name = check_name_scope.replace("LayerNorm/", "")
          elif re.match(
              "model/transformer/layer_\\d+/ff/layer_[1,2]", check_name
          ):
              model_name = check_name_scope.replace(
                  "ff/layer_1", "ff/dense"
              )
              if model_name == check_name_scope:
                  model_name = check_name_scope.replace(
                      "ff/layer_2", "ff/dense_1"
                  )
          elif re.match(
              "model/transformer/layer_\\d+/ff/LayerNorm", check_name
          ):
              model_name = check_name_scope.replace("LayerNorm/", "")
  
          if model_name in name_to_variable.keys():
              assignment_map[check_name] = model_name
              initialized_variable_names[model_name] = 1
              initialized_variable_names[model_name + ":0"] = 1
          else:
              tf.logging.info(
                  "model name:{} not exist".format(model_name)
              )
  
      return assignment_map, initialized_variable_names
  
file_path: texar/texar/tf/modules/pretrained/xlnet.py
imports: import collections
  import json
  import os
  import re
  from abc import ABCMeta
  import tensorflow
  from texar.tf.modules.pretrained.pretrained_base import PretrainedMixin
label_desc: Use image node_id 3 for calling the PretrainedXLNetMixin obj's underlying member method code with example usage: obj._get_assignment_map_from_checkpoint(tvars, init_checkpoint, scope_name) and returns: assignment_map,  initialized_variable_names