Changes

Jump to navigation Jump to search
4,060 bytes added ,  13:47, 21 September 2020
no edit summary
{{Project
|Has project output=Tool
|Has sponsor=McNair Center
|Has title=Deep Text Classifier
|Has owner=Yang Zhang,
|Has start date=September 2017
|Has keywords=Tool
|Has project status=Active
|Does subsume=Industry Classifier,
}}
=Deep Text Classifier=
 
E:\McNair\Projects\Deep Text Classifier
==Problem Description==
==About the Deep Models==
There are basically two big categories of deep neural networks - the convolutional neural networks ([http://cs231n.github.io/convolutional-networks/ CNN) ] and the recurrent neural networks ([https://en.wikipedia.org/wiki/Recurrent_neural_network RNN)]. The first one, CNN, is more suitable for dealing with the image based classification tasks. The second one, RNN, is in general for sequential information (i.e. language, video ...) based classification tasks.I have tired both kinds of models and , as expected, the RNN is more robust in facing different text classification tasks
==Major Package Dependences==
'''Data Preprocessing (preprocessing.py)''' : this is where you transfer a text based "XXX.txt" input file into a numerical value based pickle file that the later part of the code can understand and use for training and prediction.
* Step 1 : modify specify the target file name in "main()"
# don't add ".txt" extension
* Step 5 : give your pickle file a more reasonable name
By Attention: by default, the name of the pickle file is same as the original ".txt" file. But it's highly likely that you will use the same text inputs to predict different things. So it's important to give your pickle file a more reasonable nameeach time you run the above script. For example, from "longdescriptions.pkl" to "longdescriptions_indu.pkl" given to indicate that we are predicting the input file name is industry areas and to "longdescriptionslongdescriptions_ipo.txtpkl"to indicate that we are predicting the IPO status. If you don't do this, the later generated pickle files will overwrite the previously generated ones.
'''Model Training/Prediction (classification_MMM_LLL.py)''' : this is where the deep neural network is. The "MMM" represents the model. For example, currently I have "1DConvolution", "2DConvolution" and "LSTM". "LLL" represents the name of the label. Notice that for the same text inputs we can predict for different things using the same model literally. For example, "classification_LSTM_indu.py" is a LSTM model to predict the industray based on the descriptions. And "classification_LSTM_ipo.py" is a LSTM model to predict the IPO status based on the same descriptions. You Again you need to name your files properly! Different tasks will have different hyper-parameter configurations though the model and the inputs can be totally the same. This Python file, no matter what the model is, will always load in a pickle file you generated in the previous step and train the neural network. At the end, the well trained neural network will predict on your testing test examples (the examples you don't see during the training) and print the accuracy. To run this part:
* Step 1 : specify the name of the pickle file  with open('longdescription_ipo.pkl', 'rb') as file: * Step 2 : specify the total number of possible labels  model.add(Dense(2, activation='softmax')) * Step 3 : run the code  python classification_LSTMclassification_LSTM_ipo.py
==Data Preprocessing==
==How For data preprocessing, we adopt the same standard as in the [http://ai.stanford.edu/~amaas/data/sentiment/ IMDB] dataset.  '''To general users:''' Your input file (usually a single ".txt" file contains many examples each as a row) will be split into a training set (80% by default) and a testing set (20% by default). The labels you want to predict will be the folder names. The content (usually a block of text) of the examples will go into separate ".txt" files. To run the script, you basically need to specify the following:  1. "File Name" : without the ".txt" extension, 2. "Expected Columns" : total number of columns in the input file 3. "Content Index" : the column index of the content 4. "Label Index" : the column index of the label The script will generate a pickle file with an ".pkl" extension and the name will be the same as your input. Please change the name properly to indicate the label information as have been discussed above. And place this pickle file under the same directory with your classification code, i.e. "classification_MMM_LLL.py" '''To advanced users:'''  1. One important step in data preprocessing is to encode words (strings) into integers. The solution is to build a dictionary mapping words to their corresponding indices. For example, let's say "hello" is the 17th words in our dictionary and thus "hello" is encoded to 17. Our advanced dictionary is ordered by the words' frequency. Higher the frequency smaller the index. That is you should expect to see "the" and "a" these words with very small indices. Please also notice that 0 and 1 these two indices are not assigned to any words intentionally. The advantage here is that you can easily ignore those very common and meaningless words, like "the", by simply saying I only want to consider words with the indices > 20 for example. Notice that it's possible to encounter words that are not in our dictionary and we will alway assign them to index 1. These words are safe to ignore given that our dictionary is big enough.  2. Saving a pickle file is an very efficient way to Modify retrieve the Code data so that you don't need to do data preprocessing every time when you want to Solve run your own problemsclassifier. ==Model Training/Prediction== We write in [https://www.tensorflow.org/ Tensorflow] for all the classifiers. [https://keras.io/ Keras] is a good wrapper over the Tensorflow framework to allow you quickly build up a neural network and train it. ( if you are new to Deep Learning and Tensorflow, please do stay with Keras. ) * '''Embedding''' [https://keras.io/layers/embeddings/ Keras Official Documentation] [https://www.tensorflow.org/tutorials/word2vec Tensorflow : Vector Representations of Words] [https://en.wikipedia.org/wiki/Word2vec Wiki : Word2vec] * '''LSTM''' [http://colah.github.io/posts/2015-08-Understanding-LSTMs/ A Nice Blog about LSTM] [https://www.tensorflow.org/tutorials/recurrent Tensorflow : Recurrent Neural Networks] [https://keras.io/layers/recurrent/ Keras Official Documentation]
==General guidelines for tuning the hyper-parametersSummer 2018 Work==Code, data, and attempts to run are located in: E:

Navigation menu