code: def _get_named_tuple_from_ngram(ngram, dataset_dicts, starting_index):
      expected_ngram = {}
      for index, key in enumerate(
          range(min(ngram.fields.keys()), max(ngram.fields.keys()) + 1)
      ):
          if key in ngram.fields:
              current_field_names = [
                  field.name for field in ngram.fields[key]
              ]
          else:
              current_field_names = []
          new_schema = TestSchema.create_schema_view(
              [
                  TestSchema.fields.get(field)
                  for field in TestSchema.fields
                  if field in current_field_names
              ]
          )
          current_dict = dataset_dicts[starting_index + index]
          new_dict = {
              k: current_dict[k]
              for k in current_dict
              if k in current_field_names
          }
          expected_ngram[key] = new_schema.make_namedtuple(**new_dict)
      return expected_ngram
  
imports: from decimal import Decimal
  import numpy
  import pytest
  import tensorflow.compat.v1
  from unittest import mock
  from petastorm import make_reader
  from petastorm.ngram import NGram
  from petastorm.tests.conftest import SyntheticDataset, maybe_cached_dataset
  from petastorm.tests.test_common import create_test_dataset, TestSchema
  from petastorm.tests.test_tf_utils import create_tf_graph
  from petastorm.tf_utils import tf_tensors
label_desc: Use image node_id 5 for calling a global function with example usage: _get_named_tuple_from_ngram(ngram, dataset_dicts, starting_index) and returns: expected_ngram