質問編集履歴
1
ソースコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -45,3 +45,43 @@
|
|
45
45
|
変数の初期化などの問題では無いように思えるのですが、
|
46
46
|
|
47
47
|
word_vectors の出力を見るためにはどのようにしたら良いでしょうか?
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
---
|
54
|
+
|
55
|
+
---
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
最短のソースコードを追記します。
|
60
|
+
|
61
|
+
X,embeddingなどは動的に作っても同じだと思います
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
```python3
|
66
|
+
|
67
|
+
import tensorflow as tf
|
68
|
+
|
69
|
+
from tensorflow.python.ops import embedding_ops
|
70
|
+
|
71
|
+
X=[ [1, 2, 4 , 0 , 0 ], [ 1,3 ,3 ,4, 0 ] ]
|
72
|
+
|
73
|
+
embedding=[ [ 0, 0 ] , [ 1 , 1 ] , [ 2 , 2 ] , [ 3 , 3 ] , [ 4 , 4 ] , ]
|
74
|
+
|
75
|
+
sess = tf.Session()
|
76
|
+
|
77
|
+
sess.run(tf.global_variables_initializer())
|
78
|
+
|
79
|
+
init = tf.constant_initializer( embedding )
|
80
|
+
|
81
|
+
embeddings = tf.get_variable('embeddings', shape=[ len( embedding) , len( embedding[0]) ] , initializer=init , trainable=False )
|
82
|
+
|
83
|
+
word_vectors = embedding_ops.embedding_lookup(embeddings, X , name='words' )
|
84
|
+
|
85
|
+
print( sess.run( word_vectors ) )
|
86
|
+
|
87
|
+
```
|