autoencoderで、学習した結果を出力したいのですが、
python
1[[[0. 0. 0. 0. 0.24245892 0. 2 0. 0. 0. ] 3 [0. 0. 0. 0. 0. 0. 4 0. 0. 0.15186222]] 5 6 [[0. 0. 0. 0. 0. 0. 7 0. 0.27800256 0. ] 8 [0. 0.14638866 0. 0. 0. 0. 9 0. 0. 0. ]]] 10
となってしまいます。
原因を推測される方は何卒、宜しくお願い致します。
poem.txtは、
朝霧 の 中 に 九段 の ともし 哉 あたたか な 雨 が 降る なり 枯葎 菜の花 や は つと 明るき 町 は づれ 秋風 や 伊予 へ 流る る 汐 の 音 長閑 さ や 障子 の 穴 に 海 見え て
となっています。
python
1import numpy as np 2import codecs 3import keras 4from keras.layers import Activation, Dense, Input 5from keras.models import Model 6import sys 7 8with open(r'./Desktop/haiku.txt', encoding='utf-8') as f: 9 poems = f.readlines() 10 for p in poems: 11 s = p.rstrip() 12 s = s.split(' ') 13 14chars = sorted(list(set(poems))) 15char_indices = dict((c, i) for i, c in enumerate(chars)) 16maxlen = 2 17step = 3 18sentences = [] 19for i in range(0, len(poems) - maxlen, step): 20 sentences.append(poems[i: i + maxlen]) 21 22input_word = Input(shape=(maxlen, len(chars))) 23indices_char = dict((i, c) for i, c in enumerate(chars)) 24 25x = np.zeros((len(sentences), maxlen, len(chars)), dtype=np.bool) 26for i, sentence in enumerate(sentences): 27 for t, char in enumerate(sentence): 28 x[i, t, char_indices[char]] = 10 29 30encoding_dim = 128 31input_word = Input(shape=(maxlen, len(chars))) 32encoded_1 = Dense(128, activation='relu')(input_word) 33encoded_2 = Dense(64, activation='relu')(encoded_1) 34encoded_3 = Dense(32, activation='relu')(encoded_2) 35latent = Dense(8, activation='relu')(encoded_3) 36decoded_1 = Dense(32, activation='relu')(latent) 37decoded_2 = Dense(64, activation='relu')(decoded_1) 38decoded_3 = Dense(5, activation='relu')(encoded_2) 39autoencoder = Model(inputs=input_word, outputs=decoded_3) 40autoencoder.compile(optimizer='Adam', loss='categorical_crossentropy') 41 42autoencoder.fit(x, x, 43 epochs=1, 44 batch_size=150, 45 shuffle=False) 46bunsyo = autoencoder.predict(x[1:17], batch_size=10, verbose=1, steps=None) 47print(bunsyo)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/26 11:03 編集
2018/10/26 11:49
2018/10/26 11:54
2018/10/26 11:55
2018/10/26 12:01
2018/10/26 12:29 編集