Skip to content
2,400 changes: 1,194 additions & 1,206 deletions chapter_04_multilayer-perceptrons/0_mlp.ipynb

Large diffs are not rendered by default.

1,010 changes: 510 additions & 500 deletions chapter_04_multilayer-perceptrons/1_mlp-scratch.ipynb

Large diffs are not rendered by default.

451 changes: 230 additions & 221 deletions chapter_04_multilayer-perceptrons/2_mlp-concise.ipynb

Large diffs are not rendered by default.

1,865 changes: 937 additions & 928 deletions chapter_04_multilayer-perceptrons/3_underfit-overfit.ipynb

Large diffs are not rendered by default.

2,102 changes: 1,081 additions & 1,021 deletions chapter_04_multilayer-perceptrons/4_weight-decay.ipynb

Large diffs are not rendered by default.

1,423 changes: 1,125 additions & 298 deletions chapter_04_multilayer-perceptrons/5_dropout.ipynb

Large diffs are not rendered by default.

596 changes: 297 additions & 299 deletions chapter_04_multilayer-perceptrons/6_numerical-stability-and-init.ipynb

Large diffs are not rendered by default.

1,769 changes: 347 additions & 1,422 deletions chapter_04_multilayer-perceptrons/7_kaggle-house-price.ipynb

Large diffs are not rendered by default.

117 changes: 69 additions & 48 deletions chapter_05_deep-learning-computation/0_model-construction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,64 @@
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"import sys\n",
"sys.path.append('..')"
],
"execution_count": 1,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"pycharm": {
"name": "#%%\n"
}
}
},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append('..')"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {
"origin_pos": 2,
"tab": [
"pytorch"
]
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"[WARNING] CORE(326787,ffff9641e640,python):2025-12-14-22:36:28.672.832 [mindspore/core/utils/ms_context.cc:533] GetJitLevel] Set jit level to O2 for rank table startup method.\n",
"/usr/local/python3.10.14/lib/python3.10/site-packages/numpy/core/getlimits.py:500: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.\n",
" setattr(self, word, getattr(machar, word).flat[0])\n",
"/usr/local/python3.10.14/lib/python3.10/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.\n",
" return self._float_to_str(self.smallest_subnormal)\n",
"/usr/local/python3.10.14/lib/python3.10/site-packages/numpy/core/getlimits.py:500: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.\n",
" setattr(self, word, getattr(machar, word).flat[0])\n",
"/usr/local/python3.10.14/lib/python3.10/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.\n",
" return self._float_to_str(self.smallest_subnormal)\n"
]
},
{
"data": {
"text/plain": [
"Tensor(shape=[2, 10], dtype=Float32, value=\n",
"[[-6.79369224e-03, 7.97413464e-04, 3.23574618e-03 ... 7.16019771e-04, -1.44797785e-04, 1.57120079e-03],\n",
" [-6.07040105e-03, 5.09693520e-03, 4.14576288e-03 ... 1.12101820e-03, -4.35058493e-04, 4.35355678e-03]])"
"[[-6.29626662e-02, 1.17263123e-01, 2.36853719e-01 ... -1.18644319e-01, -6.00607768e-02, -3.54341976e-02],\n",
" [ 2.40386669e-02, 1.30358398e-01, 1.87603414e-01 ... -5.95855154e-03, -1.92452669e-01, 9.18698683e-03]])"
]
},
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from d2l import mindspore as d2l\n",
"import mindspore\n",
"from mindspore import nn, ops, Tensor\n",
"from mindspore import nn, mint, Tensor #ops->mint\n",
"import numpy as np\n",
"\n",
"net = nn.SequentialCell([nn.Dense(20, 256), nn.ReLU(), nn.Dense(256, 10)])\n",
Expand Down Expand Up @@ -87,7 +105,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {
"origin_pos": 12,
"tab": [
Expand Down Expand Up @@ -123,7 +141,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {
"origin_pos": 16,
"tab": [
Expand All @@ -135,11 +153,11 @@
"data": {
"text/plain": [
"Tensor(shape=[2, 10], dtype=Float32, value=\n",
"[[ 1.00408215e-06, -7.51196174e-04, -1.47786422e-03 ... 9.07916750e-04, 3.31065315e-03, 3.96206928e-03],\n",
" [-1.93189026e-03, -1.93725619e-03, -2.41200835e-03 ... 5.95276617e-03, 4.78746044e-03, 5.16231870e-03]])"
"[[-2.16613740e-01, 1.00081787e-02, -7.52887726e-02 ... -3.07381839e-01, -2.11595483e-02, -8.64412785e-02],\n",
" [-2.62258470e-01, 2.33387649e-02, 1.90157443e-04 ... -2.12538928e-01, -8.94006062e-03, -1.43828928e-01]])"
]
},
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -162,7 +180,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {
"origin_pos": 26,
"tab": [
Expand All @@ -174,11 +192,11 @@
"data": {
"text/plain": [
"Tensor(shape=[2, 10], dtype=Float32, value=\n",
"[[ 1.56846642e-03, -4.25875094e-03, 5.70291071e-04 ... -1.61940954e-03, 2.20699748e-03, -5.04909083e-03],\n",
" [-6.69776287e-04, -4.14503831e-03, 6.94219721e-04 ... -3.46967345e-03, 5.57024789e-04, -5.33907907e-03]])"
"[[ 1.53975673e-02, 1.21631876e-01, -8.63668323e-02 ... -1.22261629e-01, 2.93108106e-01, -3.11329216e-01],\n",
" [-2.56069917e-02, 1.63210899e-01, -8.27370808e-02 ... -1.32705793e-01, 3.17860305e-01, -3.00570577e-01]])"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -213,25 +231,14 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {
"origin_pos": 34,
"tab": [
"pytorch"
]
},
"outputs": [
{
"data": {
"text/plain": [
"Tensor(shape=[], dtype=Float32, value= 0.542837)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"class FixedHiddenMLP(nn.Cell):\n",
" def __init__(self):\n",
Expand All @@ -254,18 +261,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"net = FixedHiddenMLP()\n",
"net(X)"
],
"execution_count": 7,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
},
"pycharm": {
"name": "#%%\n"
}
}
},
"outputs": [
{
"data": {
"text/plain": [
"Tensor(shape=[], dtype=Float32, value= 0.0628106)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"net = FixedHiddenMLP()\n",
"net(X)"
]
},
{
"cell_type": "markdown",
Expand All @@ -280,7 +301,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 8,
"metadata": {
"origin_pos": 37,
"tab": [
Expand All @@ -291,10 +312,10 @@
{
"data": {
"text/plain": [
"Tensor(shape=[], dtype=Float32, value= -0.0956512)"
"Tensor(shape=[], dtype=Float32, value= -0.418528)"
]
},
"execution_count": 6,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -318,9 +339,9 @@
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.10",
"language": "python",
"name": "python3"
"name": "py310"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -332,7 +353,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
"version": "3.10.14"
},
"rise": {
"autolaunch": true,
Expand All @@ -343,4 +364,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
Loading