bhaveshoswal / cnn-text-classification-keras Goto Github PK
View Code? Open in Web Editor NEWText Classification by Convolutional Neural Network in Keras
Home Page: https://github.com/bhaveshoswal/CNN-text-classification-keras
Text Classification by Convolutional Neural Network in Keras
Home Page: https://github.com/bhaveshoswal/CNN-text-classification-keras
Hi,
I have used the following code to define the model, in-line with your code
def define_model(max_length, vocab_size):
inputs = Input(shape=(max_length,))
embedding1 = Embedding(vocab_size, 50)(inputs)
reshape = Reshape((max_length, 50, 1))(embedding1)
conv1 = Conv2D(num_filters, filter_sizes[0], activation='relu')(reshape)
#conv1 = Conv2D(filters=100, filter_sizes[0], activation='relu')(reshape)
conv2 = Conv2D(num_filters, filter_sizes[1], activation='relu')(reshape)
conv3 = Conv2D(num_filters, filter_sizes[2], activation='relu')(reshape)
pool1 = MaxPooling2D(pool_size=(max_length - filter_sizes[0] + 1, 1), strides=(1,1), border_mode='valid', dim_ordering='tf')(conv1)
pool2 = MaxPooling2D(pool_size=(max_length - filter_sizes[1] + 1, 1), strides=(1,1), border_mode='valid', dim_ordering='tf')(conv2)
pool3 = MaxPooling2D(pool_size=(max_length - filter_sizes[2] + 1, 1), strides=(1,1), border_mode='valid', dim_ordering='tf')(conv3)
merged = merge([pool1, pool2, pool3], mode='concat', concat_axis=1)
flatten = Flatten()(merged)
dropout = Dropout(0.5)(flatten)
dense1 = Dense(10, activation='relu')(dropout)
outputs = Dense(1, activation='sigmoid')(dense1)
model = Model(inputs=inputs, outputs=outputs)
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.summary()
return model
However, i get the following error
"concat" mode can only merge layers with matching output shapes except for the concat axis. Layer shapes: [(None, 1, 48, 100), (None, 1, 47, 100), (None, 1, 46, 100)]
The filter_size i am using is 3,4,5. Max_length is the maximum length of the document.
In the Max pooling layer, since we subtract the max_length from different filter sizes, the shape will change. Can you please guide on how to rectify it?
Very easy to use, thanks! Any idea how to cite this implementation?
for testing I set epoch to 2
after epoch 2 passed it saved model weights.001-0.6057.hdf5 and this is the output:
Epoch 00002: val_acc improved from 0.60572 to 0.66245, saving model to weights.002-0.6624.hdf5
Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7f1bf88e85f8>>
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 702, in __del__
TypeError: 'NoneType' object is not callable
marn@marn-HP-Compaq-Elite-8300-SFF ~/c/t/CNN-text-classification-keras> ls
_config.yml data_helpers.py __pycache__/ weights.001-0.6057.hdf5
data/ model.py README.md weights.002-0.6624.hdf5
is the error important? And how can I use this trained models?
thank you.
Is this classification method language independent? I want to classify some bengali sentences written in transliterated form.
Hi,
I used you helper code to prepare my dataset and then run the model. i have:
X_train=(1480,0)
y_train = (850,0)
X_test = (370,0)
y_test = (370,0)
sequence_length = 1850
the rest of parameters are the same, when i run the model, i got the error:ValueError: Error when checking input: expected input_14 to have shape (None, 1850) but got array with shape (1480, 1).
sorry, i am new, what should i do?
thanks,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.