Giter Site home page Giter Site logo

bhaveshoswal / cnn-text-classification-keras Goto Github PK

View Code? Open in Web Editor NEW
220.0 9.0 90.0 491 KB

Text Classification by Convolutional Neural Network in Keras

Home Page: https://github.com/bhaveshoswal/CNN-text-classification-keras

Python 100.00%
cnn text-classification tensorflow theano nlp sentiment-analysis text-mining text-prediction deep-learning keras

cnn-text-classification-keras's Introduction

CNN-text-classification-keras

It is simplified implementation of Implementing a CNN for Text Classification in TensorFlow in Keras as functional api

Requirements

Traning

Run the below command and it will run for 100 epochs if you want change it just open model.py

python model.py

For new data

You have to rebuild the vocabulary and then train.

For Citation

@misc{bhaveshoswal,
  author = {Bhavesh Vinod Oswal},
  title = {CNN-text-classification-keras},
  year = {2016},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/bhaveshoswal/CNN-text-classification-keras}},
}

cnn-text-classification-keras's People

Contributors

bhaveshoswal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cnn-text-classification-keras's Issues

How to cite it?

Very easy to use, thanks! Any idea how to cite this implementation?

Error in shape

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?

Language Independent or not

Is this classification method language independent? I want to classify some bengali sentences written in transliterated form.

Exception ignored in: <bound method BaseSession.__del__ of <tensorflow.python.client.session.Session object at 0x7f1bf88e85f8>>

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.

ValueError: Error when checking input: expected input_14 to have shape (None, 1850) but got array with shape (1480, 1)

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,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.