我正在使用Keras,我想构建一个新模型,但是出现以下错误:赋值之前引用了局部变量'a'
UnboundLocalError Traceback (most recent
call last)
<ipython-input-23-33520c18d79c> in <module>
16 model = Sequential()
17 model.add(Embedding(vocab_size, embed_dim))
---> 18 model.add(LSTM(nhid, dropout_W=0.2, dropout_U=0.2))
19 model.add(Dense(n_classes, activation='softmax'))
我试图更改我的keras版本,但是没有用(我降级为2.2.2)。 这是我的代码:
from keras.models import Sequential
from keras.layers import Embedding, LSTM, Dense, Activation ,
Conv1D,MaxPooling1D , Bidirectional
embed_dim = max_len # word embedding dimension
nhid = 64 # number of hidden units in the LSTM
vocab_size = len(words) # size of the vocabulary
n_classes = 5
model = Sequential()
model.add(Embedding(vocab_size, embed_dim))
model.add(LSTM(nhid, dropout_W=0.2, dropout_U=0.2))
model.add(Dense(n_classes, activation='softmax'))
有什么想法吗?