(self, field_size, layer_size=(128, 128), activation='relu', split_half=True, l2_reg=1e-5, seed=1024,
device='cpu')
| 173 | """ |
| 174 | |
| 175 | def __init__(self, field_size, layer_size=(128, 128), activation='relu', split_half=True, l2_reg=1e-5, seed=1024, |
| 176 | device='cpu'): |
| 177 | super(CIN, self).__init__() |
| 178 | if len(layer_size) == 0: |
| 179 | raise ValueError( |
| 180 | "layer_size must be a list(tuple) of length greater than 1") |
| 181 | |
| 182 | self.layer_size = layer_size |
| 183 | self.field_nums = [field_size] |
| 184 | self.split_half = split_half |
| 185 | self.activation = activation_layer(activation) |
| 186 | self.l2_reg = l2_reg |
| 187 | self.seed = seed |
| 188 | |
| 189 | self.conv1ds = nn.ModuleList() |
| 190 | for i, size in enumerate(self.layer_size): |
| 191 | self.conv1ds.append( |
| 192 | nn.Conv1d(self.field_nums[-1] * self.field_nums[0], size, 1)) |
| 193 | |
| 194 | if self.split_half: |
| 195 | if i != len(self.layer_size) - 1 and size % 2 > 0: |
| 196 | raise ValueError( |
| 197 | "layer_size must be even number except for the last layer when split_half=True") |
| 198 | |
| 199 | self.field_nums.append(size // 2) |
| 200 | else: |
| 201 | self.field_nums.append(size) |
| 202 | |
| 203 | # for tensor in self.conv1ds: |
| 204 | # nn.init.normal_(tensor.weight, mean=0, std=init_std) |
| 205 | self.to(device) |
| 206 | |
| 207 | def forward(self, inputs): |
| 208 | if len(inputs.shape) != 3: |
nothing calls this directly
no test coverage detected