Pada kode python analisis sentimen data teks berita berbahasa Indonesia berjumlah 16.600 baris data dengan 1 berita mengandung sekitar 200-5000 kata menggunakan metode gabungan model CNN layer kemudian LSTM layer (CNN-LSTM) ini masih menggunakan epoch 50. Ubah epochnya menjadi 5 saja dan sesuaikan parameter yang lain agar tidak menimbulkan error pada kode!
import numpy as np
import pandas as pd
import pickle
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn.metrics import confusion_matrix, classification_report, accuracy_score
from keras.preprocessing.text import Tokenizer
from keras.utils import pad_sequences
from keras.models import Sequential
from keras.layers import Embedding, Conv1D, MaxPooling1D, LSTM, Dense
from keras.callbacks import EarlyStopping, ModelCheckpoint
import gensim
from gensim.models import Word2Vec

# Membaca dataset
data_list = pickle.load(open('pre_processed_beritaFIX_joined.pkl', 'rb'))
data = pd.DataFrame(data_list, columns=['judul', 'isi', 'pre_processed', 'Label'])
data['Isi Berita'] = data['pre_processed']

# Konversi label ke angka
encoder = LabelEncoder()
data['label_encoded'] = encoder.fit_transform(data['Label'])

# Memisahkan data menjadi data latih dan data uji
X_train, X_test, y_train, y_test = train_test_split(data['Isi Berita'], data['label_encoded'], test_size=0.25, random_state=42)

# Tokenisasi teks dan padding
max_words = 10000
sequence_length = 500
tokenizer = Tokenizer(num_words=max_words)
tokenizer.fit_on_texts(data['Isi Berita'])
X_train_seq = tokenizer.texts_to_sequences(X_train)
X_test_seq = tokenizer.texts_to_sequences(X_test)
X_train_padded = pad_sequences(X_train_seq, maxlen=sequence_length, padding='post', truncating='post')
X_test_padded = pad_sequences(X_test_seq, maxlen=sequence_length, padding='post', truncating='post')

# Membuka model word2vec
path = 'idwiki_word2vec_300.model'
id_w2v = gensim.models.word2vec.Word2Vec.load(path)
wv = id_w2v.wv

# Membuat embeding matrix
embedding_dim = id_w2v.vector_size
embedding_matrix = np.zeros((max_words, embedding_dim))

for word, i in tokenizer.word_index.items():
    if i < max_words:
        try:
            embedding_vector = wv[word]
            embedding_matrix[i] = embedding_vector
        except KeyError:
            pass

# Membangun model CNN-LSTM dengan pre-trained Word2Vec
num_filters = 64
lstm_units = 64

model = Sequential([
    Embedding(input_dim=max_words,
              output_dim=embedding_dim,
              input_length=sequence_length,
              weights=[embedding_matrix],  # Menggunakan pre-trained Word2Vec
              trainable=False),
    Conv1D(num_filters, 5, activation='relu'),
    MaxPooling1D(pool_size=4),
    LSTM(lstm_units, return_sequences=False),
    Dense(3, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])

# Melatih model dengan early stopping dan model checkpoint
checkpoint = ModelCheckpoint('model_cnn_lstm.h5', save_best_only=True, monitor='val_accuracy', mode='max')
early_stopping = EarlyStopping(monitor='val_loss', patience=10, verbose=1)

history = model.fit(X_train_padded, y_train, validation_split=0.2, epochs=50, batch_size=64, callbacks=[checkpoint, early_stopping])

# Evaluasi model pada data uji
y_pred = np.argmax(model.predict(X_test_padded), axis=-1)

# Hitung akurasi
accuracy = accuracy_score(y_test, y_pred)
print('Akurasi: {:.2f}%'.format(accuracy * 100))

# Print classification report
print(classification_report(y_test, y_pred, target_names=encoder.classes_))