Skip to content

Commit

Permalink
Merge pull request #44 from oujago/develop
Browse files Browse the repository at this point in the history
version 0.4.0
  • Loading branch information
oujago authored Jun 18, 2017
2 parents a24734e + 1a6e258 commit b7cfaf6
Show file tree
Hide file tree
Showing 23 changed files with 571 additions and 245 deletions.
16 changes: 16 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ Changelog
---------


0.4.0 (2017.-06-18)
~~~~~~~~~~~~~~~~~~~

Version 0.4.0.

* Embedding backward
* Momentum
* NesterovMomentum
* Adagrad
* RMSprop
* Adadelta
* Adam
* Adamax



0.3.0 (2017-06-15)
~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ include requirements-dev.txt
recursive-include tests *.py

# examples
recursive-include examples *.py
recursive-include examples *.py *.txt *.label

# documents
recursive-include docs *.rst conf.py *.css Makefile
recursive-include docs *.rst *.py fix_rtd.css Makefile make.bat

# applications
recursive-include application *.py *.md *.html *.jpg
Expand Down
86 changes: 67 additions & 19 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@

.. https://codeclimate.com/github/oujago/NumpyDL/badges/gpa.svg
:target: https://codeclimate.com/github/oujago/NumpyDL
:alt: Code Climate
.. image:: https://codeclimate.com/github/oujago/NumpyDL/badges/issue_count.svg
:target: https://codeclimate.com/github/oujago/NumpyDL
:alt: Issue Count

.. image:: https://img.shields.io/github/issues/oujago/NumpyDL.svg
:target: https://github.com/oujago/NumpyDL

.. image:: https://img.shields.io/github/forks/oujago/NumpyDL.svg
:target: https://github.com/oujago/NumpyDL

.. image:: https://img.shields.io/github/stars/oujago/NumpyDL.svg
:target: https://github.com/oujago/NumpyDL

.. image:: https://zenodo.org/badge/83100910.svg
:target: https://zenodo.org/badge/latestdoi/83100910

Expand Down Expand Up @@ -67,6 +59,7 @@ Its main features are:
5. *API* like ``Keras`` library
6. *Examples* for several AI tasks
7. *Application* for a toy chatbot
8. *Mobile friendly* documents


Documentation
Expand Down Expand Up @@ -105,19 +98,17 @@ Examples
``NumpyDL`` provides several examples of AI tasks:

* sentence classification
* LSTM in `examples/lstm_sentence_classification.py`
* CNN in `examples/cnn_sentence_classification.py`
* LSTM in *examples/lstm_sentence_classification.py*
* CNN in *examples/cnn_sentence_classification.py*
* mnist handwritten recognition
* MLP in `examples/mlp-mnist.py`
* MLP in `examples/mlp-digits.py`
* CNN in `examples/cnn-minist.py`
* MLP in *examples/mlp-mnist.py*
* MLP in *examples/mlp-digits.py*
* CNN in *examples/cnn-minist.py*
* language modeling
* RNN in `examples/rnn-character-lm.py`
* RNN in `examples/rnn-character-lm2.py`
* LSTM in `examples/lstm-character-lm.py`
* LSTM in `examples/lstm-character-lm2.py`
* RNN in *examples/rnn-character-lm.py*
* LSTM in *examples/lstm-character-lm.py*

One concrete code example in `examples/mlp-digits.py`:
One concrete code example in *examples/mlp-digits.py*:

.. code-block:: python
Expand Down Expand Up @@ -152,11 +143,68 @@ Applications
``NumpyDL`` provides one toy application:

* Chatbot
* seq2seq in `applications/chatbot/model.py`
* seq2seq in *applications/chatbot/model.py*


And its final result:

.. figure:: applications/chatbot/pics/chatbot.png
:width: 80%


Supports
========

``NumpyDL`` supports following deep learning techniques:

* Layers
* Linear
* Dense
* Softmax
* Dropout
* Convolution
* Embedding
* BatchNormal
* MeanPooling
* MaxPooling
* SimpleRNN
* GRU
* LSTM
* Flatten
* DimShuffle
* Optimizers
* SGD
* Momentum
* NesterovMomentum
* Adagrad
* RMSprop
* Adadelta
* Adam
* Adamax
* Objectives
* MeanSquaredError
* HellingerDistance
* BinaryCrossEntropy
* SoftmaxCategoricalCrossEntropy
* Initializations
* Zero
* One
* Uniform
* Normal
* LecunUniform
* GlorotUniform
* GlorotNormal
* HeNormal
* HeUniform
* Orthogonal
* Activations
* Sigmoid
* Tanh
* ReLU
* Linear
* Softmax
* Elliot
* SymmetricElliot
* SoftPlus
* SoftSign

1 change: 0 additions & 1 deletion applications/chatbot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def ask():
if message == "quit":
exit()
else:
# print bot_response
return jsonify({'status': 'OK',
'answer': model.utter(message)})

Expand Down
29 changes: 26 additions & 3 deletions examples/lstm-character-lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import npdl


def main(max_iter, corpus_path=os.path.join(os.path.dirname(__file__), 'data/lm/tiny_shakespeare.txt')):
def get_data():
corpus_path = os.path.join(os.path.dirname(__file__), 'data/lm/tiny_shakespeare.txt')

raw_text = open(corpus_path, 'r').read()
chars = list(set(raw_text))
data_size, vocab_size = len(raw_text), len(chars)
Expand All @@ -16,7 +18,6 @@ def main(max_iter, corpus_path=os.path.join(os.path.dirname(__file__), 'data/lm/
index_to_char = {i: ch for i, ch in enumerate(chars)}

time_steps, batch_size = 30, 40

length = batch_size * 20
text_pointers = np.random.randint(data_size - time_steps - 1, size=length)
batch_in = np.zeros([length, time_steps, vocab_size])
Expand All @@ -26,6 +27,12 @@ def main(max_iter, corpus_path=os.path.join(os.path.dirname(__file__), 'data/lm/
batch_in[i, range(time_steps), b_[:-1]] = 1
batch_out[i, b_[-1]] = 1

return batch_size, vocab_size, time_steps, batch_in, batch_out


def main1(max_iter):
batch_size, vocab_size, time_steps, batch_in, batch_out = get_data()

print("Building model ...")
net = npdl.Model()
net.add(npdl.layers.BatchLSTM(n_out=300, n_in=vocab_size, return_sequence=True,
Expand All @@ -39,5 +46,21 @@ def main(max_iter, corpus_path=os.path.join(os.path.dirname(__file__), 'data/lm/
net.fit(batch_in, batch_out, max_iter=max_iter, batch_size=batch_size)


def main2(max_iter):
batch_size, vocab_size, time_steps, batch_in, batch_out = get_data()

print("Building model ...")
net = npdl.Model()
net.add(npdl.layers.BatchLSTM(n_out=300, n_in=vocab_size, return_sequence=False,
nb_batch=batch_size, nb_seq=time_steps))
# net.add(npdl.layers.MeanPooling(pool_size=(time_steps, 1)))
# net.add(npdl.layers.Flatten())
net.add(npdl.layers.Softmax(n_out=vocab_size))
net.compile(loss=npdl.objectives.SCCE(), optimizer=npdl.optimizers.SGD(lr=0.00001, clip=5))

print("Train model ...")
net.fit(batch_in, batch_out, max_iter=max_iter, batch_size=batch_size)


if __name__ == '__main__':
main(100)
main1(100)
43 changes: 0 additions & 43 deletions examples/lstm-character-lm2.py

This file was deleted.

21 changes: 20 additions & 1 deletion examples/lstm_sentence_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,24 @@ def main(max_iter):
net.fit(xs, ys, batch_size=nb_batch, validation_split=0.1, max_iter=max_iter)


def main2(max_iter):
nb_batch = 30
nb_seq = 20

xs, ys, x_size, y_size = prepare_data(nb_seq)

net = npdl.Model()
net.add(npdl.layers.Embedding(nb_batch=nb_batch, nb_seq=nb_seq,
n_out=200, input_size=x_size,
static=False))
net.add(npdl.layers.BatchLSTM(n_out=400, return_sequence=True))
net.add(npdl.layers.BatchLSTM(n_out=200, return_sequence=True))
net.add(npdl.layers.MeanPooling((nb_seq, 1)))
net.add(npdl.layers.Flatten())
net.add(npdl.layers.Softmax(n_out=y_size))
net.compile(loss='scce', optimizer=npdl.optimizers.RMSprop())
net.fit(xs, ys, batch_size=nb_batch, validation_split=0.1, max_iter=max_iter)


if __name__ == '__main__':
main(100)
main2(100)
Loading

0 comments on commit b7cfaf6

Please sign in to comment.