text_plain_output_1.png
from keras.layers import Dropout, Activation, Flatten, \

from keras.layers import LSTM, GRU, SimpleRNN

from keras.models import Sequential,Model,load_model

from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, classification_report, confusion_matrix,precision_recall_fscore_support

from transformers import XLMRobertaTokenizer, TFAutoModel, TFAutoModelForSequenceClassification, TFXLMRobertaModel, XLMRobertaModel

MODEL_TYPE = 'xlm-roberta-large'
xlm_tokenizer = XLMRobertaTokenizer.from_pretrained(MODEL_TYPE)
xlm_model = TFAutoModel.from_pretrained(MODEL_TYPE)

embedding_matrix = xlm_model.get_input_embeddings().weight

def create_rnn_model(input_shape):
    model_xlm = Sequential()
    model_xlm.add(Embedding(250002, 1024, trainable=False, weights=[embedding_matrix.numpy()]))
    model_xlm.add(GRU(512, return_sequences=True))
    model_xlm.add(GRU(512, return_sequences=True))
    model_xlm.add(GlobalMaxPool1D())
    model_xlm.add(Dense(30, activation='relu'))
    model_xlm.add(Dropout(0.4))
    model_xlm.add(Dense(1, activation='sigmoid'))
    return model_xlm

model = create_rnn_model(X_train_xlm.shape[1:])
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
batch_size = 64
epochs = 10
history_model_xlm = model.fit(X_train_xlm, y_train_xlm, validation_split=0.2, batch_size=batch_size, epochs=epochs)

y_pred = (model.predict(X_test_xlm) > 0.5).astype(int)

print(classification_report(y_test_xlm, y_pred))