深度学习中显性特征组合的网络结构crossNet

crossNet

论文获取

1、原理

这个网络结构最开始提出来是在推荐领域,其核心作用就是在不增加太多参数与内存的下显式实现特征交叉组合 .其公式如下: x l x_{l} xl是第l层的输出, x 0 x_{0} x0是原始输入,那么第 x l + 1 x_{l+1} xl+1层就等于原始输入乘以上一层输出实现交叉后加上上一层输出;这样一层就是 x 2 x^2 x2的交叉,两层就有 x 3 x^3 x3的交叉,依次类推,这样就确保实现高阶的特征交叉组合.且其参数是线性增长的.

2、原理分析

  • 首先从公式看其维度是不发生变化的,所以其高阶信息是压缩过的
  • 注意到公式加上一层信息,因此不同层组合,展开其最后一层输出有保留低阶到高阶的的组合信息,但可能存在部分丢失问题
  • 该结构适合在原始输入端使用,代替特征交叉组合的特征工程
  • 该结构不建议过多层,容易导致过拟合,一般1~3层
  • 该结构适合特征本身有交叉关系的场景使用
  • 该结构使用稀疏与稠密的输入

3、实现

以torch 为例,当然实际应用通常希望加一点正则防止过拟合,此时可以通过优化器指定增加该部分结构的权重正则.

python 复制代码
crossnet = CrossNet(...)
crossnet_params = []
othernet = OtherNet(...)
#获取crossnet参数
for name, param in model.named_parameters():
    if "crossnet" in name:
        crossnet_params.append(param)
optimizer = torch.optim.Adam([
    {"params": crossnet.weights, "weight_decay":1e-4}, 
    {"params": crossnet.biases, "weight_decay":0}
], lr=0.001)
python 复制代码
class CrossNet(nn.Module):
    def __init__(self, in_features, num_layers):
        super(CrossNet, self).__init__()
        self.num_layers = num_layers
        self.in_features = in_features
        self.weights = nn.ParameterList([
            nn.Parameter(torch.randn(in_features, 1)) for _ in range(num_layers)
        ])
        self.biases = nn.ParameterList([
            nn.Parameter(torch.randn(in_features)) for _ in range(num_layers)
        ])
        self.reset_parameters()
	def forward(self, x0):
        x = x0
        for i in range(self.num_layers):
            # x: (batch, in_features)
            # x @ w: (batch, 1)
            xw = torch.matmul(x, self.weights[i])  # (batch, 1)
            # x0 * (x @ w) : broadcasting (batch, in_features)
            cross = x0 * xw  # broadcasting
            x = cross + self.biases[i] + x  # (batch, in_features)
        return x
    def reset_parameters(self):
        # 用合理的初始化方法初始化 weights 和 biases
        for w in self.weights:
            nn.init.xavier_uniform_(w)
        for b in self.biases:
            nn.init.zeros_(b)
相关推荐
机器之心2 小时前
用光学生成图像,几乎0耗电,浙大校友一作研究登Nature
人工智能·openai
苏苏susuus2 小时前
NLP:Transformer之self-attention(特别分享3)
人工智能·自然语言处理·transformer
猫天意2 小时前
【目标检测】metrice_curve和loss_curve对比图可视化
人工智能·深度学习·目标检测·计算机视觉·cv
山烛2 小时前
OpenCV:图像透视变换
人工智能·opencv·计算机视觉·图像透视变换
艾醒(AiXing-w)3 小时前
探索大语言模型(LLM):Ollama快速安装部署及使用(含Linux环境下离线安装)
linux·人工智能·语言模型
月小水长3 小时前
大模型接入自定义 MCP Server,我开发了个免费使用的基金涨跌归纳和归因分析的 Agent
人工智能·后端
咏方舟【长江支流】3 小时前
AI+华为HarmonyOS开发工具DevEco Studio详细安装指南
人工智能·华为·移动开发·harmonyos·arkts·deveco studio·长江支流
阿里云云原生3 小时前
Qoder 全新「上下文压缩」功能正式上线,省 Credits !
人工智能
我星期八休息4 小时前
深入理解跳表(Skip List):原理、实现与应用
开发语言·数据结构·人工智能·python·算法·list