code: def save_transformed_sample(opts, transforms, n_sample=3):
      """Save transformed data sample as specified in opts."""
  
      if n_sample == -1:
          logger.info(
              f"n_sample={n_sample}: Save full transformed corpus."
          )
      elif n_sample == 0:
          logger.info(f"n_sample={n_sample}: no sample will be saved.")
          return
      elif n_sample > 0:
          logger.info(f"Save {n_sample} transformed example/corpus.")
      else:
          raise ValueError(f"n_sample should >= -1, get {n_sample}.")
  
      corpora = get_corpora(opts, CorpusTask.TRAIN)
      datasets_iterables = build_corpora_iters(
          corpora,
          transforms,
          opts.data,
          skip_empty_level=opts.skip_empty_level,
      )
      sample_path = os.path.join(
          os.path.dirname(opts.save_data), CorpusName.SAMPLE
      )
      os.makedirs(sample_path, exist_ok=True)
      for c_name, c_iter in datasets_iterables.items():
          dest_base = os.path.join(
              sample_path, "{}.{}".format(c_name, CorpusName.SAMPLE)
          )
          with open(
              dest_base + ".src", "w", encoding="utf-8"
          ) as f_src, open(
              dest_base + ".tgt", "w", encoding="utf-8"
          ) as f_tgt:
              bucket = []
              for i, ex in enumerate(c_iter):
                  if i > n_sample:
                      break
                  else:
                      bucket.append(ex)
              pro_bucket = process(CorpusTask.TRAIN, bucket)
              if pro_bucket is not None:
                  for maybe_example in pro_bucket:
                      if maybe_example is not None:
                          src_line, tgt_line = (
                              maybe_example["src"]["src"],
                              maybe_example["tgt"]["tgt"],
                          )
  
                          if "feats" in maybe_example["src"]:
                              src_feats_lines = maybe_example["src"][
                                  "feats"
                              ]
                          else:
                              src_feats_lines = []
  
                          src_pretty_line = append_features_to_text(
                              src_line, src_feats_lines
                          )
  
                          f_src.write(src_pretty_line + "\n")
                          f_tgt.write(tgt_line + "\n")
  
imports: import os
  from onmt.utils.logging import logger
  from onmt.constants import CorpusName, CorpusTask
  from onmt.transforms import TransformPipe
  from onmt.inputters.text_utils import process, parse_features, append_features_to_text
  from contextlib import contextmanager
  import itertools
label_desc: Use image node_id 4 for calling a global function with example usage: save_transformed_sample(opts, transforms, n_sample) without return types