class_docstr: MTV model.
docstr: Applies the global encoder.
  
  We support two strategies to merge encoded tokens from each view:
  
  In the first strategy, we extract the CLS tokens from each view (we apply
  pooling when other classifiers are used), apply tiling to match the temporal
  dimension, and concatenate them in the channel dimension.
  
  In the second strategy, after we extract the CLS tokens we linear project
  them into the same dimension and concatenate them along the temporal
  dimension.
  
  The global encoder is implemented as a ViT encoder.
  
  Args:
    tokens: A list of tokens from each view. Each one has a shape of (batch,
      time, sequence_len, channels).
    is_train: Whether or not it is in training.
  
  Returns:
    A 2D float tensor representing the embedding from the global encoder.
docstr_tok: ["Applies","the","global","encoder",".","We","support","two","strategies","to","merge","encoded","tokens","from","each","view",":","In","the","first","strategy",",","we","extract","the","CLS","tokens","from","each","view","(","we","apply","pooling","when","other","classifiers","are","used",")",",","apply","tiling","to","match","the","temporal","dimension",",","and","concatenate","them","in","the","channel","dimension",".","In","the","second","strategy",",","after","we","extract","the","CLS","tokens","we","linear","project","them","into","the","same","dimension","and","concatenate","them","along","the","temporal","dimension",".","The","global","encoder","is","implemented","as","a","ViT","encoder",".","Args",":","tokens",":","A","list","of","tokens","from","each","view",".","Each","one","has","a","shape","of","(","batch",",","time",",","sequence_len",",","channels",")",".","is_train",":","Whether","or","not","it","is","in","training",".","Returns",":","A","2D","float","tensor","representing","the","embedding","from","the","global","encoder","."]
code: def _global_encode(
      self, tokens: Sequence[jnp.ndarray], is_train: bool
  ) -> jnp.ndarray:
      """Applies the global encoder.
  
      We support two strategies to merge encoded tokens from each view:
  
      In the first strategy, we extract the CLS tokens from each view (we apply
      pooling when other classifiers are used), apply tiling to match the temporal
      dimension, and concatenate them in the channel dimension.
  
      In the second strategy, after we extract the CLS tokens we linear project
      them into the same dimension and concatenate them along the temporal
      dimension.
  
      The global encoder is implemented as a ViT encoder.
  
      Args:
        tokens: A list of tokens from each view. Each one has a shape of (batch,
          time, sequence_len, channels).
        is_train: Whether or not it is in training.
  
      Returns:
        A 2D float tensor representing the embedding from the global encoder.
      """
      encoder_config = self.global_encoder_config.to_dict()
      encoder_config.update(
          dict(
              dropout_rate=self.dropout_rate,
              attention_dropout_rate=self.attention_dropout_rate,
              stochastic_depth=self.stochastic_depth,
              dtype=self.dtype,
              name="global_encoder",
          )
      )
      merge_axis = encoder_config.pop("merge_axis", "channel")
      hidden_size = encoder_config.pop("hidden_size")
      if merge_axis == "time":
          x = self._merge_views_along_time_axis(tokens, hidden_size)
      elif merge_axis == "channel":
          x = self._merge_views_along_channel_axis(tokens)
      else:
          raise ValueError(f"Invalid merge_axis: {merge_axis}.")
      x = self._add_cls_token(x, name="cls_global")
      encoder = vit.Encoder(**encoder_config)
      if self.keep_spatiotemporal_features:
          x = jax.vmap(
              functools.partial(encoder, train=is_train),
              in_axes=2,
              out_axes=2,
          )(x)
      else:
          x = encoder(x, train=is_train)
      return (
          x
          if self.keep_spatiotemporal_features
          else self._extract_encoder_output(x)
      )
  
imports: import functools
  from typing import Any, List, Sequence, Tuple, Union
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  from scenic.model_lib.layers import attention_layers
  from scenic.model_lib.layers import nn_layers
  from scenic.projects.baselines import vit
  from scenic.projects.mtv import model_utils
  from scenic.projects.vivit import model
  from scenic.train_lib import train_utils
label_desc: Use image node_id 9 for calling the MTV obj's underlying member method code with example usage: obj._global_encode(tokens, is_train) and returns: unknown