Newer
Older
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img width=\"800px\" src=\"../fidle/img/header.svg\"></img>\n",
"\n",
"# <!-- TITLE --> [K3LSTM1] - Basic Keras LSTM Layer\n",
"<!-- DESC --> A small example of an LSTM layer in Keras\n",
"\n",
"<!-- AUTHOR : Jean-Luc Parouty (CNRS/SIMaP) -->"
]
},
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"os.environ['KERAS_BACKEND'] = 'torch'\n",
"\n",
"import keras\n",
"\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"input = keras.random.normal( [32, 20, 8] )\n",
"\n",
"lstm = keras.layers.LSTM(16)\n",
"output = lstm(input)\n",
"\n",
"print('input shape is : ',input.shape)\n",
"print('output shape is : ',output.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"input = keras.random.normal( [32, 20, 8] )\n",
"\n",
"lstm = keras.layers.LSTM(18, return_sequences=True, return_state=True)\n",
"output, memory_state, carry_state = lstm(input)\n",
"\n",
"print('input shape : ',input.shape)\n",
"print('output shape : ',output.shape)\n",
"print('memory_state : ', memory_state.shape)\n",
"print('carry_state : ', memory_state.shape)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"<img width=\"80px\" src=\"../fidle/img/logo-paysage.svg\"></img>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "fidle-env",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}