Kode analisis sentimen CNN-LSTM ini menggunakan FastText sebagai vektor representasi kata serta StratifiedKFold. Tolong ubah vektor representasi katanya menjadi menggunakan indobenchmark/indobert-large-p1 (IndoBERT)! Kode:
"import pickle
import pandas as pd
import numpy as np
from keras.preprocessing.text import Tokenizer
from keras.utils import pad_sequences
from keras.models import Sequential
from keras.layers import Embedding, LSTM, Dense, Dropout, Conv1D, MaxPooling1D
from keras.layers import Flatten
from keras.utils import to_categorical
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score, classification_report
import gensim
from gensim.models import KeyedVectors
from keras.regularizers import l2
# Parameter untuk regularisasi L2
l2_coeff = 0.01

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

# Tokenisasi dan Padding
max_words = 10000  # mengurangi jumlah kata maksimum
max_len =  500     # mengurangi panjang input
tokenizer = Tokenizer(num_words=max_words)
tokenizer.fit_on_texts(data['Isi Berita'])
sequences = tokenizer.texts_to_sequences(data['Isi Berita'])
X = pad_sequences(sequences, maxlen=max_len)
y = to_categorical(data['Label'].astype('category').cat.codes)

# Membagi data menjadi data latih dan data uji
X_train, X_test, y_train, y_test, idx_train, idx_test = train_test_split(X, y, data.index, test_size=0.25, random_state=42)


# Menggunakan pre-trained Fasttext Bahasa Indonesia
model_path = 'fasttext.4B.id.300.epoch5.uncased'
vector_file = 'fasttext.4B.id.300.epoch5.uncased.vec'
id_ft = KeyedVectors.load_word2vec_format(vector_file)

# Membuat matriks embedding
embedding_dim = 300
embedding_matrix = np.zeros((max_words, embedding_dim))
for word, i in tokenizer.word_index.items():
    if i < max_words:
        try:
            embedding_vector = id_ft[word]
            embedding_matrix[i] = embedding_vector
        except KeyError:
            pass
from keras.optimizers import Adam
from keras.callbacks import EarlyStopping
from sklearn.model_selection import StratifiedKFold

# Inisialisasi StratifiedKFold
n_splits = 5
skf = StratifiedKFold(n_splits=n_splits, shuffle=True, random_state=42)

# Konversi kategori target ke nilai numerik
y_categorical = data['Label'].astype('category').cat.codes

# Menyimpan akurasi, report, dan history untuk setiap fold
accuracies = []
class_reports = []
histories = []

iter_num = 1

for train_index, test_index in skf.split(X, y_categorical):
    print("\nTraining and evaluating model for fold", iter_num)
    
    # Membagi data berdasarkan indeks dari fold saat ini
    X_train, X_test = X[train_index], X[test_index]
    y_train, y_test = y[train_index], y[test_index]
    
    # Membangun model untuk fold saat ini

    model = Sequential([
        Embedding(input_dim=10000,
                  output_dim=300,
                  input_length=500,
                  weights=[embedding_matrix], 
                  trainable=False),
        Conv1D(256, 3, activation='relu', kernel_regularizer=l2(0.01)),
        MaxPooling1D(pool_size=4),
        LSTM(200, return_sequences=False, kernel_regularizer=l2(0.01), recurrent_regularizer=l2(0.01)),
        Dense(32, activation='relu', kernel_regularizer=l2(0.01)),
        Dropout(0.5),
        Dense(3, activation='softmax')
    ])

    # Buat callback early stopping
    callback_es = EarlyStopping(monitor='val_loss', patience=5, verbose=1, restore_best_weights=True)

    # Optimizer
    optimizer = Adam(learning_rate=0.0001)

    # Menyusun Model
    model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])

    # Melatih Model
    history = model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=100, batch_size=128, callbacks=[callback_es])
    histories.append(history)
    model.save('CNN-LSTM_FastText_Tertinggi_CNN256_LSTM200_' + str(iter_num) + '.h5')
    
    # Evaluasi model pada lipatan saat ini
    y_pred = model.predict(X_test)
    y_pred_labels = np.argmax(y_pred, axis=1)
    y_test_labels = np.argmax(y_test, axis=1)
    
    # Menghitung akurasi
    accuracy = accuracy_score(y_test_labels, y_pred_labels)
    print("Fold", iter_num, "Accuracy: {:.2f}%".format(accuracy * 100))
    
    # Classification report
    class_report = classification_report(y_test_labels, y_pred_labels)
    
    # Menambahkan akurasi dan report ke daftar
    accuracies.append(accuracy)
    class_reports.append(class_report)
    
    iter_num +=1

# Hitung rata-rata akurasi dan cetak report klasifikasi untuk setiap fold
average_accuracy = np.mean(accuracies)
print("\nAverage accuracy across folds: {:.2f}%".format(average_accuracy * 100))

for i, report in enumerate(class_reports):
    print("\nClassification report for fold", i + 1)
    print(report)
"