コード例 #1
0
 def animation_update(frame_no, test_data, xf, im, text_fields):
     """Update an animation frame."""
     steps, inpt, out_raw = test_data
     length = len(steps)
     batch = frame_no / (fps * (l + 4 * xf))
     index = int((frame_no % (fps * (l + 4 * xf))) / fps)
     # Cut output after first padding.
     out = [out_raw[i][batch] for i in xrange(len(text_fields))]
     if 0 in out:
         i = out.index(0)
         out = out[0:i] + [0 for _ in xrange(len(out) - i)]
     # Show the state after the first frames.
     if index >= 2 * xf:
         im.set_array(steps[min(length - 1, index - 2 * xf)][batch])
         for i, t in enumerate(text_fields):
             if index - 2 * xf < length:
                 t.set_text("")
             else:
                 t.set_text(data.to_symbol(out[i]))
     else:
         for i, t in enumerate(text_fields):
             t.set_text(
                 data.to_symbol(inpt[i][batch]) if index < xf else "")
         if index < xf:
             im.set_array(np.zeros_like(steps[0][0]))
         else:
             im.set_array(steps[0][batch])
     return im,
コード例 #2
0
ファイル: neural_gpu_trainer.py プロジェクト: 1206lyp/models
 def animation_update(frame_no, test_data, xf, im, text_fields):
   """Update an animation frame."""
   steps, inpt, out_raw = test_data
   length = len(steps)
   batch = frame_no / (fps * (l+4*xf))
   index = int((frame_no % (fps * (l+4*xf))) / fps)
   # Cut output after first padding.
   out = [out_raw[i][batch] for i in xrange(len(text_fields))]
   if 0 in out:
     i = out.index(0)
     out = out[0:i] + [0 for _ in xrange(len(out) - i)]
   # Show the state after the first frames.
   if index >= 2*xf:
     im.set_array(steps[min(length - 1, index - 2*xf)][batch])
     for i, t in enumerate(text_fields):
       if index - 2*xf < length:
         t.set_text("")
       else:
         t.set_text(data.to_symbol(out[i]))
   else:
     for i, t in enumerate(text_fields):
       t.set_text(data.to_symbol(inpt[i][batch]) if index < xf else "")
     if index < xf:
       im.set_array(np.zeros_like(steps[0][0]))
     else:
       im.set_array(steps[0][batch])
   return im,
コード例 #3
0
ファイル: neural_gpu_trainer.py プロジェクト: 1206lyp/models
def interactive():
  """Interactively probe an existing model."""
  with tf.Session() as sess:
    model, _, _, _, _, _ = initialize(sess)
    sys.stdout.write("Input to Neural GPU, e.g., 0 1. Use -1 for PAD.\n")
    sys.stdout.write("> ")
    sys.stdout.flush()
    inpt = sys.stdin.readline()
    while inpt:
      ids = [data.to_id(s) for s in inpt.strip().split()]
      inpt, target = data.get_batch(len(ids), 1, False, "",
                                    preset=(ids, [0 for _ in ids]))
      _, res, _, _ = model.step(sess, inpt, target, False)
      res = [np.argmax(o, axis=1) for o in res]
      res = [o for o in res[:len(ids)] if o > 0]
      print "  " + " ".join([data.to_symbol(output[0]) for output in res])
      sys.stdout.write("> ")
      sys.stdout.flush()
      inpt = sys.stdin.readline()
コード例 #4
0
def interactive():
  """Interactively probe an existing model."""
  with tf.Session() as sess:
    model, _, _, _, _, _ = initialize(sess)
    sys.stdout.write("Input to Neural GPU, e.g., 0 1. Use -1 for PAD.\n")
    sys.stdout.write("> ")
    sys.stdout.flush()
    inpt = sys.stdin.readline()
    while inpt:
      ids = [data.to_id(s) for s in inpt.strip().split()]
      inpt, target = data.get_batch(len(ids), 1, False, "",
                                    preset=(ids, [0 for _ in ids]))
      _, res, _, _ = model.step(sess, inpt, target, False)
      res = [np.argmax(o, axis=1) for o in res]
      res = [o for o in res[:len(ids)] if o > 0]
      print("  " + " ".join([data.to_symbol(output[0]) for output in res]))
      sys.stdout.write("> ")
      sys.stdout.flush()
      inpt = sys.stdin.readline()