| 224 | |
| 225 | template<OptimizerType optimizer_type> |
| 226 | __host__ __device__ |
| 227 | static void backward(Vector &head, Vector &tail, Vector &relation, |
| 228 | float l3_regularization, Float gradient, const Optimizer &optimizer, |
| 229 | float relation_lr_multiplier = 1, Float weight = 1) { |
| 230 | auto update = get_update_function<Float, optimizer_type>(); |
| 231 | l3_regularization *= 3; |
| 232 | FOR(i, dim / 2) { |
| 233 | Float h_re = head[i * 2]; |
| 234 | Float h_im = head[i * 2 + 1]; |
| 235 | Float t_re = tail[i * 2]; |
| 236 | Float t_im = tail[i * 2 + 1]; |
| 237 | Float r_re = relation[i * 2]; |
| 238 | Float r_im = relation[i * 2 + 1]; |
| 239 | // head |
| 240 | Float h_re_grad = gradient * (r_re * t_re + r_im * t_im); |
| 241 | Float h_im_grad = gradient * (-r_im * t_re + r_re * t_im); |
| 242 | head[i * 2] -= (optimizer.*update)(h_re, h_re_grad + l3_regularization * abs(h_re) * h_re, weight); |
| 243 | head[i * 2 + 1] -= (optimizer.*update)(h_im, h_im_grad + l3_regularization * abs(h_im) * h_im, weight); |
| 244 | // tail |
| 245 | Float t_re_grad = gradient * (h_re * r_re - h_im * r_im); |
| 246 | Float t_im_grad = gradient * (h_re * r_im + h_im * r_re); |
| 247 | tail[i * 2] -= (optimizer.*update)(t_re, t_re_grad + l3_regularization * abs(t_re) * t_re, weight); |
| 248 | tail[i * 2 + 1] -= (optimizer.*update)(t_im, t_im_grad + l3_regularization * abs(t_im) * t_im, weight); |
| 249 | // relation |
| 250 | Float r_re_grad = gradient * (h_re * t_re + h_im * t_im); |
| 251 | Float r_im_grad = gradient * (-h_im * t_re + h_re * t_im); |
| 252 | relation[i * 2] -= relation_lr_multiplier * |
| 253 | (optimizer.*update)(r_re, r_re_grad + l3_regularization * abs(r_re) * r_re, weight); |
| 254 | relation[i * 2 + 1] -= relation_lr_multiplier * |
| 255 | (optimizer.*update)(r_im, r_im_grad + l3_regularization * abs(r_im) * r_im, weight); |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | template<OptimizerType optimizer_type> |
| 260 | __host__ __device__ |
nothing calls this directly
no outgoing calls
no test coverage detected