code: def marginalize(self, seq_logits, doc_scores, n_docs=None):
      n_docs = n_docs if n_docs is not None else self.config.n_docs
  
      # RAG-token marginalization
      seq_logprobs = tf.nn.log_softmax(seq_logits, axis=-1)
      seq_logprobs = tf.reshape(
          seq_logprobs,
          [
              seq_logits.shape[0] // n_docs,
              n_docs,
              -1,
              seq_logits.shape[-1],
          ],
      )
      doc_logprobs = tf.nn.log_softmax(doc_scores, axis=1)
      doc_logprobs = tf.expand_dims(doc_logprobs, axis=-1)
      doc_logprobs = tf.expand_dims(doc_logprobs, axis=-1)  # twice
      log_prob_sum = seq_logprobs + doc_logprobs
      return tf.reduce_logsumexp(log_prob_sum, axis=1)
  
imports: from __future__ import annotations
  import copy
  from dataclasses import dataclass
  from typing import List, Optional, Tuple, Union
  import numpy
  import tensorflow
  from ...configuration_utils import PretrainedConfig
  from ...generation import TFLogitsProcessorList
  from ...modeling_tf_utils import TFCausalLanguageModelingLoss, TFModelInputType, TFPreTrainedModel, shape_list, unpack_inputs
  from ...utils import ModelOutput, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_rag import RagConfig
  from .retrieval_rag import RagRetriever
label_desc: Use image node_id 8 for calling the TFRagTokenForGeneration obj's underlying member method code with example usage: obj.marginalize(seq_logits, doc_scores, n_docs) and returns: tf