Skip to content

Commit

Permalink
Added gen_data.py and modified README.md for bi-lstm-sort example (ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
gurumurthys authored and mbaijal committed Sep 6, 2017
1 parent 83132f9 commit dd64f4c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion example/bi-lstm-sort/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ This is an example of using bidirection lstm to sort an array.

Firstly, generate data by:

cd data
python gen_data.py

Move generated txt files to data directory

mkdir data
mv *.txt data

Then, train the model by:

python lstm_sort.py
Expand Down
20 changes: 20 additions & 0 deletions example/bi-lstm-sort/gen_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import random

vocab = [str(x) for x in range(100, 1000)]
sw_train = open("sort.train.txt", "w")
sw_test = open("sort.test.txt", "w")
sw_valid = open("sort.valid.txt", "w")

for i in range(1000000):
seq = " ".join([vocab[random.randint(0, len(vocab) - 1)] for j in range(5)])
k = i % 50
if k == 0:
sw_test.write(seq + "\n")
elif k == 1:
sw_valid.write(seq + "\n")
else:
sw_train.write(seq + "\n")

sw_train.close()
sw_test.close()
sw_valid.close()

0 comments on commit dd64f4c

Please sign in to comment.