code: def convert_data(train_data, max_memory):
      all_data = []
      sentence_len = max(
          max(len(s.sentence) for s in story) for story in train_data
      )
      for story in train_data:
          mem = numpy.zeros(
              (max_memory, sentence_len), dtype=numpy.int32
          )
          i = 0
          for sent in story:
              if isinstance(sent, babi.Sentence):
                  if i == max_memory:
                      mem[0 : i - 1, :] = mem[1:i, :]
                      i -= 1
                  mem[i, 0 : len(sent.sentence)] = sent.sentence
                  i += 1
              elif isinstance(sent, babi.Query):
                  query = numpy.zeros(sentence_len, dtype=numpy.int32)
                  query[0 : len(sent.sentence)] = sent.sentence
                  all_data.append(
                      {
                          "sentences": mem.copy(),
                          "question": query,
                          "answer": numpy.array(
                              sent.answer, numpy.int32
                          ),
                      }
                  )
  
      return all_data
  
imports: import collections
  import json
  import os
  import numpy
  import six
  import chainer
  from chainer import backend
  import chainer.functions
  from chainer import initializers
  import chainer.links
  import babi
label_desc: Use image node_id 4 for calling a global function with example usage: convert_data(train_data, max_memory) and returns: all_data