Я пытаюсь сделать классификатор анализа настроений на основе набора данных о гнилых томатах . Я получаю эту ошибку:
AttributeError: у объекта 'RNN' нет атрибута '_output_tensor_cache'
К сожалению, нигде нет помощи. Я понятия не имею, где вообще посмотреть.
import pandas as pd
from sklearn.model_selection import train_test_split
from tensorflow import keras
from keras import Model
from tensorflow.keras.layers import LSTM, Embedding, Dense
import os
os.chdir('/home/nicolas/Documents/datasets')
df = pd.read_csv('rotten_tomatoes_reviews.csv', nrows=50_000)
df = df.loc[df.Review.str.len() >= 3]
array = df.Review.values
target = df.Freshness.values
tokenizer = keras.preprocessing.text.Tokenizer(num_words=3_000)
tokenizer.fit_on_texts(array)
vector = tokenizer.texts_to_sequences(array)
padded = keras.preprocessing.sequence.pad_sequences(vector, maxlen=40)
X_train, X_test, y_train, y_test = train_test_split(padded, target, test_size=2e-1)
class RNN(Model):
def __init__(self):
super(RNN, self).__init__()
self.rnn1 = LSTM(8, return_sequences=True, return_state=True)
self.rnn2 = LSTM(8)
self.emb1 = Embedding(input_dim=3_000, output_dim=50, input_length=40)
self.flc1 = Dense(2)
def __call__(self, inputs, training=None, mask=None):
x = self.emb1(inputs)
x = self.rnn1(x)
x = self.rnn2(x)
out = self.flc1(x)
print(out.shape)
return out
def main():
model = RNN()
model.compile(optimizer=keras.optimizers.Adam(0.001),
loss=keras.losses.BinaryCrossentropy(from_logits=True),
metrics=['accuracy'])
model.fit(X_train, y_train, batch_size=16, epochs=10,
validation_data=[X_test, y_test], verbose=1)
scores = model.evaluate(X_test, y_test, batch_size=16, verbose=1)
print("Final test loss and accuracy :", scores)
if __name__ == '__main__':
main()