1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216
|
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="http://keras.io/layers/recurrent/">
<link rel="shortcut icon" href="../../img/favicon.ico">
<title>Recurrent Layers - Keras Documentation</title>
<link href='https://fonts.googleapis.com/css?family=Lato:400,700|Source+Sans+Pro:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="../../css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../css/theme_extra.css" type="text/css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css">
<script>
// Current page data
var mkdocs_page_name = "Recurrent Layers";
var mkdocs_page_input_path = "layers/recurrent.md";
var mkdocs_page_url = "/layers/recurrent/";
</script>
<script src="../../js/jquery-2.1.1.min.js" defer></script>
<script src="../../js/modernizr-2.8.3.min.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-61785484-1', 'keras.io');
ga('send', 'pageview');
</script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side stickynav">
<div class="wy-side-scroll">
<a href="">
<div class="keras-logo">
<img src="/img/keras-logo-small.jpg" class="keras-logo-img">
Keras Documentation
</div>
</a>
<div class="wy-side-nav-search">
<div role="search">
<form id ="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" title="Type search term here" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../..">Home</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../why-use-keras/">Why use Keras</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Getting started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../getting-started/sequential-model-guide/">Guide to the Sequential model</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../getting-started/functional-api-guide/">Guide to the Functional API</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../getting-started/faq/">FAQ</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Models</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../models/about-keras-models/">About Keras models</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../models/sequential/">Sequential</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../models/model/">Model (functional API)</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Layers</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../about-keras-layers/">About Keras layers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../core/">Core Layers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../convolutional/">Convolutional Layers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../pooling/">Pooling Layers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../local/">Locally-connected Layers</a>
</li>
<li class="toctree-l1 current"><a class="reference internal current" href="./">Recurrent Layers</a>
<ul class="current">
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../embeddings/">Embedding Layers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../merge/">Merge Layers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../advanced-activations/">Advanced Activations Layers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../normalization/">Normalization Layers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../noise/">Noise layers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../wrappers/">Layer wrappers</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../writing-your-own-keras-layers/">Writing your own Keras layers</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Preprocessing</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../preprocessing/sequence/">Sequence Preprocessing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../preprocessing/text/">Text Preprocessing</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../preprocessing/image/">Image Preprocessing</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../losses/">Losses</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../metrics/">Metrics</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../optimizers/">Optimizers</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../activations/">Activations</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../callbacks/">Callbacks</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../datasets/">Datasets</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../applications/">Applications</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../backend/">Backend</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../initializers/">Initializers</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../regularizers/">Regularizers</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../constraints/">Constraints</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../visualization/">Visualization</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../scikit-learn-api/">Scikit-learn API</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../utils/">Utils</a>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../contributing/">Contributing</a>
</li>
</ul>
<p class="caption"><span class="caption-text">Examples</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../examples/addition_rnn/">Addition RNN</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/antirectifier/">Custom layer - antirectifier</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/babi_rnn/">Baby RNN</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/babi_memnn/">Baby MemNN</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/cifar10_cnn/">CIFAR-10 CNN</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/cifar10_resnet/">CIFAR-10 ResNet</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/conv_filter_visualization/">Convolution filter visualization</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/conv_lstm/">Convolutional LSTM</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/deep_dream/">Deep Dream</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/image_ocr/">Image OCR</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/imdb_bidirectional_lstm/">Bidirectional LSTM</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/imdb_cnn/">1D CNN for text classification</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/imdb_cnn_lstm/">Sentiment classification CNN-LSTM</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/imdb_fasttext/">Fasttext for text classification</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/imdb_lstm/">Sentiment classification LSTM</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/lstm_seq2seq/">Sequence to sequence - training</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/lstm_seq2seq_restore/">Sequence to sequence - prediction</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/lstm_stateful/">Stateful LSTM</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/lstm_text_generation/">LSTM for text generation</a>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../examples/mnist_acgan/">Auxiliary Classifier GAN</a>
</li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../..">Keras Documentation</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../..">Docs</a> »</li>
<li>Layers »</li>
<li>Recurrent Layers</li>
<li class="wy-breadcrumbs-aside">
<a href="https://github.com/keras-team/keras/tree/master/docs"
class="icon icon-github"> Edit on GitHub</a>
</li>
</ul>
<hr/>
</div>
<div role="main">
<div class="section">
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/recurrent.py#L239">[source]</a></span></p>
<h3 id="rnn">RNN</h3>
<pre><code class="python">keras.engine.base_layer.wrapped_fn()
</code></pre>
<p>Base class for recurrent layers.</p>
<p><strong>Arguments</strong></p>
<ul>
<li>
<p><strong>cell</strong>: A RNN cell instance. A RNN cell is a class that has:</p>
<ul>
<li>a <code>call(input_at_t, states_at_t)</code> method, returning
<code>(output_at_t, states_at_t_plus_1)</code>. The call method of the
cell can also take the optional argument <code>constants</code>, see
section "Note on passing external constants" below.</li>
<li>a <code>state_size</code> attribute. This can be a single integer
(single state) in which case it is
the size of the recurrent state
(which should be the same as the size of the cell output).
This can also be a list/tuple of integers
(one size per state).</li>
<li>a <code>output_size</code> attribute. This can be a single integer or a
TensorShape, which represent the shape of the output. For
backward compatible reason, if this attribute is not available
for the cell, the value will be inferred by the first element
of the <code>state_size</code>.</li>
</ul>
<p>It is also possible for <code>cell</code> to be a list of RNN cell instances,
in which cases the cells get stacked one after the other in the RNN,
implementing an efficient stacked RNN.</p>
</li>
<li>
<p><strong>return_sequences</strong>: Boolean. Whether to return the last output
in the output sequence, or the full sequence.</p>
</li>
<li><strong>return_state</strong>: Boolean. Whether to return the last state
in addition to the output.</li>
<li><strong>go_backwards</strong>: Boolean (default False).
If True, process the input sequence backwards and return the
reversed sequence.</li>
<li><strong>stateful</strong>: Boolean (default False). If True, the last state
for each sample at index i in a batch will be used as initial
state for the sample of index i in the following batch.</li>
<li><strong>unroll</strong>: Boolean (default False).
If True, the network will be unrolled,
else a symbolic loop will be used.
Unrolling can speed-up a RNN,
although it tends to be more memory-intensive.
Unrolling is only suitable for short sequences.</li>
<li><strong>input_dim</strong>: dimensionality of the input (integer).
This argument (or alternatively,
the keyword argument <code>input_shape</code>)
is required when using this layer as the first layer in a model.</li>
<li><strong>input_length</strong>: Length of input sequences, to be specified
when it is constant.
This argument is required if you are going to connect
<code>Flatten</code> then <code>Dense</code> layers upstream
(without it, the shape of the dense outputs cannot be computed).
Note that if the recurrent layer is not the first layer
in your model, you would need to specify the input length
at the level of the first layer
(e.g. via the <code>input_shape</code> argument)</li>
</ul>
<p><strong>Input shape</strong></p>
<p>3D tensor with shape <code>(batch_size, timesteps, input_dim)</code>.</p>
<p><strong>Output shape</strong></p>
<ul>
<li>if <code>return_state</code>: a list of tensors. The first tensor is
the output. The remaining tensors are the last states,
each with shape <code>(batch_size, units)</code>. For example, the number of
state tensors is 1 (for RNN and GRU) or 2 (for LSTM).</li>
<li>if <code>return_sequences</code>: 3D tensor with shape
<code>(batch_size, timesteps, units)</code>.</li>
<li>else, 2D tensor with shape <code>(batch_size, units)</code>.</li>
</ul>
<p><strong>Masking</strong></p>
<p>This layer supports masking for input data with a variable number
of timesteps. To introduce masks to your data,
use an <a href="../embeddings/">Embedding</a> layer with the <code>mask_zero</code> parameter
set to <code>True</code>.</p>
<p><strong>Note on using statefulness in RNNs</strong></p>
<p>You can set RNN layers to be 'stateful', which means that the states
computed for the samples in one batch will be reused as initial states
for the samples in the next batch. This assumes a one-to-one mapping
between samples in different successive batches.</p>
<p>To enable statefulness:
- specify <code>stateful=True</code> in the layer constructor.
- specify a fixed batch size for your model, by passing
if sequential model:
<code>batch_input_shape=(...)</code> to the first layer in your model.
else for functional model with 1 or more Input layers:
<code>batch_shape=(...)</code> to all the first layers in your model.
This is the expected shape of your inputs
<em>including the batch size</em>.
It should be a tuple of integers, e.g. <code>(32, 10, 100)</code>.
- specify <code>shuffle=False</code> when calling fit().</p>
<p>To reset the states of your model, call <code>.reset_states()</code> on either
a specific layer, or on your entire model.</p>
<p><strong>Note on specifying the initial state of RNNs</strong></p>
<p>You can specify the initial state of RNN layers symbolically by
calling them with the keyword argument <code>initial_state</code>. The value of
<code>initial_state</code> should be a tensor or list of tensors representing
the initial state of the RNN layer.</p>
<p>You can specify the initial state of RNN layers numerically by
calling <code>reset_states</code> with the keyword argument <code>states</code>. The value of
<code>states</code> should be a numpy array or list of numpy arrays representing
the initial state of the RNN layer.</p>
<p><strong>Note on passing external constants to RNNs</strong></p>
<p>You can pass "external" constants to the cell using the <code>constants</code>
keyword argument of <code>RNN.__call__</code> (as well as <code>RNN.call</code>) method. This
requires that the <code>cell.call</code> method accepts the same keyword argument
<code>constants</code>. Such constants can be used to condition the cell
transformation on additional static inputs (not changing over time),
a.k.a. an attention mechanism.</p>
<p><strong>Examples</strong></p>
<pre><code class="python"># First, let's define a RNN Cell, as a layer subclass.
class MinimalRNNCell(keras.layers.Layer):
def __init__(self, units, **kwargs):
self.units = units
self.state_size = units
super(MinimalRNNCell, self).__init__(**kwargs)
def build(self, input_shape):
self.kernel = self.add_weight(shape=(input_shape[-1], self.units),
initializer='uniform',
name='kernel')
self.recurrent_kernel = self.add_weight(
shape=(self.units, self.units),
initializer='uniform',
name='recurrent_kernel')
self.built = True
def call(self, inputs, states):
prev_output = states[0]
h = K.dot(inputs, self.kernel)
output = h + K.dot(prev_output, self.recurrent_kernel)
return output, [output]
# Let's use this cell in a RNN layer:
cell = MinimalRNNCell(32)
x = keras.Input((None, 5))
layer = RNN(cell)
y = layer(x)
# Here's how to use the cell to build a stacked RNN:
cells = [MinimalRNNCell(32), MinimalRNNCell(64)]
x = keras.Input((None, 5))
layer = RNN(cells)
y = layer(x)
</code></pre>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/recurrent.py#L972">[source]</a></span></p>
<h3 id="simplernn">SimpleRNN</h3>
<pre><code class="python">keras.layers.SimpleRNN(units, activation='tanh', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, return_sequences=False, return_state=False, go_backwards=False, stateful=False, unroll=False)
</code></pre>
<p>Fully-connected RNN where the output is to be fed back to input.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>units</strong>: Positive integer, dimensionality of the output space.</li>
<li><strong>activation</strong>: Activation function to use
(see <a href="../../activations/">activations</a>).
Default: hyperbolic tangent (<code>tanh</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).</li>
<li><strong>use_bias</strong>: Boolean, whether the layer uses a bias vector.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>activity_regularizer</strong>: Regularizer function applied to
the output of the layer (its "activation").
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the inputs.</li>
<li><strong>recurrent_dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the recurrent state.</li>
<li><strong>return_sequences</strong>: Boolean. Whether to return the last output
in the output sequence, or the full sequence.</li>
<li><strong>return_state</strong>: Boolean. Whether to return the last state
in addition to the output.</li>
<li><strong>go_backwards</strong>: Boolean (default False).
If True, process the input sequence backwards and return the
reversed sequence.</li>
<li><strong>stateful</strong>: Boolean (default False). If True, the last state
for each sample at index i in a batch will be used as initial
state for the sample of index i in the following batch.</li>
<li><strong>unroll</strong>: Boolean (default False).
If True, the network will be unrolled,
else a symbolic loop will be used.
Unrolling can speed-up a RNN,
although it tends to be more memory-intensive.
Unrolling is only suitable for short sequences.</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/recurrent.py#L1519">[source]</a></span></p>
<h3 id="gru">GRU</h3>
<pre><code class="python">keras.layers.GRU(units, activation='tanh', recurrent_activation='sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=2, return_sequences=False, return_state=False, go_backwards=False, stateful=False, unroll=False, reset_after=False)
</code></pre>
<p>Gated Recurrent Unit - Cho et al. 2014.</p>
<p>There are two variants. The default one is based on 1406.1078v3 and
has reset gate applied to hidden state before matrix multiplication. The
other one is based on original 1406.1078v1 and has the order reversed.</p>
<p>The second variant is compatible with CuDNNGRU (GPU-only) and allows
inference on CPU. Thus it has separate biases for <code>kernel</code> and
<code>recurrent_kernel</code>. Use <code>'reset_after'=True</code> and
<code>recurrent_activation='sigmoid'</code>.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>units</strong>: Positive integer, dimensionality of the output space.</li>
<li><strong>activation</strong>: Activation function to use
(see <a href="../../activations/">activations</a>).
Default: hyperbolic tangent (<code>tanh</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).</li>
<li><strong>recurrent_activation</strong>: Activation function to use
for the recurrent step
(see <a href="../../activations/">activations</a>).
Default: hard sigmoid (<code>hard_sigmoid</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).</li>
<li><strong>use_bias</strong>: Boolean, whether the layer uses a bias vector.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>activity_regularizer</strong>: Regularizer function applied to
the output of the layer (its "activation").
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the inputs.</li>
<li><strong>recurrent_dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the recurrent state.</li>
<li><strong>implementation</strong>: Implementation mode, either 1 or 2.
Mode 1 will structure its operations as a larger number of
smaller dot products and additions, whereas mode 2 will
batch them into fewer, larger operations. These modes will
have different performance profiles on different hardware and
for different applications.</li>
<li><strong>return_sequences</strong>: Boolean. Whether to return the last output
in the output sequence, or the full sequence.</li>
<li><strong>return_state</strong>: Boolean. Whether to return the last state
in addition to the output.</li>
<li><strong>go_backwards</strong>: Boolean (default False).
If True, process the input sequence backwards and return the
reversed sequence.</li>
<li><strong>stateful</strong>: Boolean (default False). If True, the last state
for each sample at index i in a batch will be used as initial
state for the sample of index i in the following batch.</li>
<li><strong>unroll</strong>: Boolean (default False).
If True, the network will be unrolled,
else a symbolic loop will be used.
Unrolling can speed-up a RNN,
although it tends to be more memory-intensive.
Unrolling is only suitable for short sequences.</li>
<li><strong>reset_after</strong>: GRU convention (whether to apply reset gate after or
before matrix multiplication). False = "before" (default),
True = "after" (CuDNN compatible).</li>
</ul>
<p><strong>References</strong></p>
<ul>
<li><a href="https://arxiv.org/abs/1406.1078">Learning Phrase Representations using RNN Encoder-Decoder for
Statistical Machine Translation</a></li>
<li><a href="https://arxiv.org/abs/1409.1259">On the Properties of Neural Machine Translation:
Encoder-Decoder Approaches</a></li>
<li><a href="https://arxiv.org/abs/1412.3555v1">Empirical Evaluation of Gated Recurrent Neural Networks on
Sequence Modeling</a></li>
<li><a href="https://arxiv.org/abs/1512.05287">A Theoretically Grounded Application of Dropout in
Recurrent Neural Networks</a></li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/recurrent.py#L2081">[source]</a></span></p>
<h3 id="lstm">LSTM</h3>
<pre><code class="python">keras.layers.LSTM(units, activation='tanh', recurrent_activation='sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=2, return_sequences=False, return_state=False, go_backwards=False, stateful=False, unroll=False)
</code></pre>
<p>Long Short-Term Memory layer - Hochreiter 1997.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>units</strong>: Positive integer, dimensionality of the output space.</li>
<li><strong>activation</strong>: Activation function to use
(see <a href="../../activations/">activations</a>).
Default: hyperbolic tangent (<code>tanh</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).</li>
<li><strong>recurrent_activation</strong>: Activation function to use
for the recurrent step
(see <a href="../../activations/">activations</a>).
Default: hard sigmoid (<code>hard_sigmoid</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).</li>
<li><strong>use_bias</strong>: Boolean, whether the layer uses a bias vector.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>unit_forget_bias</strong>: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Setting it to true will also force <code>bias_initializer="zeros"</code>.
This is recommended in <a href="http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf">Jozefowicz et al. (2015)</a>.</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>activity_regularizer</strong>: Regularizer function applied to
the output of the layer (its "activation").
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the inputs.</li>
<li><strong>recurrent_dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the recurrent state.</li>
<li><strong>implementation</strong>: Implementation mode, either 1 or 2.
Mode 1 will structure its operations as a larger number of
smaller dot products and additions, whereas mode 2 will
batch them into fewer, larger operations. These modes will
have different performance profiles on different hardware and
for different applications.</li>
<li><strong>return_sequences</strong>: Boolean. Whether to return the last output
in the output sequence, or the full sequence.</li>
<li><strong>return_state</strong>: Boolean. Whether to return the last state
in addition to the output. The returned elements of the
states list are the hidden state and the cell state, respectively.</li>
<li><strong>go_backwards</strong>: Boolean (default False).
If True, process the input sequence backwards and return the
reversed sequence.</li>
<li><strong>stateful</strong>: Boolean (default False). If True, the last state
for each sample at index i in a batch will be used as initial
state for the sample of index i in the following batch.</li>
<li><strong>unroll</strong>: Boolean (default False).
If True, the network will be unrolled,
else a symbolic loop will be used.
Unrolling can speed-up a RNN,
although it tends to be more memory-intensive.
Unrolling is only suitable for short sequences.</li>
</ul>
<p><strong>References</strong></p>
<ul>
<li><a href="http://www.bioinf.jku.at/publications/older/2604.pdf">Long short-term memory</a></li>
<li><a href="http://www.mitpressjournals.org/doi/pdf/10.1162/089976600300015015">Learning to forget: Continual prediction with LSTM</a></li>
<li><a href="http://www.cs.toronto.edu/~graves/preprint.pdf">Supervised sequence labeling with recurrent neural networks</a></li>
<li><a href="https://arxiv.org/abs/1512.05287">A Theoretically Grounded Application of Dropout in
Recurrent Neural Networks</a></li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/convolutional_recurrent.py#L795">[source]</a></span></p>
<h3 id="convlstm2d">ConvLSTM2D</h3>
<pre><code class="python">keras.layers.ConvLSTM2D(filters, kernel_size, strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1), activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, return_sequences=False, go_backwards=False, stateful=False, dropout=0.0, recurrent_dropout=0.0)
</code></pre>
<p>Convolutional LSTM.</p>
<p>It is similar to an LSTM layer, but the input transformations
and recurrent transformations are both convolutional.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>filters</strong>: Integer, the dimensionality of the output space
(i.e. the number output of filters in the convolution).</li>
<li><strong>kernel_size</strong>: An integer or tuple/list of n integers, specifying the
dimensions of the convolution window.</li>
<li><strong>strides</strong>: An integer or tuple/list of n integers,
specifying the strides of the convolution.
Specifying any stride value != 1 is incompatible with specifying
any <code>dilation_rate</code> value != 1.</li>
<li><strong>padding</strong>: One of <code>"valid"</code> or <code>"same"</code> (case-insensitive).</li>
<li><strong>data_format</strong>: A string,
one of <code>"channels_last"</code> (default) or <code>"channels_first"</code>.
The ordering of the dimensions in the inputs.
<code>"channels_last"</code> corresponds to inputs with shape
<code>(batch, time, ..., channels)</code>
while <code>"channels_first"</code> corresponds to
inputs with shape <code>(batch, time, channels, ...)</code>.
It defaults to the <code>image_data_format</code> value found in your
Keras config file at <code>~/.keras/keras.json</code>.
If you never set it, then it will be <code>"channels_last"</code>.</li>
<li><strong>dilation_rate</strong>: An integer or tuple/list of n integers, specifying
the dilation rate to use for dilated convolution.
Currently, specifying any <code>dilation_rate</code> value != 1 is
incompatible with specifying any <code>strides</code> value != 1.</li>
<li><strong>activation</strong>: Activation function to use
(see <a href="../../activations/">activations</a>).</li>
<li><strong>recurrent_activation</strong>: Activation function to use
for the recurrent step
(see <a href="../../activations/">activations</a>).</li>
<li><strong>use_bias</strong>: Boolean, whether the layer uses a bias vector.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>unit_forget_bias</strong>: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Use in combination with <code>bias_initializer="zeros"</code>.
This is recommended in <a href="http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf">Jozefowicz et al. (2015)</a>.</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>activity_regularizer</strong>: Regularizer function applied to
the output of the layer (its "activation").
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>return_sequences</strong>: Boolean. Whether to return the last output
in the output sequence, or the full sequence.</li>
<li><strong>go_backwards</strong>: Boolean (default False).
If True, process the input sequence backwards.</li>
<li><strong>stateful</strong>: Boolean (default False). If True, the last state
for each sample at index i in a batch will be used as initial
state for the sample of index i in the following batch.</li>
<li><strong>dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the inputs.</li>
<li><strong>recurrent_dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the recurrent state.</li>
</ul>
<p><strong>Input shape</strong></p>
<ul>
<li>if data_format='channels_first'
5D tensor with shape:
<code>(samples, time, channels, rows, cols)</code></li>
<li>if data_format='channels_last'
5D tensor with shape:
<code>(samples, time, rows, cols, channels)</code></li>
</ul>
<p><strong>Output shape</strong></p>
<ul>
<li>if <code>return_sequences</code><ul>
<li>if data_format='channels_first'
5D tensor with shape:
<code>(samples, time, filters, output_row, output_col)</code></li>
<li>if data_format='channels_last'
5D tensor with shape:
<code>(samples, time, output_row, output_col, filters)</code></li>
</ul>
</li>
<li>
<p>else</p>
<ul>
<li>if data_format='channels_first'
4D tensor with shape:
<code>(samples, filters, output_row, output_col)</code></li>
<li>if data_format='channels_last'
4D tensor with shape:
<code>(samples, output_row, output_col, filters)</code></li>
</ul>
<p>where o_row and o_col depend on the shape of the filter and
the padding</p>
</li>
</ul>
<p><strong>Raises</strong></p>
<ul>
<li><strong>ValueError</strong>: in case of invalid constructor arguments.</li>
</ul>
<p><strong>References</strong></p>
<ul>
<li><a href="http://arxiv.org/abs/1506.04214v1">Convolutional LSTM Network: A Machine Learning Approach for
Precipitation Nowcasting</a>
The current implementation does not include the feedback loop on the
cells output</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/convolutional_recurrent.py#L479">[source]</a></span></p>
<h3 id="convlstm2dcell">ConvLSTM2DCell</h3>
<pre><code class="python">keras.layers.ConvLSTM2DCell(filters, kernel_size, strides=(1, 1), padding='valid', data_format=None, dilation_rate=(1, 1), activation='tanh', recurrent_activation='hard_sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0)
</code></pre>
<p>Cell class for the ConvLSTM2D layer.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>filters</strong>: Integer, the dimensionality of the output space
(i.e. the number of output filters in the convolution).</li>
<li><strong>kernel_size</strong>: An integer or tuple/list of n integers, specifying the
dimensions of the convolution window.</li>
<li><strong>strides</strong>: An integer or tuple/list of n integers,
specifying the strides of the convolution.
Specifying any stride value != 1 is incompatible with specifying
any <code>dilation_rate</code> value != 1.</li>
<li><strong>padding</strong>: One of <code>"valid"</code> or <code>"same"</code> (case-insensitive).</li>
<li><strong>data_format</strong>: A string,
one of <code>"channels_last"</code> (default) or <code>"channels_first"</code>.
It defaults to the <code>image_data_format</code> value found in your
Keras config file at <code>~/.keras/keras.json</code>.
If you never set it, then it will be <code>"channels_last"</code>.</li>
<li><strong>dilation_rate</strong>: An integer or tuple/list of n integers, specifying
the dilation rate to use for dilated convolution.
Currently, specifying any <code>dilation_rate</code> value != 1 is
incompatible with specifying any <code>strides</code> value != 1.</li>
<li><strong>activation</strong>: Activation function to use
(see <a href="../../activations/">activations</a>).</li>
<li><strong>recurrent_activation</strong>: Activation function to use
for the recurrent step
(see <a href="../../activations/">activations</a>).</li>
<li><strong>use_bias</strong>: Boolean, whether the layer uses a bias vector.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>unit_forget_bias</strong>: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Use in combination with <code>bias_initializer="zeros"</code>.
This is recommended in <a href="http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf">Jozefowicz et al. (2015)</a>.</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the inputs.</li>
<li><strong>recurrent_dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the recurrent state.</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/recurrent.py#L807">[source]</a></span></p>
<h3 id="simplernncell">SimpleRNNCell</h3>
<pre><code class="python">keras.layers.SimpleRNNCell(units, activation='tanh', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0)
</code></pre>
<p>Cell class for SimpleRNN.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>units</strong>: Positive integer, dimensionality of the output space.</li>
<li><strong>activation</strong>: Activation function to use
(see <a href="../../activations/">activations</a>).
Default: hyperbolic tangent (<code>tanh</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).</li>
<li><strong>use_bias</strong>: Boolean, whether the layer uses a bias vector.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the inputs.</li>
<li><strong>recurrent_dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the recurrent state.</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/recurrent.py#L1191">[source]</a></span></p>
<h3 id="grucell">GRUCell</h3>
<pre><code class="python">keras.layers.GRUCell(units, activation='tanh', recurrent_activation='sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=2, reset_after=False)
</code></pre>
<p>Cell class for the GRU layer.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>units</strong>: Positive integer, dimensionality of the output space.</li>
<li><strong>activation</strong>: Activation function to use
(see <a href="../../activations/">activations</a>).
Default: hyperbolic tangent (<code>tanh</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).</li>
<li><strong>recurrent_activation</strong>: Activation function to use
for the recurrent step
(see <a href="../../activations/">activations</a>).
Default: hard sigmoid (<code>hard_sigmoid</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).</li>
<li><strong>use_bias</strong>: Boolean, whether the layer uses a bias vector.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the inputs.</li>
<li><strong>recurrent_dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the recurrent state.</li>
<li><strong>implementation</strong>: Implementation mode, either 1 or 2.
Mode 1 will structure its operations as a larger number of
smaller dot products and additions, whereas mode 2 will
batch them into fewer, larger operations. These modes will
have different performance profiles on different hardware and
for different applications.</li>
<li><strong>reset_after</strong>: GRU convention (whether to apply reset gate after or
before matrix multiplication). False = "before" (default),
True = "after" (CuDNN compatible).</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/recurrent.py#L1793">[source]</a></span></p>
<h3 id="lstmcell">LSTMCell</h3>
<pre><code class="python">keras.layers.LSTMCell(units, activation='tanh', recurrent_activation='sigmoid', use_bias=True, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, dropout=0.0, recurrent_dropout=0.0, implementation=2)
</code></pre>
<p>Cell class for the LSTM layer.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>units</strong>: Positive integer, dimensionality of the output space.</li>
<li><strong>activation</strong>: Activation function to use
(see <a href="../../activations/">activations</a>).
Default: hyperbolic tangent (<code>tanh</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).</li>
<li><strong>recurrent_activation</strong>: Activation function to use
for the recurrent step
(see <a href="../../activations/">activations</a>).
Default: hard sigmoid (<code>hard_sigmoid</code>).
If you pass <code>None</code>, no activation is applied
(ie. "linear" activation: <code>a(x) = x</code>).x</li>
<li><strong>use_bias</strong>: Boolean, whether the layer uses a bias vector.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>unit_forget_bias</strong>: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Setting it to true will also force <code>bias_initializer="zeros"</code>.
This is recommended in <a href="http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf">Jozefowicz et al. (2015)</a>.</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the inputs.</li>
<li><strong>recurrent_dropout</strong>: Float between 0 and 1.
Fraction of the units to drop for
the linear transformation of the recurrent state.</li>
<li><strong>implementation</strong>: Implementation mode, either 1 or 2.
Mode 1 will structure its operations as a larger number of
smaller dot products and additions, whereas mode 2 will
batch them into fewer, larger operations. These modes will
have different performance profiles on different hardware and
for different applications.</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/cudnn_recurrent.py#L135">[source]</a></span></p>
<h3 id="cudnngru">CuDNNGRU</h3>
<pre><code class="python">keras.layers.CuDNNGRU(units, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, return_sequences=False, return_state=False, stateful=False)
</code></pre>
<p>Fast GRU implementation backed by <a href="https://developer.nvidia.com/cudnn">CuDNN</a>.</p>
<p>Can only be run on GPU, with the TensorFlow backend.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>units</strong>: Positive integer, dimensionality of the output space.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>activity_regularizer</strong>: Regularizer function applied to
the output of the layer (its "activation").
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>return_sequences</strong>: Boolean. Whether to return the last output.
in the output sequence, or the full sequence.</li>
<li><strong>return_state</strong>: Boolean. Whether to return the last state
in addition to the output.</li>
<li><strong>stateful</strong>: Boolean (default False). If True, the last state
for each sample at index i in a batch will be used as initial
state for the sample of index i in the following batch.</li>
</ul>
<hr />
<p><span style="float:right;"><a href="https://github.com/keras-team/keras/blob/master/keras/layers/cudnn_recurrent.py#L328">[source]</a></span></p>
<h3 id="cudnnlstm">CuDNNLSTM</h3>
<pre><code class="python">keras.layers.CuDNNLSTM(units, kernel_initializer='glorot_uniform', recurrent_initializer='orthogonal', bias_initializer='zeros', unit_forget_bias=True, kernel_regularizer=None, recurrent_regularizer=None, bias_regularizer=None, activity_regularizer=None, kernel_constraint=None, recurrent_constraint=None, bias_constraint=None, return_sequences=False, return_state=False, stateful=False)
</code></pre>
<p>Fast LSTM implementation with <a href="https://developer.nvidia.com/cudnn">CuDNN</a>.</p>
<p>Can only be run on GPU, with the TensorFlow backend.</p>
<p><strong>Arguments</strong></p>
<ul>
<li><strong>units</strong>: Positive integer, dimensionality of the output space.</li>
<li><strong>kernel_initializer</strong>: Initializer for the <code>kernel</code> weights matrix,
used for the linear transformation of the inputs.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>recurrent_initializer</strong>: Initializer for the <code>recurrent_kernel</code>
weights matrix,
used for the linear transformation of the recurrent state.
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>bias_initializer</strong>: Initializer for the bias vector
(see <a href="../../initializers/">initializers</a>).</li>
<li><strong>unit_forget_bias</strong>: Boolean.
If True, add 1 to the bias of the forget gate at initialization.
Setting it to true will also force <code>bias_initializer="zeros"</code>.
This is recommended in <a href="http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf">Jozefowicz et al. (2015)</a>.</li>
<li><strong>kernel_regularizer</strong>: Regularizer function applied to
the <code>kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>recurrent_regularizer</strong>: Regularizer function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>bias_regularizer</strong>: Regularizer function applied to the bias vector
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>activity_regularizer</strong>: Regularizer function applied to
the output of the layer (its "activation").
(see <a href="../../regularizers/">regularizer</a>).</li>
<li><strong>kernel_constraint</strong>: Constraint function applied to
the <code>kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>recurrent_constraint</strong>: Constraint function applied to
the <code>recurrent_kernel</code> weights matrix
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>bias_constraint</strong>: Constraint function applied to the bias vector
(see <a href="../../constraints/">constraints</a>).</li>
<li><strong>return_sequences</strong>: Boolean. Whether to return the last output.
in the output sequence, or the full sequence.</li>
<li><strong>return_state</strong>: Boolean. Whether to return the last state
in addition to the output.</li>
<li><strong>stateful</strong>: Boolean (default False). If True, the last state
for each sample at index i in a batch will be used as initial
state for the sample of index i in the following batch.</li>
</ul>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="../embeddings/" class="btn btn-neutral float-right" title="Embedding Layers">Next <span class="icon icon-circle-arrow-right"></span></a>
<a href="../local/" class="btn btn-neutral" title="Locally-connected Layers"><span class="icon icon-circle-arrow-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<!-- Copyright etc -->
</div>
Built with <a href="https://www.mkdocs.org/">MkDocs</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<div class="rst-versions" role="note" aria-label="versions">
<span class="rst-current-version" data-toggle="rst-current-version">
<a href="http://github.com/keras-team/keras/" class="fa fa-github" style="float: left; color: #fcfcfc"> GitHub</a>
<span><a href="../local/" style="color: #fcfcfc;">« Previous</a></span>
<span style="margin-left: 15px"><a href="../embeddings/" style="color: #fcfcfc">Next »</a></span>
</span>
</div>
<script>var base_url = '../..';</script>
<script src="../../js/theme.js" defer></script>
<script src="../../search/main.js" defer></script>
<script type="text/javascript" defer>
window.onload = function () {
SphinxRtdTheme.Navigation.enable(true);
};
</script>
</body>
</html>
|