Генератор последовательностей TFlearn
Поэтому я обучил рекуррентную нейронную сеть классифицировать предложения на две разные категории. Теперь я хотел использовать его для восстановления новых.
Я закомментировал весь ненужный код.
import tflearn
from tflearn.data_utils import to_categorical, pad_sequences
import pickle
# from sklearn.cross_validation import train_test_split
#
# with open('data.pkl','rb') as f:
# data = pickle.load(f)
# with open('label.pkl','rb') as g:
# label = pickle.load(g)
with open('dictionary.pkl','rb') as h:
dictionary = pickle.load(h)
#trainX,testX,trainY,testY = train_test_split(data,label,test_size=0.2,
# random_state=True)
dicto={}
for i in range(len(dictionary)):
dicto[dictionary[i]]=i
#
# trainX = pad_sequences(trainX, maxlen=42, value=0.)
# testX = pad_sequences(testX, maxlen=42, value=0.)
# trainY = to_categorical(trainY)
# testY = to_categorical(testY)
net = tflearn.input_data([None,42])
net = tflearn.embedding(net, input_dim=2094, output_dim=150)
net = tflearn.lstm(net,150)
net = tflearn.fully_connected(net, 2, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=0.001,
loss='categorical_crossentropy')
model = tflearn.SequenceGenerator(net,dictionary=dicto,tensorboard_verbose=0,tensorboard_dir='dating/')
model.load('generate.model')
# Error are generated here
seq = model.generate(15,seq_seed=["hello","there"])
print(seq)
#Uncomment to retrain
# try:
# model.fit(trainX, trainY,show_metric=True,
# n_epoch=100,validation_set=(testX,testY))
# except KeyboardInterrupt:
# model.save('generate.model')
Произошла ошибка:
Traceback (most recent call last):
File "C:/Users/PycharmProjects/Recurrent/rnn.py", line 34, in <module>
seq = model.generate(15,seq_seed=["hello","there"])
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tflearn\models\generator.py", line 216, in generate
preds = self._predict(x)[0].tolist()
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tflearn\models\generator.py", line 180, in _predict
return self.predictor.predict(feed_dict)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tflearn\helpers\evaluator.py", line 69, in predict
return self.session.run(self.tensors[0], feed_dict=feed_dict)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 905, in run
run_metadata_ptr)
File "C:\Users\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\python\client\session.py", line 1116, in _run
str(subfeed_t.get_shape())))
ValueError: Cannot feed value of shape (1, 25, 2094) for Tensor 'InputData/X:0', which has shape '(?, 42)'
Я попытался изменить слой input_data на [None,2094] и [None,25,2094], и оба не работали. Пожалуйста, помогите мне.
А вот небольшой кусок словаря слов для вектора в переменной 'dicto', если вам интересно.
{'thats': 1825, 'ariel': 97, 'yesterday': 2077, 'alzheimer': 64, 'crossword': 425, 'squad': 1694, 'disappears': 508, 'sex': 1579, 'lovely': 1106, 'motor': 1205, 'planets': 1365, 'please': 1372, 'butt': 260, 'boy': 223, 'dance': 446, 'worry': 2057, 'karate': 991, 'already': 59, 'body': 203, 'elevator': 575, 'might': 1178, 'front': 733, 'gin': 762, 'driver': 548, 'equal': 594, 'went': 2006, 'snuggie': 1650, 'encounter': 584, 'shake': 1582, 'swim': 1783, 'like': 1069, 'spend': 1686, 'stiff': 1720, 'about': 18, 'olympics': 1271, 'exothermic': 620, 'almost': 56, 'dancing': 448, 'flips': 691, 'touch': 1882, 'triple': 1901, 'version': 1947, 'squitals': 1697, 'move': 1211, 'phone': 1348, 'express': 625, 'alone': 57, 'mcgorgeous': 1149, 'fonzi': 707, 'warm': 1976, 'heroin': 863, 'point': 1377, 'lining': 1076, 'princess': 1415, 'sqeeze': 1693, 'gift': 760, 'wants': 1975, 'tooth': 1878, 'style': 1746, 'making': 1126, 'drawn': 540, 'believed': 168, 'north': 1247, 'bye': 265, 'impact': 916, 'seem': 1567, 'apocalypse': 86, 'dragon': 537, 'flowers': 699, 'stuff': 1741, '2008': 7, 'matched': 1138, 'weather': 1994, 'honeymoon': 883, 'mart': 1135, 'temptation': 1813, 'behaved': 164, 'still': 1721, 'destined': 484, 'aesthetically': 38, 'grateful': 797, 'spending': 1687, 'nailed': 1222, 'familiar': 639, 'advertising': 37}