我尝试使用 tft.compute_and_apply_vocabulary 和 tft.tfidf 在我的 jupyter notebook 中计算 tfidf。但是我总是收到以下错误:
tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'compute_and_apply_vocabulary/vocabulary/Placeholder' with dtype string
[[node compute_and_apply_vocabulary/vocabulary/Placeholder (defined at C:\Users\secsi\Anaconda3\envs\tf2\lib\site-packages\tensorflow_
但占位符类型实际上是字符串。
这是我的代码:
import tensorflow as tf
import tensorflow_transform as tft
with tf.Session() as sess:
documents = [
"a b c d e",
"f g h i j",
"k l m n o",
"p q r s t",
]
documents_tensor = tf.placeholder(tf.string)
tokens = tf.compat.v1.string_split(documents_tensor)
compute_vocab = tft.compute_and_apply_vocabulary(tokens, vocab_filename='vocab.txt')
global_vars_init = tf.global_variables_initializer()
tabel_init = tf.tables_initializer()
sess.run([global_vars_init, tabel_init])
token2ids = sess.run(tfidf, feed_dict={documents_tensor: documents})
print(f"token2ids: {token2ids}")
版本:
- 张量流:1.14
- 张量流变换:0.14
提前致谢!