forked from mindspore-Ecosystem/mindspore
fix textcnn possible file write incomplete
This commit is contained in:
parent
14cf33a6df
commit
0c58fa9d1c
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue