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

Bug fix of NaN output of tf.norm occasionally #423

Merged
merged 15 commits into from
Sep 27, 2023
Merged
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
Binary file added docs/images/models/cl4srec.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/models/deepfm_variant.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 11 additions & 9 deletions docs/source/models/deepfm.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,22 @@ model_config:{
```

- model_class: 'DeepFM', 不需要修改

- feature_groups:

需要两个feature_group: wide group和deep group, **group name不能变**

- deepfm: deepfm相关的参数

- dnn: deep part的参数配置

- hidden_units: dnn每一层的channel数目,即神经元的数目

- wide_output_dim: wide部分输出的大小

- final_dnn: 整合wide part, fm part, deep part的参数输入, 可以选择是否使用

- hidden_units: dnn每一层的channel数目,即神经元的数目

- embedding_regularization: 对embedding部分加regularization,防止overfit

**FM Varint**

标准的FM,只会输出一个所有二阶交叉求和的logit(scalar);如果配置了final_dnn,则默认使用了FM模块的一个变种,FM模块输出一个多维的中间结果。

![deepfm_variant](../../images/models/deepfm_variant.jpg)

#### 2. 组件化模型

```protobuf
Expand Down Expand Up @@ -122,6 +119,9 @@ model_config: {
}
keras_layer {
class_name: 'FM'
fm {
use_variant: false
}
}
}
blocks {
Expand Down Expand Up @@ -177,6 +177,8 @@ model_config: {
- input_layer: 对输入的`feature group`配置的特征做一些额外的加工,比如执行可选的`batch normalization`、`layer normalization`、`feature dropout`等操作,并且可以指定输出的tensor的格式(2d、3d、list等);[参考文档](../component/backbone.md#id15)
- wide_output_dim: wide部分输出的tensor的维度
- keras_layer: 加载由`class_name`指定的自定义或系统内置的keras layer,执行一段代码逻辑;[参考文档](../component/backbone.md#keraslayer)
- FM: fm组件,use_variant参数表示是否使用FM的变种结构(如上图),默认为false
- Add: 内置的`tf.keras.layer.Add`,对输入做element-wise的加和操作
- concat_blocks: DAG的输出节点由`concat_blocks`配置项定义,如果不配置`concat_blocks`,框架会自动拼接DAG的所有叶子节点并输出。
- model_params:
- l2_regularization: 对DNN参数的regularization, 减少overfit
Expand Down
5 changes: 3 additions & 2 deletions easy_rec/python/loss/contrastive_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@


def l2_loss(x1, x2):
loss = tf.pow(tf.norm(x1 - x2, axis=1), 2)
return tf.reduce_mean(loss)
"""Compute euclidean distance of two embeddings."""
distance = tf.reduce_sum(tf.square(x1 - x2), axis=-1)
return tf.reduce_mean(distance)


def info_nce_loss(query, positive, temperature=0.1):
Expand Down