|
| 1 | +# Copyright 2018 The TensorFlow Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# ============================================================================== |
| 15 | +"""Central location for NCF specific values.""" |
| 16 | + |
| 17 | +import os |
| 18 | +import time |
| 19 | + |
| 20 | + |
| 21 | +# ============================================================================== |
| 22 | +# == Main Thread Data Processing =============================================== |
| 23 | +# ============================================================================== |
| 24 | +class Paths(object): |
| 25 | + """Container for various path information used while training NCF.""" |
| 26 | + |
| 27 | + def __init__(self, data_dir, cache_id=None): |
| 28 | + self.cache_id = cache_id or int(time.time()) |
| 29 | + self.data_dir = data_dir |
| 30 | + self.cache_root = os.path.join( |
| 31 | + self.data_dir, "{}_ncf_recommendation_cache".format(self.cache_id)) |
| 32 | + self.train_shard_subdir = os.path.join(self.cache_root, |
| 33 | + "raw_training_shards") |
| 34 | + self.train_shard_template = os.path.join(self.train_shard_subdir, |
| 35 | + "positive_shard_{}.pickle") |
| 36 | + self.train_epoch_dir = os.path.join(self.cache_root, "training_epochs") |
| 37 | + self.eval_data_subdir = os.path.join(self.cache_root, "eval_data") |
| 38 | + self.eval_raw_file = os.path.join(self.eval_data_subdir, "raw.pickle") |
| 39 | + self.eval_record_template_temp = os.path.join(self.eval_data_subdir, |
| 40 | + "eval_records.temp") |
| 41 | + self.eval_record_template = os.path.join( |
| 42 | + self.eval_data_subdir, "padded_eval_batch_size_{}.tfrecords") |
| 43 | + self.subproc_alive = os.path.join(self.cache_root, "subproc.alive") |
| 44 | + |
| 45 | + |
| 46 | +APPROX_PTS_PER_TRAIN_SHARD = 128000 |
| 47 | + |
| 48 | +# In both datasets, each user has at least 20 ratings. |
| 49 | +MIN_NUM_RATINGS = 20 |
| 50 | + |
| 51 | +# The number of negative examples attached with a positive example |
| 52 | +# when performing evaluation. |
| 53 | +NUM_EVAL_NEGATIVES = 999 |
| 54 | + |
| 55 | +# ============================================================================== |
| 56 | +# == Subprocess Data Generation ================================================ |
| 57 | +# ============================================================================== |
| 58 | +CYCLES_TO_BUFFER = 3 # The number of train cycles worth of data to "run ahead" |
| 59 | + # of the main training loop. |
| 60 | + |
| 61 | +READY_FILE = "ready.json" |
| 62 | +TRAIN_RECORD_TEMPLATE = "train_{}.tfrecords" |
| 63 | + |
| 64 | +TIMEOUT_SECONDS = 3600 * 2 # If the train loop goes more than two hours without |
| 65 | + # consuming an epoch of data, this is a good |
| 66 | + # indicator that the main thread is dead and the |
| 67 | + # subprocess is orphaned. |
0 commit comments