importsysimportosimportpaddledefparse_fields(fields):words_width=int(fields[0])words=fields[1:1+words_width]label=fields[-1]returnwords,labeldefimdb_data_feed_reader(data_dir,batch_size,buf_size):""" Data feed reader for IMDB dataset. This data set has been converted from original format to a format suitable for AsyncExecutor See data.proto for data format """defreader():forfileinos.listdir(data_dir):iffile.endswith('.proto'):continuewithopen(os.path.join(data_dir,file),'r')asf:forlineinf:fields=line.split(' ')words,label=parse_fields(fields)yieldwords,labeltest_reader=paddle.batch(paddle.reader.shuffle(reader,buf_size=buf_size),batch_size=batch_size)returntest_reader