Speed data reader for IMDB dataset.#7002
Merged
qingqing01 merged 4 commits intoPaddlePaddle:developfrom Dec 26, 2017
Merged
Conversation
chengduoZH
reviewed
Dec 25, 2017
python/paddle/v2/dataset/imdb.py
Outdated
| @@ -76,45 +75,19 @@ def build_dict(pattern, cutoff): | |||
|
|
|||
| def reader_creator(pos_pattern, neg_pattern, word_idx, buffer_size): | |||
Contributor
There was a problem hiding this comment.
buffer_size becomes useless.
Contributor
There was a problem hiding this comment.
buffer_size is never used. Even in the previous experiment, people only set the shuffle buffer.
Contributor
Author
There was a problem hiding this comment.
Done. Remove the buffer size. And I test the time for whether to use two threads.
- Not use two threads: 16.65757s
- Use two threads: 25 - 27s. I'm not sure why this is slower, the code is as follows:
def reader_creator(pos_pattern, neg_pattern, word_idx, buffer_size):
start_time = time.time()
UNK = word_idx['<unk>']
POS = []
NEG = []
def load(pattern, out, label):
for doc in tokenize(pattern):
out.append(([word_idx.get(w, UNK) for w in doc], label))
# Creates two threads that loads positive and negative samples
# into qs.
t0 = threading.Thread(
target=load, args=(
pos_pattern,
POS, 0, ))
t0.daemon = True
t0.start()
t1 = threading.Thread(
target=load, args=(
neg_pattern,
NEG, 1, ))
t1.daemon = True
t1.start()
t0.join()
t1.join()
INS = POS + NEG
random.shuffle(INS)
duration = time.time() - start_time
print('\nTotal time: %.5f ' % (duration))
def reader():
for doc, label in INS:
yield doc, label
return reader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #7001
Test Env:
Total Time: