當前位置: 首頁>>代碼示例>>Python>>正文


Python Device.make_givens方法代碼示例

本文整理匯總了Python中Device.Device.make_givens方法的典型用法代碼示例。如果您正苦於以下問題:Python Device.make_givens方法的具體用法?Python Device.make_givens怎麽用?Python Device.make_givens使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Device.Device的用法示例。


在下文中一共展示了Device.make_givens方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_multi_target_init

# 需要導入模塊: from Device import Device [as 別名]
# 或者: from Device.Device import make_givens [as 別名]

#.........這裏部分代碼省略.........
  assert_equal(dataset.is_data_sparse("t1"), True)
  assert_equal(dataset.is_data_sparse("t2"), True)

  # Copy to device allocation.
  success = assign_dev_data_single_seq(device, dataset, 0)
  assert_true(success, "failed to allocate & assign data")

  # Check allocated data.
  assert_equal(device.targets["data"].shape, (1, 1, 3))  # input shape. (time,batch,dim)
  assert_in("t1", device.targets)
  assert_in("t2", device.targets)
  assert_equal(device.targets["t1"].shape, (1, 1))
  assert_equal(device.targets["t2"].shape, (1, 1))
  assert_equal(device.output_index["data"].shape, (1, 1))
  numpy.testing.assert_equal(device.output_index["data"], numpy.array([[1]]))
  assert_equal(device.output_index["t1"].shape, (1, 1))
  numpy.testing.assert_equal(device.output_index["t1"], numpy.array([[1]]))

  # Forward test.
  device.update_data()
  device.testnet.costs["out1"].name = "out1_cost"  # nice in the func graph
  out_i1 = device.testnet.output["out1"].index
  out_i1_nonzero = device.testnet.output["out1"].i
  nll1, pcx1 = T.nnet.crossentropy_softmax_1hot(x=device.testnet.output["out1"].y_m[out_i1_nonzero],
                                                y_idx=device.testnet.output["out1"].y_data_flat[out_i1_nonzero])
  forward_func = theano.function(
    inputs=[device.block_start, device.block_end],
    outputs=[
      device.testnet.j["t1"], out_i1, out_i1_nonzero[0], nll1, pcx1,
      device.testnet.costs["out1"],
      device.testnet.output["out1"].p_y_given_x,
      device.testnet.costs["out2"],
      device.testnet.output["out2"].p_y_given_x],
    givens=device.make_givens(device.testnet),
    no_default_updates=True,
    on_unused_input='warn',
    name="forward")
  #print "forward func:"
  #theano.printing.debugprint(forward_func)
  net_j1, out_i1_val, out_i1_nz_val, nll1_val, pcx1_val, t1_cost, t1_y, t2_cost, t2_y = forward_func(0, 1)
  print "forward results:"
  pprint(net_j1)
  pprint(out_i1_val)
  pprint(out_i1_nz_val)
  pprint(nll1_val)
  pprint(pcx1_val)
  pprint(t1_cost)
  pprint(t1_y)
  pprint(t2_cost)
  pprint(t2_y)
  assert_equal(net_j1, numpy.array([[1]]))
  assert_equal(out_i1_val, numpy.array([[1]]))
  assert_equal(out_i1_nz_val, numpy.array([0]))
  assert_almost_equal(nll1_val, numpy.array([t1_cost]))
  numpy.testing.assert_almost_equal(t1_y, pcx1_val)
  assert_almost_equal(t1_cost, 1.440189698561195, places=6)
  assert_almost_equal(t2_cost, 0.45191439593759336, places=6)
  numpy.testing.assert_almost_equal(t1_y, numpy.array([[ 0.0320586 ,  0.08714432,  0.23688282,  0.64391426]]), decimal=6)
  numpy.testing.assert_almost_equal(t2_y, numpy.array([[ 0.01165623,  0.03168492,  0.08612854,  0.23412166,  0.63640865]]), decimal=6)

  # One train step.
  device.set_learning_rate(config.typed_value("learning_rate"))
  device.run("train")
  output_list, outputs_format = device.result()
  assert_is_instance(output_list, list)
  assert_true(outputs_format, "for train, we should always get the format")
開發者ID:atuxhe,項目名稱:returnn,代碼行數:70,代碼來源:test_multi_target.py


注:本文中的Device.Device.make_givens方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。