cnn-text-classification-tf | Convolutional Neural Network for Text Classification | Machine Learning library
kandi X-RAY | cnn-text-classification-tf Summary
kandi X-RAY | cnn-text-classification-tf Summary
It is slightly simplified implementation of Kim's Convolutional Neural Networks for Sentence Classification paper in Tensorflow.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Preprocess data
- Clean a string
- Load data and labels from files
- Trains TextCNN
- Yield batches of data
- Generator for batches of data
cnn-text-classification-tf Key Features
cnn-text-classification-tf Examples and Code Snippets
cd src
python process_data.py [path/to/FastText_embedding]
python train_cascade.py
Community Discussions
Trending Discussions on cnn-text-classification-tf
QUESTION
I am trying to implement the preprocessing code for this paper (code in this repo). The preprocessing code is described in the paper here:
"A convolutional neural network (Kim, 2014) is used to extract textual features from the transcript of the utterances. We use a single convolutional layer followed by max-pooling and a fully connected layer to obtain the feature representations for the utterances. The input to this network is the 300 dimensional pretrained 840B GloVe vectors (Pennington et al., 2014). We use filters of size 3, 4 and 5 with 50 feature maps in each. The convoluted features are then max-pooled with a window size of 2 followed by the ReLU activation (Nair and Hinton, 2010). These are then concatenated and fed to a 100 dimensional fully connected layer, whose activations form the representation of the utterance. This network is trained at utterance level with the emotion labels."
The authors of the paper state that CNN feature extraction code can be found in this repo. However, this code is for a complete model that does sequence classification. It does everything in the quote above except the bolded part (and it goes further to complete do classification). I want the edit the code to build that concatenates and feeds into the 100d layer and then extracts the activations. The data to train on is found in the repo (its the IMDB dataset).
The output should be a (100, ) tensor for each sequence.
Here's the code for the CNN model:
...ANSWER
Answered 2020-May-11 at 19:35The convolutional neural network you are trying to implement is a great baseline in the NLP domain. It was introduced for the first time in this paper (Kim, 2014).
I found very useful the code you report but may be more complex than we need. I try to rewrite the network in simple keras (I only miss regularizations)
QUESTION
i came across Denny Britz implementation in tensorflow link of yoon kim's work (Convolutional Neural Networks for Sentence Classification), i would like to perform SMOTE (oversampling) on the embedding vectors of each sentence, am not sure on how to get thies embeddings, or if i can do oversampling before the embeddings,here is Denny's embedding part :
...ANSWER
Answered 2019-Apr-08 at 03:42I suppose that you want to over-sample sentence embeddings based on their classes using SMOTE. Here is the easiest way:
1- install the library imblearn pip install imblearn
2- you can choose to use SMOTE oversamplig or ADASYN oversampling,
import the one that you want :
from imblearn.over_sampling import SMOTE
or
from imblearn.over_sampling import ADASYN
3- create an instance and choose you preferred parameters (depends on your problem):
sm = SMOTE(random_state=12, ratio=1.0)
4-provide your embedding list and their adequate label list and you will get the over-sampled results:
oversampled_embeddings,oversamples_labeles= sm.fit_sample(embeding_list,labels_list)
5-enjoy training and testing you network :)
Hope that helps.
QUESTION
I am referring https://github.com/dennybritz/cnn-text-classification-tf as a reference. My goal is to build frozen graph from model files. I want to know input and output node in the signature to effectively build the frozen graph. I am printing the proto file from the graph definition using the following code.
...ANSWER
Answered 2018-Aug-21 at 14:19I recommend to use Tensorboard to visualize graph structure instead of using text file with nodes. You can find more details here.
However the graph itself doesn't have notion of inputs or outputs. You can treat nodes without input connections as good candidates for being input nodes, especially placeholder nodes. Nodes that are connected to loss function are good candidates for being output nodes.
To sum up: In general you need to guess which nodes are the input and which are the output by analyzing network architecture.
As for the repository you referenced, you can read eval.py
code and find these lines:
QUESTION
I am referring (here) to freeze models into .pb file. My model is CNN for text classification I am using (Github) link to train CNN for text classification and exporting in form of models. I have trained models to 4 epoch and My checkpoints folders look as follows:
I want to freeze this model into (.pb file). For that I am using following script:
...ANSWER
Answered 2018-Jul-27 at 01:55Tensorflow: What are the "output_node_names" for freeze_graph.py in the model_with_buckets model?
Here are some answers about node names and how to identify them.
Good luck.
QUESTION
I have trained a model using the Wild ML implementation of a CNN which can be found here, and deployed it to Google Cloud Platform. I am now trying to send a JSON prediction request to the model, but I am getting the following error:
...ANSWER
Answered 2018-Feb-24 at 05:06The issue does have nothing to do with the train.py
and text_cnn.py
. They build your model. After building your model, do the following modifications in your eval.py
code.
First, you can use argument library to get your JSON file.
QUESTION
I use python and tensorflow CNN for text classification. lrp_toolbox is a explain model of the neural network, it will provide the reason of classification of neural network model like "CNN", "RNN". The input of lrp_toolbox is trained "CNN" model with the following format.
I don't know how to make this format from the sess or graph of tensorflow CNN. I try to pickle the sess use code:
filename = 'trainedCNN_model_%s.pickle' % str(current_step)
pickle.dump(sess, open(filename, 'wb'))
,
but it fails and shows TypeError: can't pickle module objects
.
And actually, I think sess can't meet the input format of lrp_toolbox. The example input of lrp_toolbox is text format like
Linear 2 3
-2.01595799878 -2.05379403106 0.688953420218 1.20338836267 -1.7518249173 -1.90515935663
-0.519917325831 0.400368842573 0.0699950389094
Tanh
Linear 3 3
-1.18542075899 -1.62921811225 0.134698917906 0.111469267787 1.85227669488 -0.350827317469 0.102194311719 -1.67678396935 0.256312518679
0.116095097279 -0.0138454065897 0.0469443958438
Tanh
Linear 3 2
1.10940574175 0.26799513777 2.51842248017 -1.5497671807 -0.606042655911 0.197763706892
-0.115832556216 0.115832556216
SoftMax
Here is the manual of lrp_toolbox.
ANSWER
Answered 2018-Feb-01 at 11:40You need to implement some method, when you need to serialize object by pickle.
TypeError: can't pickle module objects. As this error message explain, sess is not be implemented method for serialize sess object. And also, I can not see what value the sess has. Could you explain how you made the sess?
QUESTION
I am new to tensorflow and neural network. I started a project which is about detecting errors in persian texts. I used the code in this address and developed the code in here. please check the code because I can not put all the code here.
What I want to do is to give several persian sentences to the model for training and then see if model can detect wrong sentences. The model works fine with english data but when I use it for persian data I encounter this issue.
The code is too long to be written here so I try to point to the part I think might be causing the issue. I used these lines in train.py
which works fine and stores vocabularies:
ANSWER
Answered 2017-Dec-05 at 22:53Have you tried adding this at the top of your file?
QUESTION
I am following this tutorial in order to understand CNNs in NLP. There are a few things which I don't understand despite having the code in front of me. I hope somebody can clear a few things up here.
The first rather minor thing is the sequence_length
parameter of the TextCNN
object. In the example on github this is just 56
which I think is the max-length of all sentences in the training data. This means that self.input_x
is a 56-dimensional vector which will contain just the indices from the dictionary of a sentence for each word.
This list goes into tf.nn.embedding_lookup(W, self.intput_x)
which will return a matrix consisting of the word embeddings of those words given by self.input_x
. According to this answer this operation is similar to using indexing with numpy:
ANSWER
Answered 2017-Feb-01 at 19:19Answer to ques 1 (So am I correct if I assume that tf.nn.embedding_lookup ignores the value 0?) :
The 0's in the input vector is the index to 0th symbol in the vocabulary, which is the PAD symbol. I don't think it gets ignored when the lookup is performed. 0th row of the embedding matrix will be returned.
Answer to ques 2 (But how can tf.nn.embedding_lookup know about those indices given by self.input_x?) :
Size of the embedding matrix is [V * E] where is the size of vocabulary and E is dimension of embedding vector. 0th row of matrix is embedding vector for 0th element of vocabulary, 1st row of matrix is embedding vector for 1st element of vocabulary. From the input vector x, we get the indices of words in vocabulary, which are used for indexing the embedding matrix.
Answer to ques 3 (Does this mean that we are actually learning the word embeddings here?).
Yes, we are actually learning the embedding matrix.
In the embedding layer, in line W = tf.Variable( tf.random_uniform([vocab_size, embedding_size], -1.0, 1.0),name="W")
W is the embedding matrix and by default, in tensorflow trainable=TRUE
for variable. So, W will also be a learned parameter. To use pre- trained model, set trainable = False
.
For detailed explanation of the code you can follow blog: https://agarnitin86.github.io/blog/2016/12/23/text-classification-cnn
QUESTION
I've tried to compare the tutorial code for text classification from tflearn : https://github.com/tflearn/tflearn/blob/master/examples/nlp/cnn_sentence_classification.py
And the one from dennybritz : https://github.com/dennybritz/cnn-text-classification-tf
These 2 codes shows different result, i understand that it can be because the tflearn tutorial use 1d convolution, but there is one line of code that i don't understand:
network = global_max_pool(network)
What is the difference between global_max_pool and max_pool_2d?
...ANSWER
Answered 2017-Mar-31 at 16:24Looking at the code, they make different calls to the tensor flow library:
2d_max_poolDoes broadly what you would expect and returns (as well as doing some other things):
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install cnn-text-classification-tf
You can use cnn-text-classification-tf like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page