code: def _self_bleu(completions: List[Sequence], **unused_kwargs) -> float:
      """Self-BLEU.
  
      Average over all scores, where each score is the BLEU of one generation compared against all other generations.
  
      If there is fewer than one completion, the self-bleu score is 0.
      """
      completion_sequences: List[str] = [
          completion.text.strip()
          for completion in completions
          if completion.text.strip()
      ]
  
      if len(completion_sequences) <= 1:
          return 0
  
      scores = []
      for i in range(len(completion_sequences)):
          hypothesis = completion_sequences[i]
          references = (
              completion_sequences[:i] + completion_sequences[i + 1 :]
          )
  
          # Enable `effective_order` for sentence-level BLEU.
          score = BLEU(effective_order=True).sentence_score(
              hypothesis=hypothesis, references=references
          )
          scores.append(score.score)
      return sum(scores) / len(scores)
  
imports: import json
  import os
  from typing import Dict, List, Optional
  import numpy
  from sacrebleu.metrics import BLEU
  from helm.common.general import ensure_file_downloaded
  from helm.common.request import RequestResult, Sequence
  from helm.benchmark.adaptation.request_state import RequestState
  from helm.benchmark.adaptation.adapter_spec import AdapterSpec
  from .metric import Metric
  from .metric_name import MetricName
  from .metric_service import MetricService
  from .statistic import Stat
label_desc: Use image node_id 1 for calling a global function with example usage: _self_bleu(completions) and returns: unknown, int