code: def cloned_feature(feature, num_layers, detach=True):
      """
      Clone & detach the feature, keeping the last N layers (or averaging -2,-3,-4 if not specified)
  
      averaging 3 of the last 4 layers worked well for non-VI languages
      """
      # in most cases, need to call with features.hidden_states
      # bartpho is different - it has features.decoder_hidden_states
      # feature[2] is the same for bert, but it didn't work for
      # older versions of transformers for xlnet
      if num_layers is None:
          feature = torch.stack(feature[-4:-1], axis=3).sum(axis=3) / 4
      else:
          feature = torch.stack(feature[-num_layers:], axis=3)
      if detach:
          return feature.clone().detach()
      else:
          return feature
  
imports: import math
  import logging
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.utils.rnn import pad_packed_sequence, pack_padded_sequence, pack_sequence, PackedSequence
label_desc: Use image node_id 6 for calling a global function with example usage: cloned_feature(feature, num_layers, detach) and returns: feature, feature