• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..04-Nov-2021-

.gitignoreH A D04-Nov-202174 76

README.mdH A D04-Nov-20214.3 KiB13998

config.jlH A D04-Nov-20211.4 KiB4137

lstm.jlH A D04-Nov-20215.5 KiB176150

sampler.jlH A D04-Nov-20213.1 KiB9074

seq-data.jlH A D04-Nov-20213.9 KiB138117

train.jlH A D04-Nov-20212 KiB6051

visualize.jlH A D04-Nov-20211.1 KiB3327

README.md

1<!--- Licensed to the Apache Software Foundation (ASF) under one -->
2<!--- or more contributor license agreements.  See the NOTICE file -->
3<!--- distributed with this work for additional information -->
4<!--- regarding copyright ownership.  The ASF licenses this file -->
5<!--- to you under the Apache License, Version 2.0 (the -->
6<!--- "License"); you may not use this file except in compliance -->
7<!--- with the License.  You may obtain a copy of the License at -->
8
9<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
10
11<!--- Unless required by applicable law or agreed to in writing, -->
12<!--- software distributed under the License is distributed on an -->
13<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
14<!--- KIND, either express or implied.  See the License for the -->
15<!--- specific language governing permissions and limitations -->
16<!--- under the License. -->
17
18# LSTM char-rnn
19
20Because we explicitly unroll the LSTM/RNN over time for a fixed sequence length,
21it is easy to fit this model into the existing FeedForward model and re-use everything.
22To get a more flexible LSTM/RNN implementation that avoids explicit unrolling and
23deals with variable-length sequences, we still need to implement another model
24beside the existing FeedForward.
25
26To run this example, you will need to install two extra Julia packages: `Iterators.jl`
27and `StatsBase.jl`.
28
29## Training
30
31This example is adapted from the
32[example in Python binding](https://github.com/dmlc/mxnet-notebooks/blob/master/python/tutorials/char_lstm.ipynb) of
33MXNet. The data `input.txt` can be downloaded [here](https://github.com/dmlc/web-data/tree/master/mxnet/tinyshakespeare).
34
35Modify parameters in [config.jl](config.jl) and then run [train.jl](train.jl). An example output
36of training looks like this:
37```
38...
39INFO: Speed: 357.72 samples/sec
40INFO: == Epoch 020 ==========
41INFO: ## Training summary
42INFO:                NLL = 1.4672
43INFO:         perplexity = 4.3373
44INFO:               time = 87.2631 seconds
45INFO: ## Validation summary
46INFO:                NLL = 1.6374
47INFO:         perplexity = 5.1418
48INFO: Saved checkpoint to 'char-lstm/checkpoints/ptb-0020.params'
49INFO: Speed: 368.74 samples/sec
50INFO: Speed: 361.04 samples/sec
51INFO: Speed: 360.02 samples/sec
52INFO: Speed: 362.34 samples/sec
53INFO: Speed: 360.80 samples/sec
54INFO: Speed: 362.77 samples/sec
55INFO: Speed: 357.18 samples/sec
56INFO: Speed: 355.30 samples/sec
57INFO: Speed: 362.33 samples/sec
58INFO: Speed: 359.23 samples/sec
59INFO: Speed: 358.09 samples/sec
60INFO: Speed: 356.89 samples/sec
61INFO: Speed: 371.91 samples/sec
62INFO: Speed: 372.24 samples/sec
63INFO: Speed: 356.59 samples/sec
64INFO: Speed: 356.64 samples/sec
65INFO: Speed: 360.24 samples/sec
66INFO: Speed: 360.32 samples/sec
67INFO: Speed: 362.38 samples/sec
68INFO: == Epoch 021 ==========
69INFO: ## Training summary
70INFO:                NLL = 1.4655
71INFO:         perplexity = 4.3297
72INFO:               time = 86.9243 seconds
73INFO: ## Validation summary
74INFO:                NLL = 1.6366
75INFO:         perplexity = 5.1378
76INFO: Saved checkpoint to 'examples/char-lstm/checkpoints/ptb-0021.params'
77```
78
79## Sampling
80
81Run [sampler.jl](sampler.jl) to generate sample sentences from the trained model. Some example sentences are
82```
83## Sample 1
84all have sir,
85Away will fill'd in His time, I'll keep her, do not madam, if they here? Some more ha?
86
87## Sample 2
88am.
89
90CLAUDIO:
91Hone here, let her, the remedge, and I know not slept a likely, thou some soully free?
92
93## Sample 3
94arrel which noble thing
95The exchnachsureding worns: I ne'er drunken Biancas, fairer, than the lawfu?
96
97## Sample 4
98augh assalu, you'ld tell me corn;
99Farew. First, for me of a loved. Has thereat I knock you presents?
100
101## Sample 5
102ame the first answer.
103
104MARIZARINIO:
105Door of Angelo as her lord, shrield liken Here fellow the fool ?
106
107## Sample 6
108ad well.
109
110CLAUDIO:
111Soon him a fellows here; for her fine edge in a bogms' lord's wife.
112
113LUCENTIO:
114I?
115
116## Sample 7
117adrezilian measure.
118
119LUCENTIO:
120So, help'd you hath nes have a than dream's corn, beautio, I perchas?
121
122## Sample 8
123as eatter me;
124The girlly: and no other conciolation!
125
126BISTRUMIO:
127I have be rest girl. O, that I a h?
128
129## Sample 9
130and is intend you sort:
131What held her all 'clama's for maffice. Some servant.' what I say me the cu?
132
133## Sample 10
134an thoughts will said in our pleasue,
135Not scanin on him that you live; believaries she.
136
137ISABELLLLL?
138```
139