- GAN training loop from scratch
1 | discriminator = keras.Sequential( |
keras.utils.plot_model
保存模型图:
1 | model = tf.keras.Model(inputs=[input], outputs=[output]) |
keras.save
model.save()
to save the entire model as a single file. You can later recreate the same model from this file, even if the code that built the model is no longer available.
This saved file includes the:
- model architecture 模型结构
- model weight values (that were learned during training)。;模型权重
- model training config, if any (as passed to
compile
)。;模型config - optimizer and its state, if any (to restart training where you left off);优化器
1 | model.save("path_to_my_model") |
keras.Model as layer
例子:Autoencoder:
All models are callable, just like layers
You can treat any model as if it were a layer by invoking it on an
Input
or on the output of another layer. By calling a model you aren’t just reusing the architecture of the model, you’re also reusing its weights.(当使用Model作为layer时,不仅在使用模型结构同样也使用模型的权重。)
1 | # model: encoder |
ensembling:多个模型的输出集成在一起;
1 | # *ensembling*: |
multiple input & output
Sequential
API不能实现多输入多输出的要求;
Shared layers
1 | # Embedding for 1000 unique words mapped to 128-dimensional vectors |
functional API
- A functional model can be serialized or cloned
- Because a functional model is a data structure rather than a piece of code, it is safely serializable and can be saved as a single file that allows you to recreate the exact same model without having access to any of the original code.
- Functional API weakness
- The functional API treats models as DAGs of layers. This is true for most deep learning architectures, but not all — for example, recursive networks or Tree RNNs do not follow this assumption and cannot be implemented in the functional API.
functional API 形式:
1 | inputs = keras.Input(shape=(32,)) |
等价的子类形式:
1 | class MLP(keras.Model): |
whether compile before predict
- https://stackoverflow.com/questions/58378374/why-does-keras-model-predict-slower-after-compile/58385156#58385156
- https://github.com/tensorflow/tensorflow/issues/33340
速度问题
是否compile模型
1 |
|
自定义损失函数:可以包含一些超参数
1 | class CustomMSE(keras.losses.Loss): |
自定义度量信息:
__init__(self)
, in which you will create state variables for your metric.update_state(self, y_true, y_pred, sample_weight=None)
, which uses the targets y_true and the model predictions y_pred to update the state variables.result(self)
, which uses the state variables to compute the final results.reset_states(self)
, which reinitializes the state of the metric.
State update and results computation are kept separate (in update_state()
and result()
, respectively) because in some cases, results computation might be very expensive, and would only be done periodically.
1 |
|
通过add_loss
添加损失:
1 |
|
Loading mechanics
64 * 100, fanouts=[5, 10],
[320, 100] —-> [64, 5, 100]
[3200, 100] ——>[64, 50, 100]
gat模型1:
1、用8-10号的作为训练集,8-14作为预测。
阈值:模型的预测值大于阈值的order被认为是刷单。
满足增量差评率小于万分之四的时候,增量差评率为2.844,阈值是0.45,增量为31644;
2、同样8-10号的作为训练集,但是其他模型标签里做了筛选:
1 | # 其他模型预测概率大于0.2,且为刷单; |
满足增量差评率小于万分之四的时候,增量差评率为1.570,阈值是0.55,增量为25470;
9-14 号:增量差评率23000单;0.6的阈值;
这个结果是因为什么?
- 另外一天的;
3、filter-metapath之后的order数量:
1 | [ads_9ncloud@zhengchu-gpu-qz0io 09-14-2020]$ wc -l filter_order_id.txt |
Q1: use-bahavior-result(embeddingTable:= “aoftest3.aof_user_behavior_result”)这个表里的label
、prob
是对应的什么?
Prob
是预测为刷单的概率; prob和label的关联:上游模型
Q2: sku、shop的特征是什么模型得到的?
- sku,shop;统计特征;
- sku的特征是否和数据库里的一样;
Q3: 不考虑邻居节点信息,直接对每个节点做神经网络得到一个模型预测值,然后设置一个阈值,大于该阈值的order被认为是刷单,不考虑这些order的差评。为什么?
小于0.2的不用识别;
1、异构图order-sku-shop的异构图上,order-sku-order的元路径上计算相似度,
元路径Order-Sku-Order上的GAT模型1,继承自定义的基类,后续模型都能继承实现任意参数的正则化、初始化和激活等调优,模型1用2020-8-10的数据作为训练集,在预测集上以0.05作为阈值间隔生成csv统计信息;
目前预测2020-8-14号的增量差评率小于万分之四的时候,增量差评率为2.844,阈值是0.45,增量为31644;预测2020-9-14号的增量差评率为1.570,阈值是0.55,增量为25470;后续还可以通过用户行为信息进一步筛选,从而提高增量。
实现任意一条长度的元路径上做特征拼接的GAT模型2,该模型利用sku、shop等节点上的统计信息,后续可以叠加多条元路径作为训练,但目前训练(元路径为Order-Sku-Order)时F1得分不理想,后续待进一步验证数据与模型。
后续准备使用多天数据进行训练并验证增量结果,目前Galileo刚更新了版本1.0,需要对现有的模型进行重命名,调整输入文件格式等调试。