43个重量
到目前为止,发布的两个解决方案非常聪明,但是它们的方法可能不适用于机器学习中更传统的任务(例如OCR)。因此,我想为此任务提交一个“通用”(绝妙的技巧)解决方案,以期激励其他人对此进行改进,并被机器学习领域所吸引:
我的模型是一个非常简单的神经网络,具有在TensorFlow 2.0中构建的2个隐藏层(但其他任何框架也可以使用):
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(6, activation='tanh', input_shape=(2,)),
tf.keras.layers.Dense(3, activation='tanh'),
tf.keras.layers.Dense(1, activation='linear')
])
如您所见,除了输出层(由于该任务的性质,具有线性激活功能。
有43个权重: 
- (2+1)⋅6=18
- (6+1)⋅3=21
- (3+1)⋅1=4
−1010
接下来,我对其进行了微调-针对任何整数乘法任务优化了最大偏差。不幸的是,我的笔记并没有显示出我最终做过的微调,但这是非常小的。在这441个训练样本上的100个纪元附近,批量为441个。
这些是我最终得到的权重:
[<tf.Variable 'dense/kernel:0' shape=(2, 6) dtype=float32, numpy=
 array([[ 0.10697944,  0.05394982,  0.05479664, -0.04538541,  0.05369904,
         -0.0728976 ],
        [ 0.10571832,  0.05576797, -0.04670485, -0.04466859, -0.05855528,
         -0.07390639]], dtype=float32)>,
 <tf.Variable 'dense/bias:0' shape=(6,) dtype=float32, numpy=
 array([-3.4242163, -0.8875816, -1.7694025, -1.9409281,  1.7825342,
         1.1364107], dtype=float32)>,
 <tf.Variable 'dense_1/kernel:0' shape=(6, 3) dtype=float32, numpy=
 array([[-3.0665843 ,  0.64912266,  3.7107112 ],
        [ 0.4914808 ,  2.1569328 ,  0.65417236],
        [ 3.461693  ,  1.2072319 , -4.181983  ],
        [-2.8746269 , -4.9959164 ,  4.505049  ],
        [-2.920127  , -0.0665407 ,  4.1409926 ],
        [ 1.3777553 , -3.3750365 , -0.10507642]], dtype=float32)>,
 <tf.Variable 'dense_1/bias:0' shape=(3,) dtype=float32, numpy=array([-1.376577  ,  2.8885336 ,  0.19852689], dtype=float32)>,
 <tf.Variable 'dense_2/kernel:0' shape=(3, 1) dtype=float32, numpy=
 array([[-78.7569  ],
        [-23.602606],
        [ 84.29587 ]], dtype=float32)>,
 <tf.Variable 'dense_2/bias:0' shape=(1,) dtype=float32, numpy=array([8.521169], dtype=float32)>]
0.443504339⋅10=90.443504
我的模型可以在这里找到,您也可以在线尝试!在Google Colab环境中。