项目作者: gingerbig

项目描述 :
A toy example for deep learning in C.
高级语言: C
项目地址: git://github.com/gingerbig/wordnet.git
创建时间: 2019-08-11T16:38:37Z
项目社区:https://github.com/gingerbig/wordnet

开源协议:MIT License

下载


WordNet: A Toy Example for Deep Learning

This project is based on the second programming assignment of Hinton’s Coursera
course Neural Networks for Machine
Learning
. The
original code is written in MATLAB/Octave. Since I find this example elegent for
showing how deep learning works, I rewrite the code with C from scratch and call
it WordNet (without Hinton’s permission). For such a teaching purpose, the code doesn’t have a GPU mode or a
good performance in terms of memory or CPU usage, and currently I have no plan for
optimization.

Basically, WordNet reads three consecutive words and predict the fourth word.
The layout of WordNet is defined as

Layout of
WordNet

For more technical details, please read Slides.pdf.

Building the project is quite simple since it only relies on the standard C
libs. If your building tool chain is properly configured, you may simply modify
the following lines in src/makefile with your compiler and header include path:

  1. CC = clang
  2. INCLUDES = -I/usr/local/opt/llvm/include/c++/v1 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include

and type

  1. make forward load=model9-3000.bin

to interact with a console UI doing inference with the pre-trained model
model9-3000.bin. If everything goes well, you’ll see

  1. > make forward load=model9-3000.bin
  2. ./wordnet forward model9-3000.bin
  3. # Load all data
  4. # Load model: model9-3000.bin
  5. ## Model Info
  6. Mini-batch size = 100
  7. Layer 1 Neurons = 50
  8. Layer 2 Neurons = 200
  9. Training epochs = 9
  10. Early stop @ iteration = 3000
  11. Momentum = 0.900000
  12. Learning rate = 0.100000
  13. Verify per iteration = 2147483647
  14. Raw training data rows = 372550
  15. Raw validation data rows = 46568
  16. Raw test data rows = 46568
  17. Raw data columns = 4
  18. Input dimension = 3
  19. Vocabulary size = 250
  20. ##------Interactive UI------##
  21. [... here lists the vocabulary.]
  22. |Input first 3 words > have a good
  23. have a good
  24. *Top 5 = 1.time(0.332076) 2.day(0.102091) 3.game(0.059815) 4.team(0.057552) 5.year(0.041762)
  25. |Choose a number (default = 1)>

Of course, this project also covers codes for training:

  1. Usage:
  2. ./wordnet info model.bin | Show info of pretrained model.
  3. ./wordnet train model.bin | Train from scratch and save model.
  4. ./wordnet train pretrain.bin model.bin | Read pretrained data, finetune it, & save model.
  5. ./wordnet forward pretrain.bin | Read pretrained data and do inferences.
  6. Or
  7. make info load=model.bin
  8. make train save=model.bin
  9. make train load=pretrain.bin save=model.bin
  10. make forward load=pretrain.bin

Enjoy!