Skip to content

Commit ff81747

Browse files
committed
finished documention on various neural networks; added references
1 parent 75256c2 commit ff81747

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

docs/images/nnlib_clstm.png

86.2 KB
Loading

docs/images/nnlib_cnn.png

55.5 KB
Loading

docs/refs.rst

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ WWW '08 Proceedings of the 17th international conference on World Wide Web. (200
3939
<http://dl.acm.org/citation.cfm?id=1367510>`_]
4040

4141
Yoon Kim, "Convolutional Neural Networks for Sentence Classification," *EMNLP* 2014, 1746-1751 (arXiv:1408.5882). [`arXiv
42-
<https://arxiv.org/abs/1408.5882>`_]
42+
<https://arxiv.org/abs/1408.5882>`_]
43+
44+
Zackary C. Lipton, John Berkowitz, "A Critical Review of Recurrent Neural Networks for Sequence Learning," arXiv:1506.00019 (2015). [`arXiv
45+
<https://arxiv.org/abs/1506.00019>`_]
46+

docs/tutorial_nnlib.rst

+71-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Then load the training data
3737
Then we choose a neural network. We choose ConvNet:
3838

3939
>>> import shorttext.classifiers.embed.nnlib.frameworks as fr
40-
>>> kmodel = fr.CNNWordEmbed(len(classdict.keys()))
40+
>>> kmodel = fr.CNNWordEmbed(len(trainclassdict.keys()))
4141

4242
Initialize the classifier:
4343

@@ -69,18 +69,88 @@ Epoch 10/10
6969
45/45 [==============================] - 0s - loss: 0.0743
7070

7171
Then the model is ready for classification, like:
72+
7273
>>> classifier.score('artificial intelligence')
7374
{'mathematics': 0.57749695, 'physics': 0.33749574, 'theology': 0.085007325}
7475

7576
Provided Neural Networks
7677
------------------------
7778

79+
There are three neural networks available in this package for the use in
80+
:class:`shorttext.classifiers.embed.nnlib.VarNNEmbeddedVecClassification.VarNNEmbeddedVecClassifier`,
81+
and they are available in the module :module:`shorttext.classifiers.embed.nnlib.frameworks`.
82+
83+
ConvNet (Convolutional Neural Network)
84+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85+
86+
This neural network for supervised learning is using convolutional neural network (ConvNet),
87+
as demonstrated in Kim's paper.
88+
89+
.. image:: images/nnlib_cnn.png
90+
91+
The function in the frameworks returns a :class:`keras.models.Sequential`.
92+
93+
.. autofunction:: shortext.embed.nnlib.frameworks.CNNWordEmbed
94+
95+
The parameter `maxlen` defines the maximum length of the sentences. If the sentence has less than `maxlen`
96+
words, then the empty words will be filled with zero vectors.
97+
98+
>>> kmodel = fr.CNNWordEmbed(len(trainclassdict.keys()))
99+
100+
Double ConvNet
101+
^^^^^^^^^^^^^^
102+
103+
This neural network is nothing more than two ConvNet layers.
104+
105+
.. autofunction:: shortext.embed.nnlib.frameworks.DoubleCNNWordEmbed
106+
107+
The parameter `maxlen` defines the maximum length of the sentences. If the sentence has less than `maxlen`
108+
words, then the empty words will be filled with zero vectors.
109+
110+
>>> kmodel = fr.DoubleCNNWordEmbed(len(trainclassdict.keys()))
111+
112+
C-LSTM (Convolutional Long Short-Term Memory)
113+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
114+
115+
This neural network for supervised learning is using C-LSTM, according to the paper
116+
written by Zhou *et. al.* It is a neural network with ConvNet as the first layer,
117+
and then followed by LSTM (long short-term memory), a type of recurrent neural network (RNN).
118+
119+
.. image:: images/nnlib_clstm.png
120+
121+
The function in the frameworks returns a :class:`keras.models.Sequential`.
122+
123+
.. autofunction:: shorttext.embed.nnlib.frameworks.CLSTMWordEmbed
124+
125+
The parameter `maxlen` defines the maximum length of the sentences. If the sentence has less than `maxlen`
126+
words, then the empty words will be filled with zero vectors.
127+
128+
>>> kmodel = fr.CLSTMWordEmbed(len(trainclassdict.keys()))
129+
130+
User-Defined Neural Network
131+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
132+
133+
Users can define their own neural network for use in the classifier wrapped by
134+
:class:`shorttext.classifiers.embed.nnlib.VarNNEmbeddedVecClassification.VarNNEmbeddedVecClassifier`
135+
as long as the following criteria are met:
136+
137+
- the input matrix is :class:`numpy.ndarray`, and of shape `(maxlen, vecsize)`, where
138+
`maxlen` is the maximum length of the sentence, and `vecsize` is the number of dimensions
139+
of the embedded vectors. The output is a one-dimensional array, of size equal to
140+
the number of classes provided by the training data. The order of the class labels is assumed
141+
to be the same as the order of the given training data (stored as a Python dictionary).
78142

79143
Reference
80144
---------
81145

82146
Chunting Zhou, Chonglin Sun, Zhiyuan Liu, Francis Lau, "A C-LSTM Neural Network for Text Classification," (arXiv:1511.08630). [`arXiv
83147
<https://arxiv.org/abs/1511.08630>`_]
84148

149+
"CS231n Convolutional Neural Networks for Visual Recognition," Stanford Online Course. [`link
150+
<http://cs231n.github.io/convolutional-networks/>`_]
151+
85152
Yoon Kim, "Convolutional Neural Networks for Sentence Classification," *EMNLP* 2014, 1746-1751 (arXiv:1408.5882). [`arXiv
86153
<https://arxiv.org/abs/1408.5882>`_]
154+
155+
Zackary C. Lipton, John Berkowitz, "A Critical Review of Recurrent Neural Networks for Sequence Learning," arXiv:1506.00019 (2015). [`arXiv
156+
<https://arxiv.org/abs/1506.00019>`_]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import SumWord2VecClassification

0 commit comments

Comments
 (0)