Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DSSM模型增加温度系数参数 #477

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci_py3_tf25.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
TEST_DEVICES: ""
PULL_REQUEST_NUM: ${{ github.event.pull_request.number }}
run: |
whoami
pwd
conda init bash
source ~/.bashrc
conda activate tf25_py3
python git-lfs/git_lfs.py pull
Expand Down
9 changes: 6 additions & 3 deletions easy_rec/python/model/dssm.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@ def build_predict_graph(self):
kernel_regularizer=self._l2_reg,
name='item_dnn/dnn_%d' % (num_item_dnn_layer - 1))

if self._loss_type == LossType.CLASSIFICATION:
if self._model_config.simi_func == Similarity.COSINE:
if self._loss_type == LossType.CLASSIFICATION and self._model_config.simi_func == Similarity.COSINE or \
self._model_config.normalization:
user_tower_emb = self.norm(user_tower_emb)
item_tower_emb = self.norm(item_tower_emb)
temperature = self._model_config.temperature
else:
temperature = 1.0

user_item_sim = self.sim(user_tower_emb, item_tower_emb)
user_item_sim = self.sim(user_tower_emb, item_tower_emb) / temperature
if self._model_config.scale_simi:
sim_w = tf.get_variable(
'sim_w',
Expand Down
3 changes: 3 additions & 0 deletions easy_rec/python/protos/dssm.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ message DSSM {
optional bool scale_simi = 5 [default = true];
optional string item_id = 9;
required bool ignore_in_batch_neg_sam = 10 [default = false];
// normalize user_tower_embedding and item_tower_embedding
optional bool normalization = 11 [default = false];
optional float temperature = 12 [default = 1.0];
}
2 changes: 1 addition & 1 deletion easy_rec/python/test/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def main(argv):
(len(all_tests), test_dir))

max_num_port_per_proc = 3
total_port_num = (max_num_port_per_proc + 2) * FLAGS.num_parallel
total_port_num = (max_num_port_per_proc + 2) * FLAGS.num_parallel * 10
all_available_ports = test_utils.get_ports_base(total_port_num).tolist()

procs = {}
Expand Down
Loading