首页 > 解决方案 > theano.function 如何成为 python 中另一个函数的输入?

问题描述

我有两个 .py 文件。在其中一个中,我有这个功能:

    def score_semeval2015_term(pred_fn, nnet_outdir, data_dir):
  def predict(dataset):
    x_test = numpy.load(os.path.join(data_dir, 'semeval_{}_x.npy').format(dataset))
    x_test_term = numpy.load(os.path.join(data_dir, 'semeval_{}_x_term.npy').format(dataset))
    print dataset, x_test.shape
    predictions = pred_fn(x_test, x_test_term)
    y2label = {0: 'negative', 1: 'neutral', 2: 'positive'}
    labels = [y2label[y] for y in predictions]
    return labels

而 pred_fn 是在另一个 .py 文件中定义的 theano.function,如下所示:

pred_fn = theano.function(inputs=inputs_pred,
                        outputs=predictions,
                        givens=givens_pred)

我的问题是,一个函数怎么可能作为另一个函数的输入?调用 score_semeval2015_term(pred_fn, nnet_outdir, data_dir) 函数时应该如何获取它的输入?谢谢你。

标签: pythonfunctiontheano

解决方案


推荐阅读