code: def _clean_and_truncate(
      text: str, max_num_words: Optional[int] = None
  ) -> str:
      text = text.replace("\n", " ")
      whitespace_tokens = text.split()
      if max_num_words:
          whitespace_tokens = whitespace_tokens[:max_num_words]
      return " ".join(whitespace_tokens)
  
file_path: H2O/h2o_hf/helm/src/helm/benchmark/scenarios/legal_summarization_scenario.py
imports: from pathlib import Path
  from typing import List, Optional, Any
  import datasets
  from datasets import load_dataset
  from .scenario import Scenario, Instance, Reference, TRAIN_SPLIT, VALID_SPLIT, TEST_SPLIT, CORRECT_TAG, Input, Output
label_desc: Use image node_id 1 for calling a global function with example usage: _clean_and_truncate(text, max_num_words) and returns: str