text_plain_output_1.png
from keras.layers import Dense, Input, CuDNNLSTM, Embedding, Dropout, Activation, CuDNNGRU, Conv1D

from keras.layers import LSTM

from keras.models import Sequential

from keras.preprocessing.sequence import pad_sequences

from keras.preprocessing.text import Tokenizer

from keras.utils import to_categorical

import pandas as pd

data = pd.read_csv('../input/mondaq_data_adeel.csv', header=None)

columns = ['article_id', 'knt', 'unknt', 'her_knt', 'unher_knt', 'company_id', 'company_name', 'country_id', 'country_desc', 'primary_topic_id', 'topic_desc', 'article_start_date', 'daysold', 'topics', 'coauthors', 'linkedinphoto', 'title', 'body']

data.columns = columns

(train_df.shape, val_df.shape)

embed_size = 100
max_features = 100000
maxlen = 1400

train_X = train_df['entire_text'].fillna('##').values
val_X = val_df['entire_text'].fillna('##').values

tokenizer = Tokenizer(num_words=max_features)
tokenizer.fit_on_texts(list(data['entire_text'].fillna('##').values))
train_X = tokenizer.texts_to_sequences(train_X)
val_X = tokenizer.texts_to_sequences(val_X)

train_X = pad_sequences(train_X, maxlen=maxlen)
val_X = pad_sequences(val_X, maxlen=maxlen)

train_y = train_df['Reg_clicks_categorical'].values
val_y = val_df['Reg_clicks_categorical'].values

train_y = to_categorical(train_y, num_classes=4)
val_y = to_categorical(val_y, num_classes=4)

model = Sequential()
model.add(Embedding(max_features, embed_size, input_length=maxlen))
model.add(LSTM(256))
model.add(Dense(4, activation='softmax'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

model.fit(train_X, train_y, epochs=2, batch_size=256, validation_data=(val_X, val_y))