From 14462e117686c9d31f38f39a6c03f7726e42f192 Mon Sep 17 00:00:00 2001 From: Linxiao ZENG <419344739@qq.com> Date: Fri, 14 Jun 2019 15:30:11 +0200 Subject: [PATCH] Fix Bug in getting random line get line in random_file rather than original file to iterate --- bert_pytorch/dataset/dataset.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bert_pytorch/dataset/dataset.py b/bert_pytorch/dataset/dataset.py index 7d787f3..cf80a52 100644 --- a/bert_pytorch/dataset/dataset.py +++ b/bert_pytorch/dataset/dataset.py @@ -115,10 +115,10 @@ def get_random_line(self): if self.on_memory: return self.lines[random.randrange(len(self.lines))][1] - line = self.file.__next__() + line = self.random_file.__next__() if line is None: - self.file.close() - self.file = open(self.corpus_path, "r", encoding=self.encoding) + self.random_file.close() + self.random_file = open(self.corpus_path, "r", encoding=self.encoding) for _ in range(random.randint(self.corpus_lines if self.corpus_lines < 1000 else 1000)): self.random_file.__next__() line = self.random_file.__next__()