首页 > 解决方案 > 使用 tf.contrib.lookup 和 tf.python.ops.lookup_ops 的正确上下文是什么?

问题描述

我知道tf.contrib.lookuptf.python.ops.lookup_ops包含相同的功能。tf.contrib.lookup.index_table_from_file但是使用and之间有什么区别 tf.python.ops.lookup_ops.index_table_from_file吗?我遇到了tf.python.ops.lookup_ops.index_table_from_fileseq2seq 教程中使用的代码,所以我想知道为什么不使用它tf.contrib.lookup.index_table_from_file呢?如果我想在我的代码中使用它,我应该使用哪一个?

标签: pythontensorflow

解决方案


它们是相同的,tensorflow.contrib.lookup.lookup_ops.*只是按原样导入tf.contrib.lookup.

使用tf.contrib.lookup.*而不是tf.python.ops.lookup_ops.*,不仅因为它更短,而且仅仅是因为前者是官方python API的一部分,而不是后者。

至于他们为什么tf.python.ops.lookup_ops.index_table_from_file直接在您提供的示例中使用,我不确定。也许他们觉得一个名为的文件utils/vocab_utils.py是他们拥有的“内部”东西,可以绕过公共 API。恕我直言,这不是导入您自己的代码的做法。


推荐阅读