我希望有人能看到我在这里失败的地方。因此,我从buzzfeed中抓取了一些数据,现在我正在尝试格式化一个文本文件,然后用它将其发送到data_convert_examples text_to_data格式化程序中。
我想我有几次答案,但当我把它作为二进制处理,然后尝试对数据进行训练时,我仍然会碰到砖墙。
我所做的是在玩具数据集上运行binary_to_text,然后在notepad++窗口下打开文件,显示所有字符,并匹配我认为的格式。
我赞同下面的长期功能,但我真的不确定问题可能在哪里,并认为这是提供足够信息的最佳方式。有人有什么想法或建议吗?
def processPath(self, toPath):
try:
fout = open(os.path.join(toPath, '{}-{}'.format(self.baseName, self.fileNdx)), 'a+')
for path, dirs, files in os.walk(self.fromPath):
for fn in files:
fullpath = os.path.join(path, fn)
if os.path.isfile(fullpath):
#with open(fullpath, "rb") as f:
with codecs.open(fullpath, "rb", 'ascii', "ignore") as f:
try:
finalRes = ""
content = f.readlines()
self.populateVocab(content)
sentences = sent_tokenize((content[1]).encode('ascii', "ignore").strip('\n'))
for sent in sentences:
textSumFmt = self.textsumFmt
finalRes = textSumFmt["artPref"] + textSumFmt["sentPref"] + sent.replace("=", "equals") + textSumFmt["sentPost"] + textSumFmt["postVal"]
finalRes += (('\t' + textSumFmt["absPref"] + textSumFmt["sentPref"] + (content[0]).strip('\n').replace("=", "equals") + textSumFmt["sentPost"] + textSumFmt["postVal"]) + '\t' +'publisher=BUZZ' + os.linesep)
if self.lineNdx != 0 and self.lineNdx % self.lines == 0:
fout.close()
self.fileNdx+=1
fout = open(os.path.join(toPath, '{}-{}'.format(self.baseName, self.fileNdx)), 'a+')
fout.write( ("{}").format( finalRes.encode('utf-8', "ignore") ) )
self.lineNdx+=1
except RuntimeError as e:
print "Runtime Error: {0} : {1}".format(e.errno, e.strerror)
finally:
fout.close()发布于 2016-10-07 04:01:36
经过进一步的分析,问题的来源似乎更多的是来源数据和它的构造方式,而不是data_convert_example.py本身。我要结束这篇文章,因为标题与问题的来源不一致。
我发现问题的根源是我在“文章”和“等号”之间有一个空格。移除后,我成功地训练了。
https://stackoverflow.com/questions/39886898
复制相似问题