【问题标题】:How to format input data for textsum data_convert_example如何格式化 textsum data_convert_example 的输入数据
【发布时间】:2016-10-08 11:58:03
【问题描述】:

我希望有人能够看到我在这里失败的地方。所以我已经从 Buzzfeed 中抓取了一些数据,现在我正在尝试格式化一个文本文件,然后我可以将其发送到 data_convert_examples text_to_data 格式化程序中。

我以为我有几次答案了,但是当我将它作为二进制处理然后尝试针对数据进行训练时,我仍然遇到了难题。

我所做的是在玩具数据集上运行 binary_to_text,然后在 windows 下的 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()

【问题讨论】:

    标签: tensorflow textsum


    【解决方案1】:

    经过进一步分析,问题的根源似乎更多的是源数据及其构造方式,而不是data_convert_example.py本身。我要关闭它,因为标题与问题的来源不一致。

    我发现问题的根源在于“文章”和等号之间有一个空格。删除后,我能够成功训练。

    【讨论】:

      猜你喜欢
      • 2021-11-25
      • 1970-01-01
      • 2018-08-11
      • 2020-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      相关资源
      最近更新 更多