RMDL: Random Multimodel Deep Learning for Classification
This project is maintained by kk7nc
Referenced paper : RMDL: Random Multimodel Deep Learning for Classification
A new ensemble, deep learning approach for classification. Deep learning models have achieved state-of-the-art results across many domains. RMDL solves the problem of finding the best deep learning structure and architecture while simultaneously improving robustness and accuracy through ensembles of deep learning architectures. RDML can accept asinput a variety data to include text, video, images, and symbolic.

Overview of RDML: Random Multimodel Deep Learning for classification. The RMDL includesnRandom modelswhich aredrandom model of DNN classifiers, cmodels of CNN classifiers, andrRNN classifiers wherer+c+d=n.

Random Multimodel Deep Learning (RDML) architecture for classification. RMDL includes 3 Random models, oneDNN classifier at left, one Deep CNN classifier at middle, and one Deep RNN classifier at right (each unit could be LSTMor GRU).
There are git RMDL in this repository; to clone all the needed files, please use:
pip install RMDL
git clone --recursive https://github.com/kk7nc/RMDL.git
The primary requirements for this package are Python 3 with Tensorflow. The requirements.txt file contains a listing of the required Python packages; to install all requirements, run the following:
pip -r install requirements.txt
Or
pip3 install -r requirements.txt
Or:
conda install --file requirements.txt
The exponential growth in the number of complex datasets every year requires more enhancement in machine learning methods to provide robust and accurate data classification. Lately, deep learning approaches have been achieved surpassing results in comparison to previous machine learning algorithms on tasks such as image classification, natural language processing, face recognition, and etc. The success of these deep learning algorithms relys on their capacity to model complex and non-linear relationships within data. However, finding the suitable structure for these models has been a challenge for researchers. This paper introduces Random Multimodel Deep Learning (RMDL): a new ensemble, deep learning approach for classification. RMDL solves the problem of finding the best deep learning structure and architecture while simultaneously improving robustness and accuracy through ensembles of deep learning architectures. In short, RMDL trains multiple models of Deep Neural Network (DNN), Convolutional Neural Network (CNN) and Recurrent Neural Network (RNN) in parallel and combines their results to produce better result of any of those models individually. To create these models, each deep learning model has been constructed in a random fashion regarding the number of layers and nodes in their neural network structure. The resulting RDML model can be used for various domains such as text, video, images, and symbolic. In this Project, we describe RMDL model in depth and show the results for image and text classification as well as face recognition. For image classification, we compared our model with some of the available baselines using MNIST and CIFAR-10 datasets. Similarly, we used four datasets namely, WOS, Reuters, IMDB, and 20newsgroup and compared our results with available baselines. Web of Science (WOS) has been collected by authors and consists of three sets~(small, medium and large set). Lastly, we used ORL dataset to compare the performance of our approach with other face recognition methods. These test results show that RDML model consistently outperform standard methods over a broad range of data types and classification problems.
Web of Science Dataset (DOI: 10.17632/9rw3vkcfy4.2)
The Database of Faces (The Olivetti Faces Dataset)
from RMDL import RMDL_Text
Text_Classification(x_train, y_train, x_test, y_test, batch_size=128,
EMBEDDING_DIM=50,MAX_SEQUENCE_LENGTH = 500,
MAX_NB_WORDS = 75000, GloVe_dir="",
GloVe_file = "glove.6B.50d.txt",
sparse_categorical=True, random_deep=[3, 3, 3],
epochs=[500, 500, 500], plot=True,
min_hidden_layer_dnn=1, max_hidden_layer_dnn=8,
min_nodes_dnn=128, max_nodes_dnn=1024,
min_hidden_layer_rnn=1, max_hidden_layer_rnn=5,
min_nodes_rnn=32, max_nodes_rnn=128,
min_hidden_layer_cnn=3, max_hidden_layer_cnn=10,
min_nodes_cnn=128, max_nodes_cnn=512,
random_state=42, random_optimizor=True, dropout=0.05):
random_state : Integer, RandomState instance or None, optional (default=None)
from RMDL import RMDL_Image
Image_Classification(x_train, y_train, x_test, y_test, shape, batch_size=128,
sparse_categorical=True, random_deep=[3, 3, 3],
epochs=[500, 500, 500], plot=True,
min_hidden_layer_dnn=1, max_hidden_layer_dnn=8,
min_nodes_dnn=128, max_nodes_dnn=1024,
min_hidden_layer_rnn=1, max_hidden_layer_rnn=5,
min_nodes_rnn=32, max_nodes_rnn=128,
min_hidden_layer_cnn=3, max_hidden_layer_cnn=10,
min_nodes_cnn=128, max_nodes_cnn=512,
random_state=42, random_optimizor=True, dropout=0.05)
random_state : Integer, RandomState instance or None, optional (default=None)
from keras.datasets import mnist
import numpy as np
from RMDL import RMDL_Image as RMDL
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train_D = X_train.reshape(X_train.shape[0], 28, 28, 1).astype('float32')
X_test_D = X_test.reshape(X_test.shape[0], 28, 28, 1).astype('float32')
X_train = X_train_D / 255.0
X_test = X_test_D / 255.0
number_of_classes = np.unique(y_train).shape[0]
shape = (28, 28, 1)
batch_size = 128
sparse_categorical = 0
Random_Deep = [3, 3, 3] ## DNN--RNN-CNN
RMDL.Image_Classification(X_train, y_train, X_test, y_test,shape,
batch_size=batch_size,
sparse_categorical=True,
random_deep=Random_Deep,
epochs=n_epochs)
import sys
import os
from RMDL import text_feature_extraction as txt
from keras.datasets import imdb
import numpy as np
from RMDL import RMDL_Text as RMDL
print("Load IMDB dataset....")
(X_train, y_train), (X_test, y_test) = imdb.load_data(num_words=MAX_NB_WORDS)
print(len(X_train))
print(y_test)
word_index = imdb.get_word_index()
index_word = {v: k for k, v in word_index.items()}
X_train = [txt.text_cleaner(' '.join(index_word.get(w) for w in x)) for x in X_train]
X_test = [txt.text_cleaner(' '.join(index_word.get(w) for w in x)) for x in X_test]
X_train = np.array(X_train)
X_train = np.array(X_train).ravel()
print(X_train.shape)
X_test = np.array(X_test)
X_test = np.array(X_test).ravel()
batch_size = 100
sparse_categorical = 0
n_epochs = [500, 500, 500] ## DNN--RNN-CNN
Random_Deep = [3, 3,3] ## DNN--RNN-CNN
RMDL.Text_Classification(X_train, y_train, X_test, y_test,
batch_size=batch_size,
sparse_categorical=sparse_categorical,
random_deep=Random_Deep,
epochs=n_epochs)
from RMDL import text_feature_extraction as txt
from sklearn.model_selection import train_test_split
from RMDL.Download import Download_WOS as WOS
import numpy as np
from RMDL import RMDL_Text as RMDL
path_WOS = WOS.download_and_extract()
fname = os.path.join(path_WOS,"WebOfScience/WOS11967/X.txt")
fnamek = os.path.join(path_WOS,"WebOfScience/WOS11967/Y.txt")
with open(fname, encoding="utf-8") as f:
content = f.readlines()
content = [txt.text_cleaner(x) for x in content]
with open(fnamek) as fk:
contentk = fk.readlines()
contentk = [x.strip() for x in contentk]
Label = np.matrix(contentk, dtype=int)
Label = np.transpose(Label)
np.random.seed(7)
print(Label.shape)
X_train, X_test, y_train, y_test = train_test_split(content, Label, test_size=0.2, random_state=4)
batch_size = 100
sparse_categorical = 0
n_epochs = [100, 100, 100] ## DNN--RNN-CNN
Random_Deep = [3, 3, 3] ## DNN--RNN-CNN
RMDL.Text_Classification(X_train, y_train, X_test, y_test,
batch_size=batch_size,
sparse_categorical=True,
random_deep=Random_Deep,
epochs=n_epochs)
import sys
import os
import nltk
nltk.download("reuters")
from nltk.corpus import reuters
from sklearn.preprocessing import MultiLabelBinarizer
import numpy as np
from RMDL import RMDL_Text as RMDL
documents = reuters.fileids()
train_docs_id = list(filter(lambda doc: doc.startswith("train"),
documents))
test_docs_id = list(filter(lambda doc: doc.startswith("test"),
documents))
X_train = [(reuters.raw(doc_id)) for doc_id in train_docs_id]
X_test = [(reuters.raw(doc_id)) for doc_id in test_docs_id]
mlb = MultiLabelBinarizer()
y_train = mlb.fit_transform([reuters.categories(doc_id)
for doc_id in train_docs_id])
y_test = mlb.transform([reuters.categories(doc_id)
for doc_id in test_docs_id])
y_train = np.argmax(y_train, axis=1)
y_test = np.argmax(y_test, axis=1)
batch_size = 100
sparse_categorical = 0
n_epochs = [120, 120, 120] ## DNN--RNN-CNN
Random_Deep = [3, 3, 3] ## DNN--RNN-CNN
RMDL.Text_Classification(X_train, y_train, X_test, y_test,
batch_size=batch_size,
sparse_categorical=True,
random_deep=Random_Deep,
epochs=n_epochs)
from sklearn.datasets import fetch_olivetti_faces
from sklearn.model_selection import train_test_split
from RMDL import RMDL_Image as RMDL
number_of_classes = 40
shape = (64, 64, 1)
data = fetch_olivetti_faces()
X_train, X_test, y_train, y_test = train_test_split(data.data,
data.target, stratify=data.target, test_size=40)
X_train = X_train.reshape(X_train.shape[0], 64, 64, 1).astype('float32')
X_test = X_test.reshape(X_test.shape[0], 64, 64, 1).astype('float32')
batch_size = 100
sparse_categorical = 0
n_epochs = [150, 150, 150] ## DNN--RNN-CNN
Random_Deep = [3, 0, 3] ## DNN--RNN-CNN
RMDL.Image_Classification(X_train, y_train, X_test, y_test,
shape,
batch_size=batch_size,
random_deep=Random_Deep,
epochs=n_epochs)
| Methods | MNIST | CIFAR-10 |
|---|---|---|
| Deep L2-SVM | 0.87 | 11.9 |
| Maxout Network | 0.94 | 11.68 |
| BinaryConnect | 1.29 | 9.90 |
| PCANet-1 | 0.62 | 21.33 |
| gcForest | 0.74 | 31.00 |
| RMDL (3 RDLs) | 0.51 | 9.89 |
| RMDL (9 RDLs) | 0.41 | 9.1 |
| RMDL (15 RDLs) | 0.21 | 8.74 |
| RMDL (30 RDLs) | 0.18 | 8.79 |
Web of Science Dataset (DOI: 10.17632/9rw3vkcfy4.2)
| WOS-5,736 | WOS-11,967 | WOS-46,985 | Reuters-21578 | |
|---|---|---|---|---|
| Deep Neural Networks (DNN) | 86.15 | 80.02 | 66.95 | 85.3 |
| Convolutional Neural Netwroks (CNN) | 88.68 | 83.29 | 70.46 | 86.3 |
| Recurrent Neural Networks (DNN) | 89.46 | 83.96 | 72.12 | 88.4 |
| Naive Bayesian Classifier | 78.14 | 68.8 | 46.2 | 83.6 |
| Support Vector Machine (SVM) | 85.54 | 80.65 | 67.56 | 86.9 |
| Support Vector Machine (SVM using TF-IDF) | 88.24 | 83.16 | 70.22 | 88.93 |
| Stacking Support Vector Machine | 85.68 | 79.45 | 71.81 | NA |
| HDLTex | 90.42 | 86.07 | 76.58 | NA |
| RMDL (3 RDLs) | 90.86 | 87.39 | 78.39 | 89.10 |
| RMDL (9 RDLs) | 92.60 | 90.65 | 81.92 | 90.36 |
| RMDL (15 RDLs) | 92.66 | 91.01 | 81.86 | 89.91 |
| RMDL (30 RDLs) | 93.57 | 91.59 | 82.42 | 90.69 |
| Methods | IMDB | 20NewsGroup |
|---|---|---|
| Deep Neural Networks (DNN) | 88.55 | 86.5 |
| Convolutional Neural Netwroks (CNN) | 87.44 | 82.91 |
| Recurrent Neural Networks (RNN) | 88.59 | 83.75 |
| Naive Bayesian Classifier (NBC) | 83.19 | 81.67 |
| Support Vector Machine (SVM) | 87.97 | 84.57 |
| Support Vector Machine (SVM using TF-IDF) | 88.45 | 86 |
| RMDL (3 RDLs) | 89.91 | 86.73 |
| RMDL (9 RDLs) | 90.13 | 87.62 |
| RMDL (15 RDLs) | 90.79 | 87.91 |
The Database of Faces (The Olivetti Faces Dataset)
| Methods | 5 Images | 7 Images | 9 Images |
|---|---|---|---|
| gcForest | 91.00 | 96.67 | 97.50 |
| Random Forest | 91.00 | 93.33 | 95.00 |
| Convolutional Neural Netwroks | 86.50 | 91.67 | 95.00 |
| SVM (rbf kernel) | 80.50 | 82.50 | 85.00 |
| k-nearest neighbors (kNN) | 76.00 | 83.33 | 92.50 |
| Deep Neural Networks (DNN) | 85.50 | 90.84 | 92.5 |
| RMDL (3 RDL) | 93.50 | 96.67 | 97.5 |
| RMDL (9 RDL) | 93.50 | 98.34 | 97.5 |
| RMDL (15 RDL) | 94.50 | 96.67 | 97.5 |
| RMDL (30 RDL) | 95.00 | 98.34 | 100.00 |
More Exanmple link

Send an email to kk7nc@virginia.edu
@inproceedings{Kowsari2018RMDL,
title={RMDL: Random Multimodel Deep Learning for Classification},
author={Kowsari, Kamran and Heidarysafa, Mojtaba and Brown, Donald E. and Jafari Meimandi, Kiana and Barnes, Laura E.},
booktitle={Proceedings of the 2018 International Conference on Information System and Data Mining},
year={2018},
DOI={https://doi.org/10.1145/3206098.3206111},
organization={ACM}
}