!17575 fix textcnn possible file write incomplete

From: @zhouneng2
Reviewed-by: @c_34,@oacjiewen
Signed-off-by: @c_34
This commit is contained in:
mindspore-ci-bot 2021-06-03 09:14:27 +08:00 committed by Gitee
commit 5bf8595a0a
1 changed files with 14 additions and 14 deletions

View File

@ -53,7 +53,7 @@ class DataProcessor:
""" collect weight """
vocab_size = self.get_dict_len()
embedding_index = {}
f = open(glove_path)
with open(glove_path) as f:
for line in f:
values = line.split()
word = values[0]
@ -129,9 +129,9 @@ class MovieReview(DataProcessor):
self.Pos = []
self.Neg = []
for filename in self.files:
f = codecs.open(filename, 'r')
with codecs.open(filename, 'r') as f:
ff = f.read()
file_object = codecs.open(filename, 'w', 'utf-8')
with codecs.open(filename, 'w', 'utf-8') as file_object:
file_object.write(ff)
self.read_data(filename)
self.PosNeg = self.Pos + self.Neg
@ -394,9 +394,9 @@ class SST2(DataProcessor):
self.maxlen = float("-inf")
for filename in self.files:
if 'train' in filename or 'dev' in filename:
f = codecs.open(filename, 'r')
with codecs.open(filename, 'r') as f:
ff = f.read()
file_object = codecs.open(filename, 'w', 'utf-8')
with codecs.open(filename, 'w', 'utf-8') as file_object:
file_object.write(ff)
self.read_data(filename)
self.text2vec(maxlen=maxlen)