(tf_config=None, server=None)
| 550 | |
| 551 | |
| 552 | def main(tf_config=None, server=None): |
| 553 | # check dataset and count data set size |
| 554 | print("Checking dataset...") |
| 555 | train_file = args.data_location + '/taobao_train_data' |
| 556 | test_file = args.data_location + '/taobao_test_data' |
| 557 | if args.parquet_dataset and not args.tf: |
| 558 | train_file += '.parquet' |
| 559 | test_file += '.parquet' |
| 560 | if (not os.path.exists(train_file)) or (not os.path.exists(test_file)): |
| 561 | print("Dataset does not exist in the given data_location.") |
| 562 | sys.exit() |
| 563 | no_of_training_examples = 0 |
| 564 | no_of_test_examples = 0 |
| 565 | if args.parquet_dataset and not args.tf: |
| 566 | import pyarrow.parquet as pq |
| 567 | no_of_training_examples = pq.read_table(train_file).num_rows |
| 568 | no_of_test_examples = pq.read_table(test_file).num_rows |
| 569 | else: |
| 570 | no_of_training_examples = sum(1 for line in open(train_file)) |
| 571 | no_of_test_examples = sum(1 for line in open(test_file)) |
| 572 | print("Numbers of training dataset is {}".format(no_of_training_examples)) |
| 573 | print("Numbers of test dataset is {}".format(no_of_test_examples)) |
| 574 | |
| 575 | # set batch size, eporch & steps |
| 576 | batch_size = math.ceil( |
| 577 | args.batch_size / args.micro_batch |
| 578 | ) if args.micro_batch and not args.tf else args.batch_size |
| 579 | |
| 580 | if args.steps == 0: |
| 581 | no_of_epochs = 100 |
| 582 | train_steps = math.ceil( |
| 583 | (float(no_of_epochs) * no_of_training_examples) / batch_size) |
| 584 | else: |
| 585 | no_of_epochs = math.ceil( |
| 586 | (float(batch_size) * args.steps) / no_of_training_examples) |
| 587 | train_steps = args.steps |
| 588 | test_steps = math.ceil(float(no_of_test_examples) / batch_size) |
| 589 | print("The training steps is {}".format(train_steps)) |
| 590 | print("The testing steps is {}".format(test_steps)) |
| 591 | |
| 592 | # set fixed random seed |
| 593 | tf.set_random_seed(args.seed) |
| 594 | |
| 595 | # set directory path for checkpoint_dir |
| 596 | model_dir = os.path.join(args.output_dir, |
| 597 | 'model_DSSM_' + str(int(time.time()))) |
| 598 | checkpoint_dir = args.checkpoint if args.checkpoint else model_dir |
| 599 | print("Saving model checkpoints to " + checkpoint_dir) |
| 600 | |
| 601 | # create data pipline of train & test dataset |
| 602 | train_dataset = build_model_input(train_file, batch_size, no_of_epochs) |
| 603 | test_dataset = build_model_input(test_file, batch_size, 1) |
| 604 | |
| 605 | dataset_output_types = tf.data.get_output_types(train_dataset) |
| 606 | dataset_output_shapes = tf.data.get_output_shapes(test_dataset) |
| 607 | iterator = tf.data.Iterator.from_structure(dataset_output_types, |
| 608 | dataset_output_shapes) |
| 609 | next_element = iterator.get_next() |
no test coverage detected