def parse_sparse_situation(situation_representation):
  """Parse sparse situation to dense grid.

  Code adapted from https://github.com/LauraRuis/multimodal_seq2seq_gSCAN/
    blob/master/read_gscan/read_gscan.py
  Each grid cell in a situation is fully specified by a vector:
  [_ _ _ _ _ _ _   _       _      _       _   _ _ _ _]
   1 2 3 4 r g b circle square cylinder agent E S W N
   _______ _____ ______________________ _____ _______
     size  color        shape           agent agent dir.

  Args:
    situation_representation: data from dataset.txt at key "situation".

  Returns:
    grid to be parsed by computational models.
  """
  grid_size = situation_representation['grid_size']
  num_object_attributes = len(
      _parse_vector(situation_representation['target_object']['vector']))
  # Object representation + agent bit + agent direction bits (see docstring).
  num_grid_channels = num_object_attributes + 1 + 4

  # Initialize the grid.
  grid = np.zeros([grid_size, grid_size, num_grid_channels], dtype=int)

  # Place the agent.
  agent_row = int(situation_representation['agent_position']['row'])
  agent_column = int(situation_representation['agent_position']['column'])
  agent_direction = int(situation_representation['agent_direction'])
  agent_representation = np.zeros([num_grid_channels], dtype=np.int32)
  agent_representation[-5] = 1
  agent_representation[-4 + agent_direction] = 1
  grid[agent_row, agent_column, :] = agent_representation

  # Loop over the objects in the world and place them.
  placed_objects = situation_representation['placed_objects']
  for idx, object_vector in enumerate(placed_objects['vector']):
    object_vector = np.array(_parse_vector(object_vector), dtype=np.int32)
    object_row = int(placed_objects['position']['row'][idx])
    object_column = int(placed_objects['position']['column'][idx])
    grid[object_row, object_column, :] = np.concatenate(
        [object_vector, np.zeros([5], dtype=np.int32)])
  return grid
Parse sparse situation to dense grid.

  Code adapted from https://github.com/LauraRuis/multimodal_seq2seq_gSCAN/
    blob/master/read_gscan/read_gscan.py
  Each grid cell in a situation is fully specified by a vector:
  [_ _ _ _ _ _ _   _       _      _       _   _ _ _ _]
   1 2 3 4 r g b circle square cylinder agent E S W N
   _______ _____ ______________________ _____ _______
     size  color        shape           agent agent dir.

  Args:
    situation_representation: data from dataset.txt at key "situation".

  Returns:
    grid to be parsed by computational models.
  
language/gscan/xattn_model/dataset/preprocess.py