TextSumモデル用に独自のトレーニングデータを作成しようとしています。私の理解として、私は自分の記事と抄録をバイナリファイル(TFRecords内)に入れる必要があります。しかし、生のテキストファイルから私自身の訓練データを作成することはできません。私は非常に明確にフォーマットを理解していないので、私は次のコードを使用して、非常に単純なバイナリファイルを作成しようとしています:Tensorflow - TextSumモデル:独自のトレーニングデータを作成する方法
files = os.listdir(path)
writer = tf.python_io.TFRecordWriter("test_data")
for i, file in enumerate(files):
content = open(os.path.join(path, file), "r").read()
example = tf.train.Example(
features = tf.train.Features(
feature = {
'content': tf.train.Feature(bytes_list=tf.train.BytesList(value=[content]))
}
)
)
serialized = example.SerializeToString()
writer.write(serialized)
をそして私は、このTEST_DATAファイル
の値を読み出すために、次のコードを使用してみてください私が間違って何であるか見当がつかないFile "dailymail_corpus_to_tfrecords.py", line 34, in check_file
example_pb2.Example.FromString(example_str)
File "/home/s1510032/anaconda2/lib/python2.7/site-packages/google/protobuf/internal/python_message.py", line 770, in FromString
message.MergeFromString(s)
File "/home/s1510032/anaconda2/lib/python2.7/site-packages/google/protobuf/internal/python_message.py", line 1091, in MergeFromString
if self._InternalParse(serialized, 0, length) != length:
File "/home/s1510032/anaconda2/lib/python2.7/site-packages/google/protobuf/internal/python_message.py", line 1117, in InternalParse
new_pos = local_SkipField(buffer, new_pos, end, tag_bytes)
File "/home/s1510032/anaconda2/lib/python2.7/site-packages/google/protobuf/internal/decoder.py", line 850, in SkipField
return WIRETYPE_TO_SKIPPER[wire_type](buffer, pos, end)
File "/home/s1510032/anaconda2/lib/python2.7/site-packages/google/protobuf/internal/decoder.py", line 791, in _SkipLengthDelimited
raise _DecodeError('Truncated message.')
google.protobuf.message.DecodeError: Truncated message.
:
reader = open("test_data", 'rb')
len_bytes = reader.read(8)
str_len = struct.unpack('q', len_bytes)[0]
example_str = struct.unpack('%ds' % str_len, reader.read(str_len))[0]
example_pb2.Example.FromString(example_str)
は、しかし、私は常に、次のエラーを取得します。この問題を解決するためのご提案があれば教えてください。
あなたがこれをどのようなオペレーティングシステムを手に入れましたOSX 11では問題が発生しています私がここに来る前に。私は監督者がスレッドが止まるのを待つように 'Train'メソッドを修正しなければなりませんでした。 – Jordan
OSXを使用しています。私もUnix上で実行しようとしたが、うまく動作していた。しかし私の解決策には小さな間違いがあります。 'read(read)(4)'を使って 'seek(12)'を使う代わりに 'data.py'の4バイトをスキップするべきです。私は私のポストを更新するつもりです –