Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Added gen_data.py and modified README.md for bi-lstm-sort example #6549

Merged
merged 2 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()