keras-metadata.json 246 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567
  1. [
  2. {
  3. "name": "Activation",
  4. "module": "tensorflow.keras.layers",
  5. "description": "Applies an activation function to an output.",
  6. "attributes": [
  7. {
  8. "description": "Activation function, such as `tf.nn.relu`, or string name of\n built-in activation function, such as \"relu\".",
  9. "name": "activation"
  10. }
  11. ],
  12. "inputs": [
  13. {
  14. "description": "Arbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the batch axis)\nwhen using this layer as the first layer in a model.",
  15. "name": "input"
  16. }
  17. ],
  18. "outputs": [
  19. {
  20. "description": "Same shape as input.",
  21. "name": "output"
  22. }
  23. ],
  24. "examples": [
  25. {
  26. "code": ">>> layer = tf.keras.layers.Activation('relu')\n>>> output = layer([-3.0, -1.0, 0.0, 2.0])\n>>> list(output.numpy())\n[0.0, 0.0, 0.0, 2.0]\n>>> layer = tf.keras.layers.Activation(tf.nn.relu)\n>>> output = layer([-3.0, -1.0, 0.0, 2.0])\n>>> list(output.numpy())\n[0.0, 0.0, 0.0, 2.0]"
  27. }
  28. ]
  29. },
  30. {
  31. "name": "ActivityRegularization",
  32. "module": "tensorflow.keras.layers",
  33. "description": "Layer that applies an update to the cost function based input activity.",
  34. "attributes": [
  35. {
  36. "description": "L1 regularization factor (positive float).",
  37. "name": "l1"
  38. },
  39. {
  40. "description": "L2 regularization factor (positive float).",
  41. "name": "l2"
  42. }
  43. ],
  44. "inputs": [
  45. {
  46. "description": "Arbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the samples axis)\nwhen using this layer as the first layer in a model.",
  47. "name": "input"
  48. }
  49. ],
  50. "outputs": [
  51. {
  52. "description": "Same shape as input.",
  53. "name": "output"
  54. }
  55. ]
  56. },
  57. {
  58. "name": "Add",
  59. "module": "tensorflow.keras.layers",
  60. "description": "Layer that adds a list of inputs.\n\nIt takes as input a list of tensors,\nall of the same shape, and returns\na single tensor (also of the same shape).",
  61. "inputs": [
  62. {
  63. "name": "inputs",
  64. "list": true
  65. }
  66. ],
  67. "outputs": [
  68. {
  69. "name": "output"
  70. }
  71. ],
  72. "examples": [
  73. {
  74. "code": ">>> input_shape = (2, 3, 4)\n>>> x1 = tf.random.normal(input_shape)\n>>> x2 = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Add()([x1, x2])\n>>> print(y.shape)\n(2, 3, 4)"
  75. },
  76. {
  77. "summary": "Used in a functional model:",
  78. "code": ">>> input1 = tf.keras.layers.Input(shape=(16,))\n>>> x1 = tf.keras.layers.Dense(8, activation='relu')(input1)\n>>> input2 = tf.keras.layers.Input(shape=(32,))\n>>> x2 = tf.keras.layers.Dense(8, activation='relu')(input2)\n>>> # equivalent to `added = tf.keras.layers.add([x1, x2])`\n>>> added = tf.keras.layers.Add()([x1, x2])\n>>> out = tf.keras.layers.Dense(4)(added)\n>>> model = tf.keras.models.Model(inputs=[input1, input2], outputs=out)"
  79. }
  80. ]
  81. },
  82. {
  83. "name": "Attention",
  84. "module": "tensorflow.keras.layers",
  85. "description": "Dot-product attention layer, a.k.a. Luong-style attention.\n\nInputs are `query` tensor of shape `[batch_size, Tq, dim]`, `value` tensor\nof shape `[batch_size, Tv, dim]` and `key` tensor of shape\n`[batch_size, Tv, dim]`. The calculation follows the steps:\n\n1. Calculate scores with shape `[batch_size, Tq, Tv]` as a `query`-`key` dot\n product: `scores = tf.matmul(query, key, transpose_b=True)`.\n2. Use scores to calculate a distribution with shape\n `[batch_size, Tq, Tv]`: `distribution = tf.nn.softmax(scores)`.\n3. Use `distribution` to create a linear combination of `value` with\n shape `[batch_size, Tq, dim]`:\n `return tf.matmul(distribution, value)`.",
  86. "attributes": [
  87. {
  88. "description": "If `True`, will create a scalar variable to scale the attention\n scores.",
  89. "name": "use_scale"
  90. },
  91. {
  92. "description": "Boolean. Set to `True` for decoder self-attention. Adds a mask\n such that position `i` cannot attend to positions `j > i`. This prevents\n the flow of information from the future towards the past. Defaults to\n `False`.",
  93. "name": "causal"
  94. },
  95. {
  96. "description": "Float between 0 and 1. Fraction of the units to drop for the\n attention scores. Defaults to 0.0.",
  97. "name": "dropout"
  98. },
  99. {
  100. "description": "List of the following tensors:\n * query: Query `Tensor` of shape `[batch_size, Tq, dim]`.\n * value: Value `Tensor` of shape `[batch_size, Tv, dim]`.\n * key: Optional key `Tensor` of shape `[batch_size, Tv, dim]`. If not\n given, will use `value` for both `key` and `value`, which is the\n most common case.",
  101. "name": "inputs"
  102. },
  103. {
  104. "description": "List of the following tensors:\n * query_mask: A boolean mask `Tensor` of shape `[batch_size, Tq]`.\n If given, the output will be zero at the positions where\n `mask==False`.\n * value_mask: A boolean mask `Tensor` of shape `[batch_size, Tv]`.\n If given, will apply the mask such that values at positions where\n `mask==False` do not contribute to the result.",
  105. "name": "mask"
  106. },
  107. {
  108. "description": "bool, it `True`, returns the attention scores\n (after masking and softmax) as an additional output argument.",
  109. "name": "return_attention_scores"
  110. },
  111. {
  112. "description": "Python boolean indicating whether the layer should behave in\n training mode (adding dropout) or in inference mode (no dropout).",
  113. "name": "training"
  114. },
  115. {
  116. "name": "score_mode",
  117. "description": "Function to use to compute attention scores, one of\n `{\"dot\", \"concat\"}`. `\"dot\"` refers to the dot product between the query\n and key vectors. `\"concat\"` refers to the hyperbolic tangent of the\n concatenation of the query and key vectors.\n\nCall Args:"
  118. },
  119. {
  120. "name": "use_causal_mask",
  121. "description": "Boolean. Set to `True` for decoder self-attention. Adds a\n mask such that position `i` cannot attend to positions `j > i`. This\n prevents the flow of information from the future towards the past.\n Defaults to `False`.\n\nOutput:\n\n Attention outputs of shape `[batch_size, Tq, dim]`.\n [Optional] Attention scores after masking and softmax with shape\n `[batch_size, Tq, Tv]`.\n\nThe meaning of `query`, `value` and `key` depend on the application. In the\ncase of text similarity, for example, `query` is the sequence embeddings of\nthe first piece of text and `value` is the sequence embeddings of the second\npiece of text. `key` is usually the same tensor as `value`.\n\nHere is a code example for using `Attention` in a CNN+Attention network:\n\n```python\n# Variable-length int sequences.\nquery_input = tf.keras.Input(shape=(None,), dtype='int32')\nvalue_input = tf.keras.Input(shape=(None,), dtype='int32')\n\n# Embedding lookup.\ntoken_embedding = tf.keras.layers.Embedding(input_dim=1000, output_dim=64)\n# Query embeddings of shape [batch_size, Tq, dimension].\nquery_embeddings = token_embedding(query_input)\n# Value embeddings of shape [batch_size, Tv, dimension].\nvalue_embeddings = token_embedding(value_input)\n\n# CNN layer.\ncnn_layer = tf.keras.layers.Conv1D(\n filters=100,\n kernel_size=4,\n # Use 'same' padding so outputs have the same shape as inputs.\n padding='same')\n# Query encoding of shape [batch_size, Tq, filters].\nquery_seq_encoding = cnn_layer(query_embeddings)\n# Value encoding of shape [batch_size, Tv, filters].\nvalue_seq_encoding = cnn_layer(value_embeddings)\n\n# Query-value attention of shape [batch_size, Tq, filters].\nquery_value_attention_seq = tf.keras.layers.Attention()(\n [query_seq_encoding, value_seq_encoding])\n\n# Reduce over the sequence axis to produce encodings of shape\n# [batch_size, filters].\nquery_encoding = tf.keras.layers.GlobalAveragePooling1D()(\n query_seq_encoding)\nquery_value_attention = tf.keras.layers.GlobalAveragePooling1D()(\n query_value_attention_seq)\n\n# Concatenate query and document encodings to produce a DNN input layer.\ninput_layer = tf.keras.layers.Concatenate()(\n [query_encoding, query_value_attention])\n\n# Add DNN layers, and create Model.\n# ...\n```"
  122. }
  123. ]
  124. },
  125. {
  126. "name": "Average",
  127. "module": "tensorflow.keras.layers",
  128. "category": "Tensor",
  129. "description": "Layer that averages a list of inputs element-wise.\n\nIt takes as input a list of tensors, all of the same shape, and returns\na single tensor (also of the same shape).",
  130. "inputs": [
  131. {
  132. "name": "inputs",
  133. "list": true
  134. }
  135. ],
  136. "outputs": [
  137. {
  138. "name": "output"
  139. }
  140. ],
  141. "examples": [
  142. {
  143. "code": ">>> x1 = np.ones((2, 2))\n>>> x2 = np.zeros((2, 2))\n>>> y = tf.keras.layers.Average()([x1, x2])\n>>> y.numpy().tolist()\n[[0.5, 0.5], [0.5, 0.5]]"
  144. },
  145. {
  146. "summary": "Usage in a functional model:",
  147. "code": ">>> input1 = tf.keras.layers.Input(shape=(16,))\n>>> x1 = tf.keras.layers.Dense(8, activation='relu')(input1)\n>>> input2 = tf.keras.layers.Input(shape=(32,))\n>>> x2 = tf.keras.layers.Dense(8, activation='relu')(input2)\n>>> avg = tf.keras.layers.Average()([x1, x2])\n>>> out = tf.keras.layers.Dense(4)(avg)\n>>> model = tf.keras.models.Model(inputs=[input1, input2], outputs=out)"
  148. }
  149. ]
  150. },
  151. {
  152. "name": "AveragePooling1D",
  153. "module": "tensorflow.keras.layers",
  154. "category": "Pool",
  155. "description": "Average pooling for temporal data.\n\nDownsamples the input representation by taking the average value over the\nwindow defined by `pool_size`. The window is shifted by `strides`. The\nresulting output when using \"valid\" padding option has a shape of:\n`output_shape = (input_shape - pool_size + 1) / strides)`\n\nThe resulting output shape when using the \"same\" padding option is:\n`output_shape = input_shape / strides`\n\nFor example, for strides=1 and padding=\"valid\":\n\n```\n>>> x = tf.constant([1., 2., 3., 4., 5.])\n>>> x = tf.reshape(x, [1, 5, 1])\n>>> x\n<tf.Tensor: shape=(1, 5, 1), dtype=float32, numpy=\n array([[[1.],\n [2.],\n [3.],\n [4.],\n [5.]], dtype=float32)>\n>>> avg_pool_1d = tf.keras.layers.AveragePooling1D(pool_size=2,\n... strides=1, padding='valid')\n>>> avg_pool_1d(x)\n<tf.Tensor: shape=(1, 4, 1), dtype=float32, numpy=\narray([[[1.5],\n [2.5],\n [3.5],\n [4.5]]], dtype=float32)>\n```\n\nFor example, for strides=2 and padding=\"valid\":\n\n```\n>>> x = tf.constant([1., 2., 3., 4., 5.])\n>>> x = tf.reshape(x, [1, 5, 1])\n>>> x\n<tf.Tensor: shape=(1, 5, 1), dtype=float32, numpy=\n array([[[1.],\n [2.],\n [3.],\n [4.],\n [5.]], dtype=float32)>\n>>> avg_pool_1d = tf.keras.layers.AveragePooling1D(pool_size=2,\n... strides=2, padding='valid')\n>>> avg_pool_1d(x)\n<tf.Tensor: shape=(1, 2, 1), dtype=float32, numpy=\narray([[[1.5],\n [3.5]]], dtype=float32)>\n```\n\nFor example, for strides=1 and padding=\"same\":\n\n```\n>>> x = tf.constant([1., 2., 3., 4., 5.])\n>>> x = tf.reshape(x, [1, 5, 1])\n>>> x\n<tf.Tensor: shape=(1, 5, 1), dtype=float32, numpy=\n array([[[1.],\n [2.],\n [3.],\n [4.],\n [5.]], dtype=float32)>\n>>> avg_pool_1d = tf.keras.layers.AveragePooling1D(pool_size=2,\n... strides=1, padding='same')\n>>> avg_pool_1d(x)\n<tf.Tensor: shape=(1, 5, 1), dtype=float32, numpy=\narray([[[1.5],\n [2.5],\n [3.5],\n [4.5],\n [5.]]], dtype=float32)>\n```",
  156. "attributes": [
  157. {
  158. "description": "Integer, size of the average pooling windows.",
  159. "name": "pool_size"
  160. },
  161. {
  162. "description": "Integer, or None. Factor by which to downscale.\n E.g. 2 will halve the input.\n If None, it will default to `pool_size`.",
  163. "name": "strides"
  164. },
  165. {
  166. "description": "One of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding evenly to\n the left/right or up/down of the input such that output has the same\n height/width dimension as the input.",
  167. "name": "padding"
  168. },
  169. {
  170. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, steps, features)` while `channels_first`\n corresponds to inputs with shape\n `(batch, features, steps)`.",
  171. "name": "data_format"
  172. }
  173. ],
  174. "inputs": [
  175. {
  176. "description": "- If `data_format='channels_last'`:\n 3D tensor with shape `(batch_size, steps, features)`.\n- If `data_format='channels_first'`:\n 3D tensor with shape `(batch_size, features, steps)`.",
  177. "name": "input"
  178. }
  179. ],
  180. "outputs": [
  181. {
  182. "description": "- If `data_format='channels_last'`:\n 3D tensor with shape `(batch_size, downsampled_steps, features)`.\n- If `data_format='channels_first'`:\n 3D tensor with shape `(batch_size, features, downsampled_steps)`.",
  183. "name": "output"
  184. }
  185. ]
  186. },
  187. {
  188. "name": "AveragePooling2D",
  189. "module": "tensorflow.keras.layers",
  190. "category": "Pool",
  191. "description": "Average pooling operation for spatial data.\n\nDownsamples the input along its spatial dimensions (height and width)\nby taking the average value over an input window\n(of size defined by `pool_size`) for each channel of the input.\nThe window is shifted by `strides` along each dimension.\n\nThe resulting output when using `\"valid\"` padding option has a shape\n(number of rows or columns) of:\n`output_shape = math.floor((input_shape - pool_size) / strides) + 1`\n(when `input_shape >= pool_size`)\n\nThe resulting output shape when using the `\"same\"` padding option is:\n`output_shape = math.floor((input_shape - 1) / strides) + 1`\n\nFor example, for `strides=(1, 1)` and `padding=\"valid\"`:\n\n```\n>>> x = tf.constant([[1., 2., 3.],\n... [4., 5., 6.],\n... [7., 8., 9.]])\n>>> x = tf.reshape(x, [1, 3, 3, 1])\n>>> avg_pool_2d = tf.keras.layers.AveragePooling2D(pool_size=(2, 2),\n... strides=(1, 1), padding='valid')\n>>> avg_pool_2d(x)\n<tf.Tensor: shape=(1, 2, 2, 1), dtype=float32, numpy=\n array([[[[3.],\n [4.]],\n [[6.],\n [7.]]]], dtype=float32)>\n```\n\nFor example, for `stride=(2, 2)` and `padding=\"valid\"`:\n\n```\n>>> x = tf.constant([[1., 2., 3., 4.],\n... [5., 6., 7., 8.],\n... [9., 10., 11., 12.]])\n>>> x = tf.reshape(x, [1, 3, 4, 1])\n>>> avg_pool_2d = tf.keras.layers.AveragePooling2D(pool_size=(2, 2),\n... strides=(2, 2), padding='valid')\n>>> avg_pool_2d(x)\n<tf.Tensor: shape=(1, 1, 2, 1), dtype=float32, numpy=\n array([[[[3.5],\n [5.5]]]], dtype=float32)>\n```\n\nFor example, for `strides=(1, 1)` and `padding=\"same\"`:\n\n```\n>>> x = tf.constant([[1., 2., 3.],\n... [4., 5., 6.],\n... [7., 8., 9.]])\n>>> x = tf.reshape(x, [1, 3, 3, 1])\n>>> avg_pool_2d = tf.keras.layers.AveragePooling2D(pool_size=(2, 2),\n... strides=(1, 1), padding='same')\n>>> avg_pool_2d(x)\n<tf.Tensor: shape=(1, 3, 3, 1), dtype=float32, numpy=\n array([[[[3.],\n [4.],\n [4.5]],\n [[6.],\n [7.],\n [7.5]],\n [[7.5],\n [8.5],\n [9.]]]], dtype=float32)>\n```",
  192. "attributes": [
  193. {
  194. "default": "channels_last",
  195. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, height, width, channels)` while `channels_first`\n corresponds to inputs with shape\n `(batch, channels, height, width)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  196. "name": "data_format"
  197. },
  198. {
  199. "description": "integer or tuple of 2 integers,\n factors by which to downscale (vertical, horizontal).\n `(2, 2)` will halve the input in both spatial dimension.\n If only one integer is specified, the same window length\n will be used for both dimensions.",
  200. "name": "pool_size"
  201. },
  202. {
  203. "description": "Integer, tuple of 2 integers, or None.\n Strides values.\n If None, it will default to `pool_size`.",
  204. "name": "strides"
  205. },
  206. {
  207. "description": "One of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding evenly to\n the left/right or up/down of the input such that output has the same\n height/width dimension as the input.",
  208. "name": "padding"
  209. }
  210. ],
  211. "inputs": [
  212. {
  213. "description": "- If `data_format='channels_last'`:\n 4D tensor with shape `(batch_size, rows, cols, channels)`.\n- If `data_format='channels_first'`:\n 4D tensor with shape `(batch_size, channels, rows, cols)`.",
  214. "name": "input"
  215. }
  216. ],
  217. "outputs": [
  218. {
  219. "description": "- If `data_format='channels_last'`:\n 4D tensor with shape `(batch_size, pooled_rows, pooled_cols, channels)`.\n- If `data_format='channels_first'`:\n 4D tensor with shape `(batch_size, channels, pooled_rows, pooled_cols)`.",
  220. "name": "output"
  221. }
  222. ]
  223. },
  224. {
  225. "name": "AveragePooling3D",
  226. "module": "tensorflow.keras.layers",
  227. "description": "Average pooling operation for 3D data (spatial or spatio-temporal).\n\nDownsamples the input along its spatial dimensions (depth, height, and\nwidth) by taking the average value over an input window\n(of size defined by `pool_size`) for each channel of the input.\nThe window is shifted by `strides` along each dimension.",
  228. "attributes": [
  229. {
  230. "description": "tuple of 3 integers,\n factors by which to downscale (dim1, dim2, dim3).\n `(2, 2, 2)` will halve the size of the 3D input in each dimension.",
  231. "name": "pool_size"
  232. },
  233. {
  234. "description": "tuple of 3 integers, or None. Strides values.",
  235. "name": "strides"
  236. },
  237. {
  238. "description": "One of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding evenly to\n the left/right or up/down of the input such that output has the same\n height/width dimension as the input.",
  239. "name": "padding"
  240. },
  241. {
  242. "default": "channels_last",
  243. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)`\n while `channels_first` corresponds to inputs with shape\n `(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  244. "name": "data_format"
  245. }
  246. ],
  247. "inputs": [
  248. {
  249. "description": "- If `data_format='channels_last'`:\n 5D tensor with shape:\n `(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)`\n- If `data_format='channels_first'`:\n 5D tensor with shape:\n `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)`",
  250. "name": "input"
  251. }
  252. ],
  253. "outputs": [
  254. {
  255. "description": "- If `data_format='channels_last'`:\n 5D tensor with shape:\n `(batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels)`\n- If `data_format='channels_first'`:\n 5D tensor with shape:\n `(batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3)`",
  256. "name": "output"
  257. }
  258. ],
  259. "examples": [
  260. {
  261. "code": "depth = 30\nheight = 30\nwidth = 30\ninput_channels = 3\n\ninputs = tf.keras.Input(shape=(depth, height, width, input_channels))\nlayer = tf.keras.layers.AveragePooling3D(pool_size=3)\noutputs = layer(inputs) # Shape: (batch_size, 10, 10, 10, 3)"
  262. }
  263. ]
  264. },
  265. {
  266. "name": "BatchNorm",
  267. "category": "Normalization",
  268. "attributes": [
  269. {
  270. "default": -1,
  271. "name": "axis"
  272. },
  273. {
  274. "default": 0.001,
  275. "name": "epsilon"
  276. },
  277. {
  278. "default": 0.99,
  279. "name": "momentum"
  280. },
  281. {
  282. "default": true,
  283. "name": "scale"
  284. },
  285. {
  286. "default": true,
  287. "name": "center"
  288. },
  289. {
  290. "default": {
  291. "class_name": "Ones",
  292. "config": {}
  293. },
  294. "name": "gamma_initializer",
  295. "visible": false
  296. },
  297. {
  298. "default": {
  299. "class_name": "Zeros",
  300. "config": {}
  301. },
  302. "name": "moving_mean_initializer",
  303. "visible": false
  304. },
  305. {
  306. "default": {
  307. "class_name": "Ones",
  308. "config": {}
  309. },
  310. "name": "moving_variance_initializer",
  311. "visible": false
  312. },
  313. {
  314. "default": {
  315. "class_name": "Zeros",
  316. "config": {}
  317. },
  318. "name": "beta_initializer",
  319. "visible": false
  320. },
  321. {
  322. "name": "beta_regularizer",
  323. "visible": false
  324. },
  325. {
  326. "name": "gamma_regularizer",
  327. "visible": false
  328. },
  329. {
  330. "name": "beta_constraint"
  331. },
  332. {
  333. "name": "gamma_constraint"
  334. }
  335. ],
  336. "inputs": [
  337. {
  338. "name": "input"
  339. },
  340. {
  341. "name": "gamma"
  342. },
  343. {
  344. "name": "beta"
  345. },
  346. {
  347. "name": "running_mean"
  348. },
  349. {
  350. "name": "running_std"
  351. }
  352. ],
  353. "outputs": [
  354. {
  355. "name": "output"
  356. }
  357. ]
  358. },
  359. {
  360. "name": "BatchNormalization",
  361. "module": "tensorflow.keras.layers",
  362. "category": "Normalization",
  363. "description": "Layer that normalizes its inputs.\n\nBatch normalization applies a transformation that maintains the mean output\nclose to 0 and the output standard deviation close to 1.\n\nImportantly, batch normalization works differently during training and\nduring inference.\n\n**During training** (i.e. when using `fit()` or when calling the layer/model\nwith the argument `training=True`), the layer normalizes its output using\nthe mean and standard deviation of the current batch of inputs. That is to\nsay, for each channel being normalized, the layer returns\n`gamma * (batch - mean(batch)) / sqrt(var(batch) + epsilon) + beta`, where:\n\n- `epsilon` is small constant (configurable as part of the constructor\narguments)\n- `gamma` is a learned scaling factor (initialized as 1), which\ncan be disabled by passing `scale=False` to the constructor.\n- `beta` is a learned offset factor (initialized as 0), which\ncan be disabled by passing `center=False` to the constructor.\n\n**During inference** (i.e. when using `evaluate()` or `predict()` or when\ncalling the layer/model with the argument `training=False` (which is the\ndefault), the layer normalizes its output using a moving average of the\nmean and standard deviation of the batches it has seen during training. That\nis to say, it returns\n`gamma * (batch - self.moving_mean) / sqrt(self.moving_var+epsilon) + beta`.\n\n`self.moving_mean` and `self.moving_var` are non-trainable variables that\nare updated each time the layer in called in training mode, as such:\n\n- `moving_mean = moving_mean * momentum + mean(batch) * (1 - momentum)`\n- `moving_var = moving_var * momentum + var(batch) * (1 - momentum)`\n\nAs such, the layer will only normalize its inputs during inference\n*after having been trained on data that has similar statistics as the\ninference data*.",
  364. "attributes": [
  365. {
  366. "default": -1,
  367. "description": "Integer, the axis that should be normalized (typically the features\n axis). For instance, after a `Conv2D` layer with\n `data_format=\"channels_first\"`, set `axis=1` in `BatchNormalization`.",
  368. "name": "axis"
  369. },
  370. {
  371. "default": 0.001,
  372. "description": "Small float added to variance to avoid dividing by zero.",
  373. "name": "epsilon"
  374. },
  375. {
  376. "default": 0.99,
  377. "description": "Momentum for the moving average.",
  378. "name": "momentum"
  379. },
  380. {
  381. "default": true,
  382. "description": "If True, multiply by `gamma`. If False, `gamma` is not used. When\n the next layer is linear (also e.g. `nn.relu`), this can be disabled\n since the scaling will be done by the next layer.",
  383. "name": "scale",
  384. "type": "boolean"
  385. },
  386. {
  387. "default": true,
  388. "description": "If True, add offset of `beta` to normalized tensor. If False,\n `beta` is ignored.",
  389. "name": "center",
  390. "type": "boolean"
  391. },
  392. {
  393. "default": {
  394. "class_name": "Ones",
  395. "config": {}
  396. },
  397. "description": "Initializer for the gamma weight.",
  398. "name": "gamma_initializer",
  399. "visible": false
  400. },
  401. {
  402. "default": {
  403. "class_name": "Zeros",
  404. "config": {}
  405. },
  406. "description": "Initializer for the moving mean.",
  407. "name": "moving_mean_initializer",
  408. "visible": false
  409. },
  410. {
  411. "default": {
  412. "class_name": "Ones",
  413. "config": {}
  414. },
  415. "description": "Initializer for the moving variance.",
  416. "name": "moving_variance_initializer",
  417. "visible": false
  418. },
  419. {
  420. "default": {
  421. "class_name": "Zeros",
  422. "config": {}
  423. },
  424. "description": "Initializer for the beta weight.",
  425. "name": "beta_initializer",
  426. "visible": false
  427. },
  428. {
  429. "description": "Optional regularizer for the beta weight.",
  430. "name": "beta_regularizer",
  431. "visible": false
  432. },
  433. {
  434. "description": "Optional regularizer for the gamma weight.",
  435. "name": "gamma_regularizer",
  436. "visible": false
  437. },
  438. {
  439. "description": "Optional constraint for the beta weight.",
  440. "name": "beta_constraint"
  441. },
  442. {
  443. "description": "Optional constraint for the gamma weight.",
  444. "name": "gamma_constraint"
  445. },
  446. {
  447. "description": "Whether to use [Batch Renormalization](\n https://arxiv.org/abs/1702.03275). This adds extra variables during\n training. The inference is the same for either value of this parameter.",
  448. "name": "renorm"
  449. },
  450. {
  451. "description": "A dictionary that may map keys 'rmax', 'rmin', 'dmax' to\n scalar `Tensors` used to clip the renorm correction. The correction `(r,\n d)` is used as `corrected_value = normalized_value * r + d`, with `r`\n clipped to [rmin, rmax], and `d` to [-dmax, dmax]. Missing rmax, rmin,\n dmax are set to inf, 0, inf, respectively.",
  452. "name": "renorm_clipping"
  453. },
  454. {
  455. "description": "Momentum used to update the moving means and standard\n deviations with renorm. Unlike `momentum`, this affects training and\n should be neither too small (which would add noise) nor too large (which\n would give stale estimates). Note that `momentum` is still applied to get\n the means and variances for inference.",
  456. "name": "renorm_momentum"
  457. },
  458. {
  459. "description": "if `True`, use a faster, fused implementation, or raise a ValueError\n if the fused implementation cannot be used. If `None`, use the faster\n implementation if possible. If False, do not used the fused\n implementation.",
  460. "name": "fused"
  461. },
  462. {
  463. "description": "Boolean, if `True` the variables will be marked as trainable.",
  464. "name": "trainable"
  465. },
  466. {
  467. "description": "An `int`. By default, `virtual_batch_size` is `None`,\n which means batch normalization is performed across the whole batch. When\n `virtual_batch_size` is not `None`, instead perform \"Ghost Batch\n Normalization\", which creates virtual sub-batches which are each\n normalized separately (with shared gamma, beta, and moving statistics).\n Must divide the actual batch size during execution.",
  468. "name": "virtual_batch_size"
  469. },
  470. {
  471. "description": "A function taking the `Tensor` containing the (dynamic) shape of\n the input tensor and returning a pair (scale, bias) to apply to the\n normalized values (before gamma and beta), only during training. For\n example, if axis==-1,\n `adjustment = lambda shape: (\n tf.random.uniform(shape[-1:], 0.93, 1.07),\n tf.random.uniform(shape[-1:], -0.1, 0.1))` will scale the normalized\n value by up to 7% up or down, then shift the result by up to 0.1\n (with independent scaling and bias for each feature but shared\n across all examples), and finally apply gamma and/or beta. If\n `None`, no adjustment is applied. Cannot be specified if\n virtual_batch_size is specified.",
  472. "name": "adjustment"
  473. }
  474. ],
  475. "inputs": [
  476. {
  477. "description": "Arbitrary. Use the keyword argument `input_shape` (tuple of\nintegers, does not include the samples axis) when using this layer as the\nfirst layer in a model.",
  478. "name": "input"
  479. },
  480. {
  481. "name": "gamma"
  482. },
  483. {
  484. "name": "beta"
  485. },
  486. {
  487. "name": "moving_mean"
  488. },
  489. {
  490. "name": "moving_variance"
  491. }
  492. ],
  493. "outputs": [
  494. {
  495. "description": "Same shape as input.\n\nReference:\n - [Ioffe and Szegedy, 2015](https://arxiv.org/abs/1502.03167).\n\n**About setting `layer.trainable = False` on a `BatchNormalization` layer:**\n\nThe meaning of setting `layer.trainable = False` is to freeze the layer,\ni.e. its internal state will not change during training:\nits trainable weights will not be updated\nduring `fit()` or `train_on_batch()`, and its state updates will not be run.\n\nUsually, this does not necessarily mean that the layer is run in inference\nmode (which is normally controlled by the `training` argument that can\nbe passed when calling a layer). \"Frozen state\" and \"inference mode\"\nare two separate concepts.\n\nHowever, in the case of the `BatchNormalization` layer, **setting\n`trainable = False` on the layer means that the layer will be\nsubsequently run in inference mode** (meaning that it will use\nthe moving mean and the moving variance to normalize the current batch,\nrather than using the mean and variance of the current batch).\n\nThis behavior has been introduced in TensorFlow 2.0, in order\nto enable `layer.trainable = False` to produce the most commonly\nexpected behavior in the convnet fine-tuning use case.\n\nNote that:\n - Setting `trainable` on an model containing other layers will\n recursively set the `trainable` value of all inner layers.\n - If the value of the `trainable`\n attribute is changed after calling `compile()` on a model,\n the new value doesn't take effect for this model\n until `compile()` is called again.",
  496. "name": "output"
  497. }
  498. ],
  499. "references": [
  500. {
  501. "description": "[Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift](https://arxiv.org/abs/1502.03167)"
  502. }
  503. ]
  504. },
  505. {
  506. "name": "Bidirectional",
  507. "module": "tensorflow.keras.layers",
  508. "category": "Wrapper",
  509. "description": "Bidirectional wrapper for RNNs.",
  510. "attributes": [
  511. {
  512. "default": "concat",
  513. "description": "Mode by which outputs of the forward and backward RNNs will be\n combined. One of {'sum', 'mul', 'concat', 'ave', None}. If None, the\n outputs will not be combined, they will be returned as a list. Default\n value is 'concat'.",
  514. "name": "merge_mode"
  515. },
  516. {
  517. "description": "`keras.layers.RNN` instance, such as `keras.layers.LSTM` or\n `keras.layers.GRU`. It could also be a `keras.layers.Layer` instance\n that meets the following criteria:\n 1. Be a sequence-processing layer (accepts 3D+ inputs).\n 2. Have a `go_backwards`, `return_sequences` and `return_state`\n attribute (with the same semantics as for the `RNN` class).\n 3. Have an `input_spec` attribute.\n 4. Implement serialization via `get_config()` and `from_config()`.\n Note that the recommended way to create new RNN layers is to write a\n custom RNN cell and use it with `keras.layers.RNN`, instead of\n subclassing `keras.layers.Layer` directly.\n - When the `returns_sequences` is true, the output of the masked\n timestep will be zero regardless of the layer's original\n `zero_output_for_mask` value.",
  518. "name": "layer"
  519. },
  520. {
  521. "description": "Initial weights to load in the Bidirectional model\n",
  522. "name": "weights"
  523. },
  524. {
  525. "description": "Optional `keras.layers.RNN`, or `keras.layers.Layer`\n instance to be used to handle backwards input processing.\n If `backward_layer` is not provided, the layer instance passed as the\n `layer` argument will be used to generate the backward layer\n automatically.\n Note that the provided `backward_layer` layer should have properties\n matching those of the `layer` argument, in particular it should have the\n same values for `stateful`, `return_states`, `return_sequences`, etc.\n In addition, `backward_layer` and `layer` should have different\n `go_backwards` argument values.\n A `ValueError` will be raised if these requirements are not met.",
  526. "name": "backward_layer"
  527. }
  528. ],
  529. "inputs": [
  530. {
  531. "name": "input"
  532. }
  533. ],
  534. "outputs": [
  535. {
  536. "name": "output"
  537. }
  538. ],
  539. "examples": [
  540. {
  541. "code": "model = Sequential()\nmodel.add(Bidirectional(LSTM(10, return_sequences=True),\n input_shape=(5, 10)))\nmodel.add(Bidirectional(LSTM(10)))\nmodel.add(Dense(5))\nmodel.add(Activation('softmax'))\nmodel.compile(loss='categorical_crossentropy', optimizer='rmsprop')\n\n# With custom backward layer\nmodel = Sequential()\nforward_layer = LSTM(10, return_sequences=True)\nbackward_layer = LSTM(10, activation='relu', return_sequences=True,\n go_backwards=True)\nmodel.add(Bidirectional(forward_layer, backward_layer=backward_layer,\n input_shape=(5, 10)))\nmodel.add(Dense(5))\nmodel.add(Activation('softmax'))\nmodel.compile(loss='categorical_crossentropy', optimizer='rmsprop')"
  542. }
  543. ]
  544. },
  545. {
  546. "name": "Concatenate",
  547. "module": "tensorflow.keras.layers",
  548. "category": "Tensor",
  549. "description": "Layer that concatenates a list of inputs.\n\nIt takes as input a list of tensors, all of the same shape except\nfor the concatenation axis, and returns a single tensor that is the\nconcatenation of all inputs.\n\n```\n>>> x = np.arange(20).reshape(2, 2, 5)\n>>> print(x)\n[[[ 0 1 2 3 4]\n [ 5 6 7 8 9]]\n [[10 11 12 13 14]\n [15 16 17 18 19]]]\n>>> y = np.arange(20, 30).reshape(2, 1, 5)\n>>> print(y)\n[[[20 21 22 23 24]]\n [[25 26 27 28 29]]]\n>>> tf.keras.layers.Concatenate(axis=1)([x, y])\n<tf.Tensor: shape=(2, 3, 5), dtype=int64, numpy=\narray([[[ 0, 1, 2, 3, 4],\n [ 5, 6, 7, 8, 9],\n [20, 21, 22, 23, 24]],\n [[10, 11, 12, 13, 14],\n [15, 16, 17, 18, 19],\n [25, 26, 27, 28, 29]]])>\n```\n\n```\n>>> x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2))\n>>> x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))\n>>> concatted = tf.keras.layers.Concatenate()([x1, x2])\n>>> concatted.shape\nTensorShape([5, 16])\n```",
  550. "attributes": [
  551. {
  552. "description": "Axis along which to concatenate.",
  553. "name": "axis"
  554. },
  555. {
  556. "description": "standard layer keyword arguments.\n",
  557. "name": "**kwargs"
  558. }
  559. ],
  560. "inputs": [
  561. {
  562. "name": "inputs",
  563. "list": true
  564. }
  565. ],
  566. "outputs": [
  567. {
  568. "name": "output"
  569. }
  570. ]
  571. },
  572. {
  573. "name": "Conv1D",
  574. "module": "tensorflow.keras.layers",
  575. "category": "Layer",
  576. "description": "1D convolution layer (e.g. temporal convolution).\n\nThis layer creates a convolution kernel that is convolved\nwith the layer input over a single spatial (or temporal) dimension\nto produce a tensor of outputs.\nIf `use_bias` is True, a bias vector is created and added to the outputs.\nFinally, if `activation` is not `None`,\nit is applied to the outputs as well.\n\nWhen using this layer as the first layer in a model,\nprovide an `input_shape` argument\n(tuple of integers or `None`, e.g.\n`(10, 128)` for sequences of 10 vectors of 128-dimensional vectors,\nor `(None, 128)` for variable-length sequences of 128-dimensional vectors.",
  577. "attributes": [
  578. {
  579. "default": "linear",
  580. "description": "Activation function to use.\n If you don't specify anything, no activation is applied\n (see `keras.activations`).",
  581. "name": "activation"
  582. },
  583. {
  584. "default": "valid",
  585. "description": "One of `\"valid\"`, `\"same\"` or `\"causal\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding with zeros\n evenly to the left/right or up/down of the input such that output has\n the same height/width dimension as the input.\n `\"causal\"` results in causal (dilated) convolutions, e.g. `output[t]`\n does not depend on `input[t+1:]`. Useful when modeling temporal data\n where the model should not violate the temporal order.\n See [WaveNet: A Generative Model for Raw Audio, section\n 2.1](https://arxiv.org/abs/1609.03499).",
  586. "name": "padding"
  587. },
  588. {
  589. "default": true,
  590. "description": "Boolean, whether the layer uses a bias vector.",
  591. "name": "use_bias",
  592. "visible": false
  593. },
  594. {
  595. "default": "channels_last",
  596. "description": "A string,\n one of `channels_last` (default) or `channels_first`.",
  597. "name": "data_format"
  598. },
  599. {
  600. "default": [
  601. 1
  602. ],
  603. "description": "An integer or tuple/list of a single integer,\n specifying the stride length of the convolution.\n Specifying any stride value != 1 is incompatible with specifying\n any `dilation_rate` value != 1.",
  604. "name": "strides"
  605. },
  606. {
  607. "default": [
  608. 1
  609. ],
  610. "description": "an integer or tuple/list of a single integer, specifying\n the dilation rate to use for dilated convolution.\n Currently, specifying any `dilation_rate` value != 1 is\n incompatible with specifying any `strides` value != 1.",
  611. "name": "dilation_rate"
  612. },
  613. {
  614. "default": {
  615. "class_name": "Zeros",
  616. "config": {}
  617. },
  618. "description": "Initializer for the bias vector\n (see `keras.initializers`). Defaults to 'zeros'.",
  619. "name": "bias_initializer",
  620. "visible": false
  621. },
  622. {
  623. "default": {
  624. "class_name": "VarianceScaling",
  625. "config": {
  626. "distribution": "uniform",
  627. "mode": "fan_avg",
  628. "scale": 1,
  629. "seed": null
  630. }
  631. },
  632. "description": "Initializer for the `kernel` weights matrix\n (see `keras.initializers`). Defaults to 'glorot_uniform'.",
  633. "name": "kernel_initializer",
  634. "visible": false
  635. },
  636. {
  637. "description": "Integer, the dimensionality of the output space\n (i.e. the number of output filters in the convolution).",
  638. "name": "filters"
  639. },
  640. {
  641. "description": "An integer or tuple/list of a single integer,\n specifying the length of the 1D convolution window.",
  642. "name": "kernel_size"
  643. },
  644. {
  645. "description": "Regularizer function applied to\n the `kernel` weights matrix (see `keras.regularizers`).",
  646. "name": "kernel_regularizer",
  647. "visible": false
  648. },
  649. {
  650. "description": "Regularizer function applied to the bias vector\n (see `keras.regularizers`).",
  651. "name": "bias_regularizer",
  652. "visible": false
  653. },
  654. {
  655. "description": "Regularizer function applied to\n the output of the layer (its \"activation\")\n (see `keras.regularizers`).",
  656. "name": "activity_regularizer",
  657. "visible": false
  658. },
  659. {
  660. "description": "Constraint function applied to the kernel matrix\n (see `keras.constraints`).",
  661. "name": "kernel_constraint"
  662. },
  663. {
  664. "description": "Constraint function applied to the bias vector\n (see `keras.constraints`).",
  665. "name": "bias_constraint"
  666. },
  667. {
  668. "description": "A positive integer specifying the number of groups in which the\n input is split along the channel axis. Each group is convolved\n separately with `filters / groups` filters. The output is the\n concatenation of all the `groups` results along the channel axis.\n Input channels and `filters` must both be divisible by `groups`.",
  669. "name": "groups"
  670. }
  671. ],
  672. "inputs": [
  673. {
  674. "description": "3+D tensor with shape: `batch_shape + (steps, input_dim)`",
  675. "name": "input"
  676. },
  677. {
  678. "name": "kernel"
  679. },
  680. {
  681. "name": "bias"
  682. }
  683. ],
  684. "outputs": [
  685. {
  686. "description": "3+D tensor with shape: `batch_shape + (new_steps, filters)`\n `steps` value might have changed due to padding or strides.",
  687. "name": "output"
  688. }
  689. ],
  690. "examples": [
  691. {
  692. "code": ">>> # The inputs are 128-length vectors with 10 timesteps, and the\n>>> # batch size is 4.\n>>> input_shape = (4, 10, 128)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv1D(\n... 32, 3, activation='relu',input_shape=input_shape[1:])(x)\n>>> print(y.shape)\n(4, 8, 32)"
  693. },
  694. {
  695. "code": ">>> # With extended batch shape [4, 7] (e.g. weather data where batch\n>>> # dimensions correspond to spatial location and the third dimension\n>>> # corresponds to time.)\n>>> input_shape = (4, 7, 10, 128)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv1D(\n... 32, 3, activation='relu', input_shape=input_shape[2:])(x)\n>>> print(y.shape)\n(4, 7, 8, 32)"
  696. }
  697. ]
  698. },
  699. {
  700. "name": "Conv2D",
  701. "module": "tensorflow.keras.layers",
  702. "category": "Layer",
  703. "description": "2D convolution layer (e.g. spatial convolution over images).\n\nThis layer creates a convolution kernel that is convolved\nwith the layer input to produce a tensor of\noutputs. If `use_bias` is True,\na bias vector is created and added to the outputs. Finally, if\n`activation` is not `None`, it is applied to the outputs as well.\n\nWhen using this layer as the first layer in a model,\nprovide the keyword argument `input_shape`\n(tuple of integers or `None`, does not include the sample axis),\ne.g. `input_shape=(128, 128, 3)` for 128x128 RGB pictures\nin `data_format=\"channels_last\"`. You can use `None` when\na dimension has variable size.",
  704. "attributes": [
  705. {
  706. "default": "linear",
  707. "description": "Activation function to use. If you don't specify anything, no\n activation is applied (see `keras.activations`).",
  708. "name": "activation"
  709. },
  710. {
  711. "default": "valid",
  712. "description": "one of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding with zeros\n evenly to the left/right or up/down of the input. When `padding=\"same\"`\n and `strides=1`, the output has the same size as the input.",
  713. "name": "padding"
  714. },
  715. {
  716. "default": true,
  717. "description": "Boolean, whether the layer uses a bias vector.",
  718. "name": "use_bias",
  719. "type": "boolean",
  720. "visible": false
  721. },
  722. {
  723. "default": "channels_last",
  724. "description": "A string, one of `channels_last` (default) or\n `channels_first`. The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape `(batch_size, height,\n width, channels)` while `channels_first` corresponds to inputs with\n shape `(batch_size, channels, height, width)`. It defaults to the\n `image_data_format` value found in your Keras config file at\n `~/.keras/keras.json`. If you never set it, then it will be\n `channels_last`.",
  725. "name": "data_format"
  726. },
  727. {
  728. "default": [
  729. 1,
  730. 1
  731. ],
  732. "description": "An integer or tuple/list of 2 integers, specifying the strides of\n the convolution along the height and width. Can be a single integer to\n specify the same value for all spatial dimensions. Specifying any stride\n value != 1 is incompatible with specifying any `dilation_rate` value !=\n 1.",
  733. "name": "strides"
  734. },
  735. {
  736. "default": [
  737. 1,
  738. 1
  739. ],
  740. "description": "an integer or tuple/list of 2 integers, specifying the\n dilation rate to use for dilated convolution. Can be a single integer to\n specify the same value for all spatial dimensions. Currently, specifying\n any `dilation_rate` value != 1 is incompatible with specifying any\n stride value != 1.",
  741. "name": "dilation_rate"
  742. },
  743. {
  744. "default": {
  745. "class_name": "Zeros",
  746. "config": {}
  747. },
  748. "description": "Initializer for the bias vector (see\n `keras.initializers`). Defaults to 'zeros'.",
  749. "name": "bias_initializer",
  750. "visible": false
  751. },
  752. {
  753. "default": {
  754. "class_name": "VarianceScaling",
  755. "config": {
  756. "distribution": "uniform",
  757. "mode": "fan_avg",
  758. "scale": 1,
  759. "seed": null
  760. }
  761. },
  762. "description": "Initializer for the `kernel` weights matrix (see\n `keras.initializers`). Defaults to 'glorot_uniform'.",
  763. "name": "kernel_initializer",
  764. "visible": false
  765. },
  766. {
  767. "description": "Integer, the dimensionality of the output space (i.e. the number\n of output filters in the convolution).",
  768. "name": "filters"
  769. },
  770. {
  771. "description": "An integer or tuple/list of 2 integers, specifying the height\n and width of the 2D convolution window. Can be a single integer to\n specify the same value for all spatial dimensions.",
  772. "name": "kernel_size"
  773. },
  774. {
  775. "description": "Regularizer function applied to the `kernel` weights\n matrix (see `keras.regularizers`).",
  776. "name": "kernel_regularizer",
  777. "visible": false
  778. },
  779. {
  780. "description": "Regularizer function applied to the bias vector (see\n `keras.regularizers`).",
  781. "name": "bias_regularizer",
  782. "visible": false
  783. },
  784. {
  785. "description": "Regularizer function applied to the output of the\n layer (its \"activation\") (see `keras.regularizers`).",
  786. "name": "activity_regularizer",
  787. "visible": false
  788. },
  789. {
  790. "description": "Constraint function applied to the kernel matrix (see\n `keras.constraints`).",
  791. "name": "kernel_constraint",
  792. "visible": false
  793. },
  794. {
  795. "description": "Constraint function applied to the bias vector (see\n `keras.constraints`).",
  796. "name": "bias_constraint",
  797. "visible": false
  798. },
  799. {
  800. "description": "A positive integer specifying the number of groups in which the\n input is split along the channel axis. Each group is convolved\n separately with `filters / groups` filters. The output is the\n concatenation of all the `groups` results along the channel axis. Input\n channels and `filters` must both be divisible by `groups`.",
  801. "name": "groups"
  802. }
  803. ],
  804. "inputs": [
  805. {
  806. "description": "4+D tensor with shape: `batch_shape + (channels, rows, cols)` if\n `data_format='channels_first'`\nor 4+D tensor with shape: `batch_shape + (rows, cols, channels)` if\n `data_format='channels_last'`.",
  807. "name": "input"
  808. },
  809. {
  810. "name": "kernel"
  811. },
  812. {
  813. "name": "bias"
  814. }
  815. ],
  816. "outputs": [
  817. {
  818. "description": "4+D tensor with shape: `batch_shape + (filters, new_rows, new_cols)` if\n`data_format='channels_first'` or 4+D tensor with shape: `batch_shape +\n (new_rows, new_cols, filters)` if `data_format='channels_last'`. `rows`\n and `cols` values might have changed due to padding.",
  819. "name": "output"
  820. }
  821. ],
  822. "examples": [
  823. {
  824. "code": ">>> # The inputs are 28x28 RGB images with `channels_last` and the batch\n>>> # size is 4.\n>>> input_shape = (4, 28, 28, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv2D(\n... 2, 3, activation='relu', input_shape=input_shape[1:])(x)\n>>> print(y.shape)\n(4, 26, 26, 2)"
  825. },
  826. {
  827. "code": ">>> # With `dilation_rate` as 2.\n>>> input_shape = (4, 28, 28, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv2D(\n... 2, 3,\n... activation='relu',\n... dilation_rate=2,\n... input_shape=input_shape[1:])(x)\n>>> print(y.shape)\n(4, 24, 24, 2)"
  828. },
  829. {
  830. "code": ">>> # With `padding` as \"same\".\n>>> input_shape = (4, 28, 28, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv2D(\n... 2, 3, activation='relu', padding=\"same\", input_shape=input_shape[1:])(x)\n>>> print(y.shape)\n(4, 28, 28, 2)"
  831. },
  832. {
  833. "code": ">>> # With extended batch shape [4, 7]:\n>>> input_shape = (4, 7, 28, 28, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv2D(\n... 2, 3, activation='relu', input_shape=input_shape[2:])(x)\n>>> print(y.shape)\n(4, 7, 26, 26, 2)"
  834. }
  835. ]
  836. },
  837. {
  838. "name": "Conv2DTranspose",
  839. "module": "tensorflow.keras.layers",
  840. "category": "Layer",
  841. "description": "Transposed convolution layer (sometimes called Deconvolution).\n\nThe need for transposed convolutions generally arises\nfrom the desire to use a transformation going in the opposite direction\nof a normal convolution, i.e., from something that has the shape of the\noutput of some convolution to something that has the shape of its input\nwhile maintaining a connectivity pattern that is compatible with\nsaid convolution.\n\nWhen using this layer as the first layer in a model,\nprovide the keyword argument `input_shape`\n(tuple of integers or `None`, does not include the sample axis),\ne.g. `input_shape=(128, 128, 3)` for 128x128 RGB pictures\nin `data_format=\"channels_last\"`.",
  842. "attributes": [
  843. {
  844. "description": "Integer, the dimensionality of the output space\n (i.e. the number of output filters in the convolution).",
  845. "name": "filters"
  846. },
  847. {
  848. "description": "An integer or tuple/list of 2 integers, specifying the\n height and width of the 2D convolution window.\n Can be a single integer to specify the same value for\n all spatial dimensions.",
  849. "name": "kernel_size"
  850. },
  851. {
  852. "description": "An integer or tuple/list of 2 integers,\n specifying the strides of the convolution along the height and width.\n Can be a single integer to specify the same value for\n all spatial dimensions.\n Specifying any stride value != 1 is incompatible with specifying\n any `dilation_rate` value != 1.",
  853. "name": "strides"
  854. },
  855. {
  856. "description": "one of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding with zeros\n evenly to the left/right or up/down of the input such that output has\n the same height/width dimension as the input.",
  857. "name": "padding"
  858. },
  859. {
  860. "default": "channels_last",
  861. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch_size, height, width, channels)` while `channels_first`\n corresponds to inputs with shape\n `(batch_size, channels, height, width)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  862. "name": "data_format"
  863. },
  864. {
  865. "description": "an integer, specifying the dilation rate for all spatial\n dimensions for dilated convolution. Specifying different dilation rates\n for different dimensions is not supported.\n Currently, specifying any `dilation_rate` value != 1 is\n incompatible with specifying any stride value != 1.",
  866. "name": "dilation_rate"
  867. },
  868. {
  869. "description": "Activation function to use.\n If you don't specify anything, no activation is applied\n (see `keras.activations`).",
  870. "name": "activation"
  871. },
  872. {
  873. "default": true,
  874. "description": "Boolean, whether the layer uses a bias vector.",
  875. "name": "use_bias",
  876. "visible": false
  877. },
  878. {
  879. "default": {
  880. "class_name": "VarianceScaling",
  881. "config": {
  882. "distribution": "uniform",
  883. "mode": "fan_avg",
  884. "scale": 1,
  885. "seed": null
  886. }
  887. },
  888. "description": "Initializer for the `kernel` weights matrix\n (see `keras.initializers`). Defaults to 'glorot_uniform'.",
  889. "name": "kernel_initializer",
  890. "visible": false
  891. },
  892. {
  893. "default": {
  894. "class_name": "Zeros",
  895. "config": {}
  896. },
  897. "description": "Initializer for the bias vector\n (see `keras.initializers`). Defaults to 'zeros'.",
  898. "name": "bias_initializer",
  899. "visible": false
  900. },
  901. {
  902. "description": "Regularizer function applied to\n the `kernel` weights matrix (see `keras.regularizers`).",
  903. "name": "kernel_regularizer",
  904. "visible": false
  905. },
  906. {
  907. "description": "Regularizer function applied to the bias vector\n (see `keras.regularizers`).",
  908. "name": "bias_regularizer",
  909. "visible": false
  910. },
  911. {
  912. "description": "Regularizer function applied to\n the output of the layer (its \"activation\") (see `keras.regularizers`).",
  913. "name": "activity_regularizer",
  914. "visible": false
  915. },
  916. {
  917. "description": "Constraint function applied to the kernel matrix\n (see `keras.constraints`).",
  918. "name": "kernel_constraint"
  919. },
  920. {
  921. "description": "Constraint function applied to the bias vector\n (see `keras.constraints`).",
  922. "name": "bias_constraint"
  923. },
  924. {
  925. "description": "An integer or tuple/list of 2 integers,\n specifying the amount of padding along the height and width\n of the output tensor.\n Can be a single integer to specify the same value for all\n spatial dimensions.\n The amount of output padding along a given dimension must be\n lower than the stride along that same dimension.\n If set to `None` (default), the output shape is inferred.",
  926. "name": "output_padding"
  927. }
  928. ],
  929. "inputs": [
  930. {
  931. "description": "4D tensor with shape:\n`(batch_size, channels, rows, cols)` if data_format='channels_first'\nor 4D tensor with shape:\n`(batch_size, rows, cols, channels)` if data_format='channels_last'.",
  932. "name": "input"
  933. },
  934. {
  935. "name": "kernel"
  936. },
  937. {
  938. "name": "bias"
  939. }
  940. ],
  941. "outputs": [
  942. {
  943. "description": "4D tensor with shape:\n`(batch_size, filters, new_rows, new_cols)` if\ndata_format='channels_first'\nor 4D tensor with shape:\n`(batch_size, new_rows, new_cols, filters)` if\ndata_format='channels_last'. `rows` and `cols` values might have changed\ndue to padding.\nIf `output_padding` is specified:\n```\nnew_rows = ((rows - 1) * strides[0] + kernel_size[0] - 2 * padding[0] +\noutput_padding[0])\nnew_cols = ((cols - 1) * strides[1] + kernel_size[1] - 2 * padding[1] +\noutput_padding[1])\n```",
  944. "name": "output"
  945. }
  946. ],
  947. "references": [
  948. {
  949. "description": "[A guide to convolution arithmetic for deep learning](https://arxiv.org/abs/1603.07285v1)"
  950. },
  951. {
  952. "description": "[Deconvolutional Networks](https://www.matthewzeiler.com/mattzeiler/deconvolutionalnetworks.pdf)"
  953. }
  954. ]
  955. },
  956. {
  957. "name": "Conv3D",
  958. "module": "tensorflow.keras.layers",
  959. "category": "Layer",
  960. "description": "3D convolution layer (e.g. spatial convolution over volumes).\n\nThis layer creates a convolution kernel that is convolved\nwith the layer input to produce a tensor of\noutputs. If `use_bias` is True,\na bias vector is created and added to the outputs. Finally, if\n`activation` is not `None`, it is applied to the outputs as well.\n\nWhen using this layer as the first layer in a model,\nprovide the keyword argument `input_shape`\n(tuple of integers or `None`, does not include the sample axis),\ne.g. `input_shape=(128, 128, 128, 1)` for 128x128x128 volumes\nwith a single channel,\nin `data_format=\"channels_last\"`.",
  961. "attributes": [
  962. {
  963. "description": "Integer, the dimensionality of the output space (i.e. the number\n of output filters in the convolution).",
  964. "name": "filters"
  965. },
  966. {
  967. "description": "An integer or tuple/list of 3 integers, specifying the depth,\n height and width of the 3D convolution window. Can be a single integer\n to specify the same value for all spatial dimensions.",
  968. "name": "kernel_size"
  969. },
  970. {
  971. "description": "An integer or tuple/list of 3 integers, specifying the strides of\n the convolution along each spatial dimension. Can be a single integer to\n specify the same value for all spatial dimensions. Specifying any stride\n value != 1 is incompatible with specifying any `dilation_rate` value !=\n 1.",
  972. "name": "strides"
  973. },
  974. {
  975. "description": "one of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding with zeros\n evenly to the left/right or up/down of the input such that output has\n the same height/width dimension as the input.",
  976. "name": "padding"
  977. },
  978. {
  979. "description": "A string, one of `channels_last` (default) or\n `channels_first`. The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape `batch_shape +\n (spatial_dim1, spatial_dim2, spatial_dim3, channels)` while\n `channels_first` corresponds to inputs with shape `batch_shape +\n (channels, spatial_dim1, spatial_dim2, spatial_dim3)`. It defaults to\n the `image_data_format` value found in your Keras config file at\n `~/.keras/keras.json`. If you never set it, then it will be\n \"channels_last\".",
  980. "name": "data_format"
  981. },
  982. {
  983. "description": "an integer or tuple/list of 3 integers, specifying the\n dilation rate to use for dilated convolution. Can be a single integer to\n specify the same value for all spatial dimensions. Currently, specifying\n any `dilation_rate` value != 1 is incompatible with specifying any\n stride value != 1.",
  984. "name": "dilation_rate"
  985. },
  986. {
  987. "description": "Activation function to use. If you don't specify anything, no\n activation is applied (see `keras.activations`).",
  988. "name": "activation"
  989. },
  990. {
  991. "default": true,
  992. "description": "Boolean, whether the layer uses a bias vector.",
  993. "name": "use_bias",
  994. "visible": false
  995. },
  996. {
  997. "description": "Initializer for the `kernel` weights matrix (see\n `keras.initializers`). Defaults to 'glorot_uniform'.",
  998. "name": "kernel_initializer",
  999. "visible": false
  1000. },
  1001. {
  1002. "description": "Initializer for the bias vector (see\n `keras.initializers`). Defaults to 'zeros'.",
  1003. "name": "bias_initializer",
  1004. "visible": false
  1005. },
  1006. {
  1007. "description": "Regularizer function applied to the `kernel` weights\n matrix (see `keras.regularizers`).",
  1008. "name": "kernel_regularizer",
  1009. "visible": false
  1010. },
  1011. {
  1012. "description": "Regularizer function applied to the bias vector (see\n `keras.regularizers`).",
  1013. "name": "bias_regularizer",
  1014. "visible": false
  1015. },
  1016. {
  1017. "description": "Regularizer function applied to the output of the\n layer (its \"activation\") (see `keras.regularizers`).",
  1018. "name": "activity_regularizer",
  1019. "visible": false
  1020. },
  1021. {
  1022. "description": "Constraint function applied to the kernel matrix (see\n `keras.constraints`).",
  1023. "name": "kernel_constraint"
  1024. },
  1025. {
  1026. "description": "Constraint function applied to the bias vector (see\n `keras.constraints`).",
  1027. "name": "bias_constraint"
  1028. },
  1029. {
  1030. "description": "A positive integer specifying the number of groups in which the\n input is split along the channel axis. Each group is convolved\n separately with `filters / groups` filters. The output is the\n concatenation of all the `groups` results along the channel axis. Input\n channels and `filters` must both be divisible by `groups`.",
  1031. "name": "groups"
  1032. }
  1033. ],
  1034. "inputs": [
  1035. {
  1036. "description": "5+D tensor with shape: `batch_shape + (channels, conv_dim1, conv_dim2,\n conv_dim3)` if data_format='channels_first'\nor 5+D tensor with shape: `batch_shape + (conv_dim1, conv_dim2, conv_dim3,\n channels)` if data_format='channels_last'.",
  1037. "name": "input"
  1038. }
  1039. ],
  1040. "outputs": [
  1041. {
  1042. "description": "5+D tensor with shape: `batch_shape + (filters, new_conv_dim1,\n new_conv_dim2, new_conv_dim3)` if data_format='channels_first'\nor 5+D tensor with shape: `batch_shape + (new_conv_dim1, new_conv_dim2,\n new_conv_dim3, filters)` if data_format='channels_last'.\n `new_conv_dim1`, `new_conv_dim2` and `new_conv_dim3` values might have\n changed due to padding.",
  1043. "name": "output"
  1044. }
  1045. ],
  1046. "examples": [
  1047. {
  1048. "code": ">>> # The inputs are 28x28x28 volumes with a single channel, and the\n>>> # batch size is 4\n>>> input_shape =(4, 28, 28, 28, 1)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv3D(\n... 2, 3, activation='relu', input_shape=input_shape[1:])(x)\n>>> print(y.shape)\n(4, 26, 26, 26, 2)"
  1049. },
  1050. {
  1051. "code": ">>> # With extended batch shape [4, 7], e.g. a batch of 4 videos of\n>>> # 3D frames, with 7 frames per video.\n>>> input_shape = (4, 7, 28, 28, 28, 1)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv3D(\n... 2, 3, activation='relu', input_shape=input_shape[2:])(x)\n>>> print(y.shape)\n(4, 7, 26, 26, 26, 2)"
  1052. }
  1053. ]
  1054. },
  1055. {
  1056. "name": "ConvLSTM2D",
  1057. "module": "tensorflow.keras.layers",
  1058. "description": "2D Convolutional LSTM.\n\nSimilar to an LSTM layer, but the input transformations\nand recurrent transformations are both convolutional.",
  1059. "attributes": [
  1060. {
  1061. "description": "Integer, the dimensionality of the output space (i.e. the number\n of output filters in the convolution).",
  1062. "name": "filters"
  1063. },
  1064. {
  1065. "description": "An integer or tuple/list of n integers, specifying the\n dimensions of the convolution window.",
  1066. "name": "kernel_size"
  1067. },
  1068. {
  1069. "description": "An integer or tuple/list of n integers, specifying the strides of\n the convolution. Specifying any stride value != 1 is incompatible with\n specifying any `dilation_rate` value != 1.",
  1070. "name": "strides"
  1071. },
  1072. {
  1073. "description": "One of `\"valid\"` or `\"same\"` (case-insensitive). `\"valid\"` means\n no padding. `\"same\"` results in padding evenly to the left/right or\n up/down of the input such that output has the same height/width\n dimension as the input.",
  1074. "name": "padding"
  1075. },
  1076. {
  1077. "default": "channels_last",
  1078. "description": "A string, one of `channels_last` (default) or\n `channels_first`. The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape `(batch, time, ...,\n channels)` while `channels_first` corresponds to inputs with shape\n `(batch, time, channels, ...)`. It defaults to the `image_data_format`\n value found in your Keras config file at `~/.keras/keras.json`. If you\n never set it, then it will be \"channels_last\".",
  1079. "name": "data_format"
  1080. },
  1081. {
  1082. "description": "An integer or tuple/list of n integers, specifying the\n dilation rate to use for dilated convolution. Currently, specifying any\n `dilation_rate` value != 1 is incompatible with specifying any `strides`\n value != 1.",
  1083. "name": "dilation_rate"
  1084. },
  1085. {
  1086. "description": "Activation function to use. By default hyperbolic tangent\n activation function is applied (`tanh(x)`).",
  1087. "name": "activation"
  1088. },
  1089. {
  1090. "description": "Activation function to use for the recurrent step.",
  1091. "name": "recurrent_activation"
  1092. },
  1093. {
  1094. "default": true,
  1095. "description": "Boolean, whether the layer uses a bias vector.",
  1096. "name": "use_bias",
  1097. "visible": false
  1098. },
  1099. {
  1100. "description": "Initializer for the `kernel` weights matrix, used for\n the linear transformation of the inputs.",
  1101. "name": "kernel_initializer",
  1102. "visible": false
  1103. },
  1104. {
  1105. "description": "Initializer for the `recurrent_kernel` weights\n matrix, used for the linear transformation of the recurrent state.",
  1106. "name": "recurrent_initializer",
  1107. "visible": false
  1108. },
  1109. {
  1110. "description": "Initializer for the bias vector.",
  1111. "name": "bias_initializer",
  1112. "visible": false
  1113. },
  1114. {
  1115. "description": "Boolean. If True, add 1 to the bias of the forget gate\n at initialization. Use in combination with `bias_initializer=\"zeros\"`.\n This is recommended in [Jozefowicz et al., 2015](\n http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf)",
  1116. "name": "unit_forget_bias"
  1117. },
  1118. {
  1119. "description": "Regularizer function applied to the `kernel` weights\n matrix.",
  1120. "name": "kernel_regularizer",
  1121. "visible": false
  1122. },
  1123. {
  1124. "description": "Regularizer function applied to the\n `recurrent_kernel` weights matrix.",
  1125. "name": "recurrent_regularizer",
  1126. "visible": false
  1127. },
  1128. {
  1129. "description": "Regularizer function applied to the bias vector.",
  1130. "name": "bias_regularizer",
  1131. "visible": false
  1132. },
  1133. {
  1134. "description": "Regularizer function applied to.",
  1135. "name": "activity_regularizer",
  1136. "visible": false
  1137. },
  1138. {
  1139. "description": "Constraint function applied to the `kernel` weights\n matrix.",
  1140. "name": "kernel_constraint",
  1141. "visible": false
  1142. },
  1143. {
  1144. "description": "Constraint function applied to the\n `recurrent_kernel` weights matrix.",
  1145. "name": "recurrent_constraint",
  1146. "visible": false
  1147. },
  1148. {
  1149. "description": "Constraint function applied to the bias vector.",
  1150. "name": "bias_constraint",
  1151. "visible": false
  1152. },
  1153. {
  1154. "description": "Boolean. Whether to return the last output in the output\n sequence, or the full sequence. (default False)",
  1155. "name": "return_sequences"
  1156. },
  1157. {
  1158. "description": "Boolean (default False). If True, process the input sequence\n backwards.",
  1159. "name": "go_backwards"
  1160. },
  1161. {
  1162. "description": "Boolean (default False). If True, the last state for each sample\n at index i in a batch will be used as initial state for the sample of\n index i in the following batch.",
  1163. "name": "stateful"
  1164. },
  1165. {
  1166. "default": 0,
  1167. "description": "Float between 0 and 1. Fraction of the units to drop for the\n linear transformation of the inputs.",
  1168. "name": "dropout"
  1169. },
  1170. {
  1171. "description": "Float between 0 and 1. Fraction of the units to drop\n for the linear transformation of the recurrent state.",
  1172. "name": "recurrent_dropout"
  1173. },
  1174. {
  1175. "description": "Boolean Whether to return the last state in addition to the\n output. (default False)",
  1176. "name": "return_state"
  1177. }
  1178. ],
  1179. "inputs": [
  1180. {
  1181. "description": "- If data_format='channels_first'\n 5D tensor with shape:\n `(samples, time, channels, rows, cols)`\n- If data_format='channels_last'\n 5D tensor with shape:\n `(samples, time, rows, cols, channels)`",
  1182. "name": "input"
  1183. }
  1184. ],
  1185. "outputs": [
  1186. {
  1187. "description": "- If `return_state`: a list of tensors. The first tensor is the output.\n The remaining tensors are the last states,\n each 4D tensor with shape: `(samples, filters, new_rows, new_cols)` if\n data_format='channels_first'\n or shape: `(samples, new_rows, new_cols, filters)` if\n data_format='channels_last'. `rows` and `cols` values might have\n changed due to padding.\n- If `return_sequences`: 5D tensor with shape: `(samples, timesteps,\n filters, new_rows, new_cols)` if data_format='channels_first'\n or shape: `(samples, timesteps, new_rows, new_cols, filters)` if\n data_format='channels_last'.\n- Else, 4D tensor with shape: `(samples, filters, new_rows, new_cols)` if\n data_format='channels_first'\n or shape: `(samples, new_rows, new_cols, filters)` if\n data_format='channels_last'.",
  1188. "name": "output"
  1189. }
  1190. ],
  1191. "examples": [
  1192. {
  1193. "code": "steps = 10\nheight = 32\nwidth = 32\ninput_channels = 3\noutput_channels = 6\n\ninputs = tf.keras.Input(shape=(steps, height, width, input_channels))\nlayer = tf.keras.layers.ConvLSTM2D(filters=output_channels, kernel_size=3)\noutputs = layer(inputs)"
  1194. }
  1195. ],
  1196. "references": [
  1197. {
  1198. "description": "[Shi et al., 2015](http://arxiv.org/abs/1506.04214v1) (the current implementation does not include the feedback loop on the cells output)."
  1199. }
  1200. ]
  1201. },
  1202. {
  1203. "name": "Convolution2D",
  1204. "module": "tensorflow.keras.layers",
  1205. "category": "Layer",
  1206. "description": "2D convolution layer (e.g. spatial convolution over images).\n\nThis layer creates a convolution kernel that is convolved\nwith the layer input to produce a tensor of\noutputs. If `use_bias` is True,\na bias vector is created and added to the outputs. Finally, if\n`activation` is not `None`, it is applied to the outputs as well.\n\nWhen using this layer as the first layer in a model,\nprovide the keyword argument `input_shape`\n(tuple of integers or `None`, does not include the sample axis),\ne.g. `input_shape=(128, 128, 3)` for 128x128 RGB pictures\nin `data_format=\"channels_last\"`. You can use `None` when\na dimension has variable size.",
  1207. "attributes": [
  1208. {
  1209. "default": "linear",
  1210. "description": "Activation function to use. If you don't specify anything, no\n activation is applied (see `keras.activations`).",
  1211. "name": "activation"
  1212. },
  1213. {
  1214. "default": "valid",
  1215. "description": "one of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding with zeros\n evenly to the left/right or up/down of the input. When `padding=\"same\"`\n and `strides=1`, the output has the same size as the input.",
  1216. "name": "padding"
  1217. },
  1218. {
  1219. "default": true,
  1220. "description": "Boolean, whether the layer uses a bias vector.",
  1221. "name": "use_bias",
  1222. "visible": false
  1223. },
  1224. {
  1225. "default": "channels_last",
  1226. "description": "A string, one of `channels_last` (default) or\n `channels_first`. The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape `(batch_size, height,\n width, channels)` while `channels_first` corresponds to inputs with\n shape `(batch_size, channels, height, width)`. It defaults to the\n `image_data_format` value found in your Keras config file at\n `~/.keras/keras.json`. If you never set it, then it will be\n `channels_last`.",
  1227. "name": "data_format"
  1228. },
  1229. {
  1230. "default": [
  1231. 1,
  1232. 1
  1233. ],
  1234. "description": "An integer or tuple/list of 2 integers, specifying the strides of\n the convolution along the height and width. Can be a single integer to\n specify the same value for all spatial dimensions. Specifying any stride\n value != 1 is incompatible with specifying any `dilation_rate` value !=\n 1.",
  1235. "name": "strides"
  1236. },
  1237. {
  1238. "default": [
  1239. 1,
  1240. 1
  1241. ],
  1242. "description": "an integer or tuple/list of 2 integers, specifying the\n dilation rate to use for dilated convolution. Can be a single integer to\n specify the same value for all spatial dimensions. Currently, specifying\n any `dilation_rate` value != 1 is incompatible with specifying any\n stride value != 1.",
  1243. "name": "dilation_rate"
  1244. },
  1245. {
  1246. "default": 1,
  1247. "name": "depth_multiplier"
  1248. },
  1249. {
  1250. "default": {
  1251. "class_name": "Zeros",
  1252. "config": {}
  1253. },
  1254. "description": "Initializer for the bias vector (see\n `keras.initializers`). Defaults to 'zeros'.",
  1255. "name": "bias_initializer",
  1256. "visible": false
  1257. },
  1258. {
  1259. "default": {
  1260. "class_name": "VarianceScaling",
  1261. "config": {
  1262. "distribution": "uniform",
  1263. "mode": "fan_avg",
  1264. "scale": 1,
  1265. "seed": null
  1266. }
  1267. },
  1268. "description": "Initializer for the `kernel` weights matrix (see\n `keras.initializers`). Defaults to 'glorot_uniform'.",
  1269. "name": "kernel_initializer",
  1270. "visible": false
  1271. },
  1272. {
  1273. "description": "Integer, the dimensionality of the output space (i.e. the number\n of output filters in the convolution).",
  1274. "name": "filters"
  1275. },
  1276. {
  1277. "description": "An integer or tuple/list of 2 integers, specifying the height\n and width of the 2D convolution window. Can be a single integer to\n specify the same value for all spatial dimensions.",
  1278. "name": "kernel_size"
  1279. },
  1280. {
  1281. "description": "Regularizer function applied to the `kernel` weights\n matrix (see `keras.regularizers`).",
  1282. "name": "kernel_regularizer",
  1283. "visible": false
  1284. },
  1285. {
  1286. "description": "Regularizer function applied to the bias vector (see\n `keras.regularizers`).",
  1287. "name": "bias_regularizer",
  1288. "visible": false
  1289. },
  1290. {
  1291. "description": "Regularizer function applied to the output of the\n layer (its \"activation\") (see `keras.regularizers`).",
  1292. "name": "activity_regularizer",
  1293. "visible": false
  1294. },
  1295. {
  1296. "description": "Constraint function applied to the kernel matrix (see\n `keras.constraints`).",
  1297. "name": "kernel_constraint"
  1298. },
  1299. {
  1300. "description": "Constraint function applied to the bias vector (see\n `keras.constraints`).",
  1301. "name": "bias_constraint"
  1302. },
  1303. {
  1304. "description": "A positive integer specifying the number of groups in which the\n input is split along the channel axis. Each group is convolved\n separately with `filters / groups` filters. The output is the\n concatenation of all the `groups` results along the channel axis. Input\n channels and `filters` must both be divisible by `groups`.",
  1305. "name": "groups"
  1306. }
  1307. ],
  1308. "inputs": [
  1309. {
  1310. "description": "4+D tensor with shape: `batch_shape + (channels, rows, cols)` if\n `data_format='channels_first'`\nor 4+D tensor with shape: `batch_shape + (rows, cols, channels)` if\n `data_format='channels_last'`.",
  1311. "name": "input"
  1312. },
  1313. {
  1314. "name": "kernel"
  1315. },
  1316. {
  1317. "name": "bias"
  1318. }
  1319. ],
  1320. "outputs": [
  1321. {
  1322. "description": "4+D tensor with shape: `batch_shape + (filters, new_rows, new_cols)` if\n`data_format='channels_first'` or 4+D tensor with shape: `batch_shape +\n (new_rows, new_cols, filters)` if `data_format='channels_last'`. `rows`\n and `cols` values might have changed due to padding.",
  1323. "name": "output"
  1324. }
  1325. ],
  1326. "examples": [
  1327. {
  1328. "code": ">>> # The inputs are 28x28 RGB images with `channels_last` and the batch\n>>> # size is 4.\n>>> input_shape = (4, 28, 28, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv2D(\n... 2, 3, activation='relu', input_shape=input_shape[1:])(x)\n>>> print(y.shape)\n(4, 26, 26, 2)"
  1329. },
  1330. {
  1331. "code": ">>> # With `dilation_rate` as 2.\n>>> input_shape = (4, 28, 28, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv2D(\n... 2, 3,\n... activation='relu',\n... dilation_rate=2,\n... input_shape=input_shape[1:])(x)\n>>> print(y.shape)\n(4, 24, 24, 2)"
  1332. },
  1333. {
  1334. "code": ">>> # With `padding` as \"same\".\n>>> input_shape = (4, 28, 28, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv2D(\n... 2, 3, activation='relu', padding=\"same\", input_shape=input_shape[1:])(x)\n>>> print(y.shape)\n(4, 28, 28, 2)"
  1335. },
  1336. {
  1337. "code": ">>> # With extended batch shape [4, 7]:\n>>> input_shape = (4, 7, 28, 28, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.Conv2D(\n... 2, 3, activation='relu', input_shape=input_shape[2:])(x)\n>>> print(y.shape)\n(4, 7, 26, 26, 2)"
  1338. }
  1339. ]
  1340. },
  1341. {
  1342. "name": "Cropping1D",
  1343. "module": "tensorflow.keras.layers",
  1344. "category": "Shape",
  1345. "description": "Cropping layer for 1D input (e.g. temporal sequence).\n\nIt crops along the time dimension (axis 1).",
  1346. "attributes": [
  1347. {
  1348. "description": "Int or tuple of int (length 2)\n How many units should be trimmed off at the beginning and end of\n the cropping dimension (axis 1).\n If a single int is provided, the same value will be used for both.",
  1349. "name": "cropping"
  1350. }
  1351. ],
  1352. "inputs": [
  1353. {
  1354. "description": "3D tensor with shape `(batch_size, axis_to_crop, features)`",
  1355. "name": "input"
  1356. }
  1357. ],
  1358. "outputs": [
  1359. {
  1360. "description": "3D tensor with shape `(batch_size, cropped_axis, features)`",
  1361. "name": "output"
  1362. }
  1363. ],
  1364. "examples": [
  1365. {
  1366. "code": ">>> input_shape = (2, 3, 2)\n>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)\n>>> print(x)\n[[[ 0 1]\n [ 2 3]\n [ 4 5]]\n [[ 6 7]\n [ 8 9]\n [10 11]]]\n>>> y = tf.keras.layers.Cropping1D(cropping=1)(x)\n>>> print(y)\ntf.Tensor(\n [[[2 3]]\n [[8 9]]], shape=(2, 1, 2), dtype=int64)"
  1367. }
  1368. ]
  1369. },
  1370. {
  1371. "name": "Cropping2D",
  1372. "module": "tensorflow.keras.layers",
  1373. "category": "Shape",
  1374. "description": "Cropping layer for 2D input (e.g. picture).\n\nIt crops along spatial dimensions, i.e. height and width.",
  1375. "attributes": [
  1376. {
  1377. "description": "Int, or tuple of 2 ints, or tuple of 2 tuples of 2 ints.\n - If int: the same symmetric cropping\n is applied to height and width.\n - If tuple of 2 ints:\n interpreted as two different\n symmetric cropping values for height and width:\n `(symmetric_height_crop, symmetric_width_crop)`.\n - If tuple of 2 tuples of 2 ints:\n interpreted as\n `((top_crop, bottom_crop), (left_crop, right_crop))`",
  1378. "name": "cropping"
  1379. },
  1380. {
  1381. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch_size, height, width, channels)` while `channels_first`\n corresponds to inputs with shape\n `(batch_size, channels, height, width)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  1382. "name": "data_format"
  1383. }
  1384. ],
  1385. "inputs": [
  1386. {
  1387. "description": "4D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, rows, cols, channels)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, channels, rows, cols)`",
  1388. "name": "input"
  1389. }
  1390. ],
  1391. "outputs": [
  1392. {
  1393. "description": "4D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, cropped_rows, cropped_cols, channels)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, channels, cropped_rows, cropped_cols)`",
  1394. "name": "output"
  1395. }
  1396. ],
  1397. "examples": [
  1398. {
  1399. "code": ">>> input_shape = (2, 28, 28, 3)\n>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)\n>>> y = tf.keras.layers.Cropping2D(cropping=((2, 2), (4, 4)))(x)\n>>> print(y.shape)\n(2, 24, 20, 3)"
  1400. }
  1401. ]
  1402. },
  1403. {
  1404. "name": "Cropping3D",
  1405. "module": "tensorflow.keras.layers",
  1406. "category": "Shape",
  1407. "description": "Cropping layer for 3D data (e.g. spatial or spatio-temporal).\n\n Examples:\n\n```\n>>> input_shape = (2, 28, 28, 10, 3)\n>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)\n>>> y = tf.keras.layers.Cropping3D(cropping=(2, 4, 2))(x)\n>>> print(y.shape)\n(2, 24, 20, 6, 3)\n```",
  1408. "attributes": [
  1409. {
  1410. "description": "Int, or tuple of 3 ints, or tuple of 3 tuples of 2 ints.\n - If int: the same symmetric cropping\n is applied to depth, height, and width.\n - If tuple of 3 ints: interpreted as two different\n symmetric cropping values for depth, height, and width:\n `(symmetric_dim1_crop, symmetric_dim2_crop, symmetric_dim3_crop)`.\n - If tuple of 3 tuples of 2 ints: interpreted as\n `((left_dim1_crop, right_dim1_crop), (left_dim2_crop,\n right_dim2_crop), (left_dim3_crop, right_dim3_crop))`",
  1411. "name": "cropping"
  1412. },
  1413. {
  1414. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)`\n while `channels_first` corresponds to inputs with shape\n `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  1415. "name": "data_format"
  1416. }
  1417. ],
  1418. "inputs": [
  1419. {
  1420. "description": "5D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, first_axis_to_crop, second_axis_to_crop,\n third_axis_to_crop, depth)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, depth, first_axis_to_crop, second_axis_to_crop,\n third_axis_to_crop)`",
  1421. "name": "input"
  1422. }
  1423. ],
  1424. "outputs": [
  1425. {
  1426. "description": "5D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, first_cropped_axis, second_cropped_axis,\n third_cropped_axis, depth)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, depth, first_cropped_axis, second_cropped_axis,\n third_cropped_axis)`",
  1427. "name": "output"
  1428. }
  1429. ]
  1430. },
  1431. {
  1432. "name": "CuDNNGRU",
  1433. "description": "Fast GRU implementation backed by [CuDNN](https://developer.nvidia.com/cudnn).\n\nCan only be run on GPU, with the TensorFlow backend.\n",
  1434. "attributes": [
  1435. {
  1436. "description": "Positive integer, dimensionality of the output space.",
  1437. "name": "units"
  1438. },
  1439. {
  1440. "description": "Initializer for the `kernel` weights matrix,\n used for the linear transformation of the inputs.\n (see [initializers](https://keras.io/initializers)).",
  1441. "name": "kernel_initializer",
  1442. "visible": false
  1443. },
  1444. {
  1445. "description": "Initializer for the `recurrent_kernel`\n weights matrix,\n used for the linear transformation of the recurrent state.\n (see [initializers](https://keras.io/initializers)).",
  1446. "name": "recurrent_initializer",
  1447. "visible": false
  1448. },
  1449. {
  1450. "description": "Initializer for the bias vector\n (see [initializers](https://keras.io/initializers)).",
  1451. "name": "bias_initializer",
  1452. "visible": false
  1453. },
  1454. {
  1455. "description": "Regularizer function applied to\n the `kernel` weights matrix\n (see [regularizer](https://keras.io/regularizers)).",
  1456. "name": "kernel_regularizer",
  1457. "visible": false
  1458. },
  1459. {
  1460. "description": "Regularizer function applied to\n the `recurrent_kernel` weights matrix\n (see [regularizer](https://keras.io/regularizers)).",
  1461. "name": "recurrent_regularizer",
  1462. "visible": false
  1463. },
  1464. {
  1465. "description": "Regularizer function applied to the bias vector\n (see [regularizer](https://keras.io/regularizers)).",
  1466. "name": "bias_regularizer",
  1467. "visible": false
  1468. },
  1469. {
  1470. "description": "Regularizer function applied to\n the output of the layer (its \"activation\").\n (see [regularizer](https://keras.io/regularizers)).",
  1471. "name": "activity_regularizer",
  1472. "visible": false
  1473. },
  1474. {
  1475. "description": "Constraint function applied to\n the `kernel` weights matrix\n (see [constraints](https://keras.io/constraints)).",
  1476. "name": "kernel_constraint"
  1477. },
  1478. {
  1479. "description": "Constraint function applied to\n the `recurrent_kernel` weights matrix\n (see [constraints](https://keras.io/constraints)).",
  1480. "name": "recurrent_constraint"
  1481. },
  1482. {
  1483. "description": "Constraint function applied to the bias vector\n (see [constraints](https://keras.io/constraints)).",
  1484. "name": "bias_constraint"
  1485. },
  1486. {
  1487. "description": "Boolean. Whether to return the last output.\n in the output sequence, or the full sequence.",
  1488. "name": "return_sequences"
  1489. },
  1490. {
  1491. "description": "Boolean. Whether to return the last state\n in addition to the output.",
  1492. "name": "return_state"
  1493. },
  1494. {
  1495. "description": "Boolean (default False). If True, the last state\n for each sample at index i in a batch will be used as initial\n state for the sample of index i in the following batch.\n",
  1496. "name": "stateful"
  1497. }
  1498. ]
  1499. },
  1500. {
  1501. "name": "CuDNNLSTM",
  1502. "description": "Fast LSTM implementation with [CuDNN](https://developer.nvidia.com/cudnn).\n\nCan only be run on GPU, with the TensorFlow backend.\n",
  1503. "attributes": [
  1504. {
  1505. "description": "Positive integer, dimensionality of the output space.",
  1506. "name": "units"
  1507. },
  1508. {
  1509. "description": "Initializer for the `kernel` weights matrix,\n used for the linear transformation of the inputs.\n (see [initializers](https://keras.io/initializers)).",
  1510. "name": "kernel_initializer"
  1511. },
  1512. {
  1513. "description": "Initializer for the `recurrent_kernel`\n weights matrix,\n used for the linear transformation of the recurrent state.\n (see [initializers](https://keras.io/initializers)).",
  1514. "name": "recurrent_initializer"
  1515. },
  1516. {
  1517. "description": "Initializer for the bias vector\n (see [initializers](https://keras.io/initializers)).",
  1518. "name": "bias_initializer"
  1519. },
  1520. {
  1521. "description": "Boolean.\n If True, add 1 to the bias of the forget gate at initialization.\n Setting it to true will also force `bias_initializer=\"zeros\"`.\n This is recommended in [Jozefowicz et al. (2015)](\n http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf).",
  1522. "name": "unit_forget_bias"
  1523. },
  1524. {
  1525. "description": "Regularizer function applied to\n the `kernel` weights matrix\n (see [regularizer](https://keras.io/regularizers)).",
  1526. "name": "kernel_regularizer"
  1527. },
  1528. {
  1529. "description": "Regularizer function applied to\n the `recurrent_kernel` weights matrix\n (see [regularizer](https://keras.io/regularizers)).",
  1530. "name": "recurrent_regularizer"
  1531. },
  1532. {
  1533. "description": "Regularizer function applied to the bias vector\n (see [regularizer](https://keras.io/regularizers)).",
  1534. "name": "bias_regularizer"
  1535. },
  1536. {
  1537. "description": "Regularizer function applied to\n the output of the layer (its \"activation\").\n (see [regularizer](https://keras.io/regularizers)).",
  1538. "name": "activity_regularizer"
  1539. },
  1540. {
  1541. "description": "Constraint function applied to\n the `kernel` weights matrix\n (see [constraints](https://keras.io/constraints)).",
  1542. "name": "kernel_constraint"
  1543. },
  1544. {
  1545. "description": "Constraint function applied to\n the `recurrent_kernel` weights matrix\n (see [constraints](https://keras.io/constraints)).",
  1546. "name": "recurrent_constraint"
  1547. },
  1548. {
  1549. "description": "Constraint function applied to the bias vector\n (see [constraints](https://keras.io/constraints)).",
  1550. "name": "bias_constraint"
  1551. },
  1552. {
  1553. "description": "Boolean. Whether to return the last output.\n in the output sequence, or the full sequence.",
  1554. "name": "return_sequences"
  1555. },
  1556. {
  1557. "description": "Boolean. Whether to return the last state\n in addition to the output.",
  1558. "name": "return_state"
  1559. },
  1560. {
  1561. "description": "Boolean (default False). If True, the last state\n for each sample at index i in a batch will be used as initial\n state for the sample of index i in the following batch.\n",
  1562. "name": "stateful"
  1563. }
  1564. ]
  1565. },
  1566. {
  1567. "name": "Dense",
  1568. "module": "tensorflow.keras.layers",
  1569. "category": "Layer",
  1570. "description": "Just your regular densely-connected NN layer.\n\n`Dense` implements the operation:\n`output = activation(dot(input, kernel) + bias)`\nwhere `activation` is the element-wise activation function\npassed as the `activation` argument, `kernel` is a weights matrix\ncreated by the layer, and `bias` is a bias vector created by the layer\n(only applicable if `use_bias` is `True`). These are all attributes of\n`Dense`.\n\nNote: If the input to the layer has a rank greater than 2, then `Dense`\ncomputes the dot product between the `inputs` and the `kernel` along the\nlast axis of the `inputs` and axis 0 of the `kernel` (using `tf.tensordot`).\nFor example, if input has dimensions `(batch_size, d0, d1)`, then we create\na `kernel` with shape `(d1, units)`, and the `kernel` operates along axis 2\nof the `input`, on every sub-tensor of shape `(1, 1, d1)` (there are\n`batch_size * d0` such sub-tensors). The output in this case will have\nshape `(batch_size, d0, units)`.\n\nBesides, layer attributes cannot be modified after the layer has been called\nonce (except the `trainable` attribute).\nWhen a popular kwarg `input_shape` is passed, then keras will create\nan input layer to insert before the current layer. This can be treated\nequivalent to explicitly defining an `InputLayer`.",
  1571. "attributes": [
  1572. {
  1573. "description": "Positive integer, dimensionality of the output space.",
  1574. "name": "units"
  1575. },
  1576. {
  1577. "default": "linear",
  1578. "description": "Activation function to use.\n If you don't specify anything, no activation is applied\n (ie. \"linear\" activation: `a(x) = x`).",
  1579. "name": "activation"
  1580. },
  1581. {
  1582. "default": true,
  1583. "description": "Boolean, whether the layer uses a bias vector.",
  1584. "name": "use_bias",
  1585. "type": "boolean"
  1586. },
  1587. {
  1588. "default": {
  1589. "class_name": "VarianceScaling",
  1590. "config": {
  1591. "distribution": "uniform",
  1592. "mode": "fan_avg",
  1593. "scale": 1,
  1594. "seed": null
  1595. }
  1596. },
  1597. "description": "Initializer for the `kernel` weights matrix.",
  1598. "name": "kernel_initializer",
  1599. "visible": false
  1600. },
  1601. {
  1602. "default": {
  1603. "class_name": "Zeros",
  1604. "config": {}
  1605. },
  1606. "description": "Initializer for the bias vector.",
  1607. "name": "bias_initializer",
  1608. "visible": false
  1609. },
  1610. {
  1611. "description": "Regularizer function applied to\n the `kernel` weights matrix.",
  1612. "name": "kernel_regularizer",
  1613. "visible": false
  1614. },
  1615. {
  1616. "description": "Regularizer function applied to the bias vector.",
  1617. "name": "bias_regularizer",
  1618. "visible": false
  1619. },
  1620. {
  1621. "description": "Regularizer function applied to\n the output of the layer (its \"activation\").",
  1622. "name": "activity_regularizer",
  1623. "visible": false
  1624. },
  1625. {
  1626. "description": "Constraint function applied to\n the `kernel` weights matrix.",
  1627. "name": "kernel_constraint"
  1628. },
  1629. {
  1630. "description": "Constraint function applied to the bias vector.",
  1631. "name": "bias_constraint"
  1632. }
  1633. ],
  1634. "inputs": [
  1635. {
  1636. "description": "N-D tensor with shape: `(batch_size, ..., input_dim)`.\nThe most common situation would be\na 2D input with shape `(batch_size, input_dim)`.",
  1637. "name": "input",
  1638. "type": "T"
  1639. },
  1640. {
  1641. "name": "kernel",
  1642. "type": "T"
  1643. },
  1644. {
  1645. "name": "bias",
  1646. "type": "T"
  1647. }
  1648. ],
  1649. "outputs": [
  1650. {
  1651. "description": "N-D tensor with shape: `(batch_size, ..., units)`.\nFor instance, for a 2D input with shape `(batch_size, input_dim)`,\nthe output would have shape `(batch_size, units)`.",
  1652. "name": "output",
  1653. "type": "T"
  1654. }
  1655. ],
  1656. "examples": [
  1657. {
  1658. "code": ">>> # Create a `Sequential` model and add a Dense layer as the first layer.\n>>> model = tf.keras.models.Sequential()\n>>> model.add(tf.keras.Input(shape=(16,)))\n>>> model.add(tf.keras.layers.Dense(32, activation='relu'))\n>>> # Now the model will take as input arrays of shape (None, 16)\n>>> # and output arrays of shape (None, 32).\n>>> # Note that after the first layer, you don't need to specify\n>>> # the size of the input anymore:\n>>> model.add(tf.keras.layers.Dense(32))\n>>> model.output_shape\n(None, 32)"
  1659. }
  1660. ]
  1661. },
  1662. {
  1663. "name": "DepthwiseConv2D",
  1664. "category": "Layer",
  1665. "attributes": [
  1666. {
  1667. "default": "linear",
  1668. "name": "activation"
  1669. },
  1670. {
  1671. "default": "valid",
  1672. "name": "padding"
  1673. },
  1674. {
  1675. "default": true,
  1676. "name": "use_bias",
  1677. "type": "boolean",
  1678. "visible": false
  1679. },
  1680. {
  1681. "default": "channels_last",
  1682. "name": "data_format"
  1683. },
  1684. {
  1685. "default": [
  1686. 1,
  1687. 1
  1688. ],
  1689. "name": "strides"
  1690. },
  1691. {
  1692. "default": [
  1693. 1,
  1694. 1
  1695. ],
  1696. "name": "dilation_rate"
  1697. },
  1698. {
  1699. "default": {
  1700. "class_name": "Zeros",
  1701. "config": {}
  1702. },
  1703. "name": "bias_initializer",
  1704. "visible": false
  1705. },
  1706. {
  1707. "default": {
  1708. "class_name": "VarianceScaling",
  1709. "config": {
  1710. "distribution": "uniform",
  1711. "mode": "fan_avg",
  1712. "scale": 1,
  1713. "seed": null
  1714. }
  1715. },
  1716. "name": "depthwise_initializer",
  1717. "visible": false
  1718. },
  1719. {
  1720. "default": 1,
  1721. "name": "depth_multiplier"
  1722. }
  1723. ],
  1724. "inputs": [
  1725. {
  1726. "name": "input"
  1727. },
  1728. {
  1729. "name": "kernel"
  1730. },
  1731. {
  1732. "name": "bias"
  1733. }
  1734. ],
  1735. "outputs": [
  1736. {
  1737. "name": "output"
  1738. }
  1739. ]
  1740. },
  1741. {
  1742. "name": "Dot",
  1743. "module": "tensorflow.keras.layers",
  1744. "description": "Layer that computes a dot product between samples in two tensors.\n\nE.g. if applied to a list of two tensors `a` and `b` of shape\n`(batch_size, n)`, the output will be a tensor of shape `(batch_size, 1)`\nwhere each entry `i` will be the dot product between\n`a[i]` and `b[i]`.\n\n```\n>>> x = np.arange(10).reshape(1, 5, 2)\n>>> print(x)\n[[[0 1]\n [2 3]\n [4 5]\n [6 7]\n [8 9]]]\n>>> y = np.arange(10, 20).reshape(1, 2, 5)\n>>> print(y)\n[[[10 11 12 13 14]\n [15 16 17 18 19]]]\n>>> tf.keras.layers.Dot(axes=(1, 2))([x, y])\n<tf.Tensor: shape=(1, 2, 2), dtype=int64, numpy=\narray([[[260, 360],\n [320, 445]]])>\n```\n\n```\n>>> x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2))\n>>> x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))\n>>> dotted = tf.keras.layers.Dot(axes=1)([x1, x2])\n>>> dotted.shape\nTensorShape([5, 1])\n```",
  1745. "attributes": [
  1746. {
  1747. "description": "Integer or tuple of integers,\n axis or axes along which to take the dot product.",
  1748. "name": "axes"
  1749. },
  1750. {
  1751. "description": "Whether to L2-normalize samples along the\n dot product axis before taking the dot product.\n If set to True, then the output of the dot product\n is the cosine proximity between the two samples.",
  1752. "name": "normalize"
  1753. },
  1754. {
  1755. "description": "Standard layer keyword arguments.\n",
  1756. "name": "**kwargs"
  1757. }
  1758. ],
  1759. "inputs": [
  1760. {
  1761. "name": "x"
  1762. },
  1763. {
  1764. "name": "y"
  1765. }
  1766. ],
  1767. "outputs": [
  1768. {
  1769. "name": "z"
  1770. }
  1771. ]
  1772. },
  1773. {
  1774. "name": "Dropout",
  1775. "module": "tensorflow.keras.layers",
  1776. "category": "Dropout",
  1777. "description": "Applies Dropout to the input.\n\nThe Dropout layer randomly sets input units to 0 with a frequency of `rate`\nat each step during training time, which helps prevent overfitting.\nInputs not set to 0 are scaled up by 1/(1 - rate) such that the sum over\nall inputs is unchanged.\n\nNote that the Dropout layer only applies when `training` is set to True\nsuch that no values are dropped during inference. When using `model.fit`,\n`training` will be appropriately set to True automatically, and in other\ncontexts, you can set the kwarg explicitly to True when calling the layer.\n\n(This is in contrast to setting `trainable=False` for a Dropout layer.\n`trainable` does not affect the layer's behavior, as Dropout does\nnot have any variables/weights that can be frozen during training.)\n\n```\n>>> tf.random.set_seed(0)\n>>> layer = tf.keras.layers.Dropout(.2, input_shape=(2,))\n>>> data = np.arange(10).reshape(5, 2).astype(np.float32)\n>>> print(data)\n[[0. 1.]\n [2. 3.]\n [4. 5.]\n [6. 7.]\n [8. 9.]]\n>>> outputs = layer(data, training=True)\n>>> print(outputs)\ntf.Tensor(\n[[ 0. 1.25]\n [ 2.5 3.75]\n [ 5. 6.25]\n [ 7.5 8.75]\n [10. 0. ]], shape=(5, 2), dtype=float32)\n```",
  1778. "attributes": [
  1779. {
  1780. "description": "Float between 0 and 1. Fraction of the input units to drop.",
  1781. "name": "rate"
  1782. },
  1783. {
  1784. "description": "1D integer tensor representing the shape of the\n binary dropout mask that will be multiplied with the input.\n For instance, if your inputs have shape\n `(batch_size, timesteps, features)` and\n you want the dropout mask to be the same for all timesteps,\n you can use `noise_shape=(batch_size, 1, features)`.",
  1785. "name": "noise_shape"
  1786. },
  1787. {
  1788. "description": "A Python integer to use as random seed.",
  1789. "name": "seed"
  1790. }
  1791. ],
  1792. "inputs": [
  1793. {
  1794. "name": "input"
  1795. }
  1796. ],
  1797. "outputs": [
  1798. {
  1799. "name": "output"
  1800. }
  1801. ],
  1802. "references": [
  1803. {
  1804. "description": "[Dropout: A Simple Way to Prevent Neural Networks from Overfitting]( http://www.jmlr.org/papers/volume15/srivastava14a/srivastava14a.pdf)"
  1805. }
  1806. ]
  1807. },
  1808. {
  1809. "name": "ELU",
  1810. "module": "tensorflow.keras.layers",
  1811. "category": "Activation",
  1812. "description": "Exponential Linear Unit.\n\nIt follows:\n\n```\n f(x) = alpha * (exp(x) - 1.) for x < 0\n f(x) = x for x >= 0\n```",
  1813. "attributes": [
  1814. {
  1815. "description": "Scale for the negative factor.",
  1816. "name": "alpha"
  1817. }
  1818. ],
  1819. "inputs": [
  1820. {
  1821. "description": "Arbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the samples axis)\nwhen using this layer as the first layer in a model.",
  1822. "name": "input"
  1823. }
  1824. ],
  1825. "outputs": [
  1826. {
  1827. "description": "Same shape as the input.",
  1828. "name": "output"
  1829. }
  1830. ],
  1831. "references": [
  1832. {
  1833. "description": "[Fast and Accurate Deep Network Learning by Exponential Linear Units (ELUs)](https://arxiv.org/abs/1511.07289v1)"
  1834. }
  1835. ]
  1836. },
  1837. {
  1838. "name": "Embedding",
  1839. "module": "tensorflow.keras.layers",
  1840. "category": "Transform",
  1841. "description": "Turns positive integers (indexes) into dense vectors of fixed size.\n\ne.g. `[[4], [20]] -> [[0.25, 0.1], [0.6, -0.2]]`\n\nThis layer can only be used on positive integer inputs of a fixed range. The\n`tf.keras.layers.TextVectorization`, `tf.keras.layers.StringLookup`,\nand `tf.keras.layers.IntegerLookup` preprocessing layers can help prepare\ninputs for an `Embedding` layer.\n\nThis layer accepts `tf.Tensor` and `tf.RaggedTensor` inputs. It cannot be\ncalled with `tf.SparseTensor` input.",
  1842. "attributes": [
  1843. {
  1844. "default": false,
  1845. "description": "Boolean, whether or not the input value 0 is a special\n \"padding\" value that should be masked out. This is useful when using\n recurrent layers which may take variable length input. If this is\n `True`, then all subsequent layers in the model need to support masking\n or an exception will be raised. If mask_zero is set to True, as a\n consequence, index 0 cannot be used in the vocabulary (input_dim should\n equal size of vocabulary + 1).",
  1846. "name": "mask_zero"
  1847. },
  1848. {
  1849. "default": {
  1850. "class_name": "RandomUniform",
  1851. "config": {
  1852. "maxval": 0.05,
  1853. "minval": -0.05,
  1854. "seed": null
  1855. }
  1856. },
  1857. "description": "Initializer for the `embeddings`\n matrix (see `keras.initializers`).",
  1858. "name": "embeddings_initializer",
  1859. "visible": false
  1860. },
  1861. {
  1862. "description": "Integer. Size of the vocabulary,\n i.e. maximum integer index + 1.",
  1863. "name": "input_dim"
  1864. },
  1865. {
  1866. "description": "Integer. Dimension of the dense embedding.",
  1867. "name": "output_dim"
  1868. },
  1869. {
  1870. "description": "Regularizer function applied to\n the `embeddings` matrix (see `keras.regularizers`).",
  1871. "name": "embeddings_regularizer",
  1872. "visible": false
  1873. },
  1874. {
  1875. "description": "Constraint function applied to\n the `embeddings` matrix (see `keras.constraints`).",
  1876. "name": "embeddings_constraint"
  1877. },
  1878. {
  1879. "description": "Length of input sequences, when it is constant.\n This argument is required if you are going to connect\n `Flatten` then `Dense` layers upstream\n (without it, the shape of the dense outputs cannot be computed).",
  1880. "name": "input_length"
  1881. },
  1882. {
  1883. "description": "Regularizer function applied to\n the output of the layer (its \"activation\").\n (see [regularizer](https://keras.io/regularizers)).",
  1884. "name": "activity_regularizer"
  1885. }
  1886. ],
  1887. "inputs": [
  1888. {
  1889. "description": "2D tensor with shape: `(batch_size, input_length)`.",
  1890. "name": "input"
  1891. },
  1892. {
  1893. "name": "embeddings"
  1894. }
  1895. ],
  1896. "outputs": [
  1897. {
  1898. "description": "3D tensor with shape: `(batch_size, input_length, output_dim)`.\n\n**Note on variable placement:**\nBy default, if a GPU is available, the embedding matrix will be placed on\nthe GPU. This achieves the best performance, but it might cause issues:\n\n- You may be using an optimizer that does not support sparse GPU kernels.\nIn this case you will see an error upon training your model.\n- Your embedding matrix may be too large to fit on your GPU. In this case\nyou will see an Out Of Memory (OOM) error.\n\nIn such cases, you should place the embedding matrix on the CPU memory.\nYou can do so with a device scope, as such:\n\n```python\nwith tf.device('cpu:0'):\n embedding_layer = Embedding(...)\n embedding_layer.build()\n```\n\nThe pre-built `embedding_layer` instance can then be added to a `Sequential`\nmodel (e.g. `model.add(embedding_layer)`), called in a Functional model\n(e.g. `x = embedding_layer(x)`), or used in a subclassed model.",
  1899. "name": "output"
  1900. }
  1901. ],
  1902. "references": [
  1903. {
  1904. "description": "[A Theoretically Grounded Application of Dropout in Recurrent Neural Networks](http://arxiv.org/abs/1512.05287)"
  1905. }
  1906. ],
  1907. "examples": [
  1908. {
  1909. "code": ">>> model = tf.keras.Sequential()\n>>> model.add(tf.keras.layers.Embedding(1000, 64, input_length=10))\n>>> # The model will take as input an integer matrix of size (batch,\n>>> # input_length), and the largest integer (i.e. word index) in the input\n>>> # should be no larger than 999 (vocabulary size).\n>>> # Now model.output_shape is (None, 10, 64), where `None` is the batch\n>>> # dimension.\n>>> input_array = np.random.randint(1000, size=(32, 10))\n>>> model.compile('rmsprop', 'mse')\n>>> output_array = model.predict(input_array)\n>>> print(output_array.shape)\n(32, 10, 64)"
  1910. }
  1911. ]
  1912. },
  1913. {
  1914. "name": "Flatten",
  1915. "module": "tensorflow.keras.layers",
  1916. "category": "Shape",
  1917. "description": "Flattens the input. Does not affect the batch size.\n\nNote: If inputs are shaped `(batch,)` without a feature axis, then\nflattening adds an extra channel dimension and output shape is `(batch, 1)`.",
  1918. "attributes": [
  1919. {
  1920. "default": "channels_last",
  1921. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, ..., channels)` while `channels_first` corresponds to\n inputs with shape `(batch, channels, ...)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  1922. "name": "data_format"
  1923. }
  1924. ],
  1925. "inputs": [
  1926. {
  1927. "name": "input"
  1928. }
  1929. ],
  1930. "outputs": [
  1931. {
  1932. "name": "output"
  1933. }
  1934. ],
  1935. "examples": [
  1936. {
  1937. "code": ">>> model = tf.keras.Sequential()\n>>> model.add(tf.keras.layers.Conv2D(64, 3, 3, input_shape=(3, 32, 32)))\n>>> model.output_shape\n(None, 1, 10, 64)"
  1938. },
  1939. {
  1940. "code": ">>> model.add(Flatten())\n>>> model.output_shape\n(None, 640)"
  1941. }
  1942. ]
  1943. },
  1944. {
  1945. "name": "GlobalAveragePooling1D",
  1946. "module": "tensorflow.keras.layers",
  1947. "category": "Pool",
  1948. "description": "Global average pooling operation for temporal data.",
  1949. "attributes": [
  1950. {
  1951. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, steps, features)` while `channels_first`\n corresponds to inputs with shape\n `(batch, features, steps)`.",
  1952. "name": "data_format"
  1953. },
  1954. {
  1955. "name": "keepdims",
  1956. "description": "A boolean, whether to keep the temporal dimension or not.\n If `keepdims` is `False` (default), the rank of the tensor is reduced\n for spatial dimensions.\n If `keepdims` is `True`, the temporal dimension are retained with\n length 1.\n The behavior is the same as for `tf.reduce_mean` or `np.mean`."
  1957. }
  1958. ],
  1959. "inputs": [
  1960. {
  1961. "description": "- If `data_format='channels_last'`:\n 3D tensor with shape:\n `(batch_size, steps, features)`\n- If `data_format='channels_first'`:\n 3D tensor with shape:\n `(batch_size, features, steps)`",
  1962. "name": "input"
  1963. }
  1964. ],
  1965. "outputs": [
  1966. {
  1967. "description": "- If `keepdims`=False:\n 2D tensor with shape `(batch_size, features)`.\n- If `keepdims`=True:\n - If `data_format='channels_last'`:\n 3D tensor with shape `(batch_size, 1, features)`\n - If `data_format='channels_first'`:\n 3D tensor with shape `(batch_size, features, 1)`",
  1968. "name": "output"
  1969. }
  1970. ],
  1971. "examples": [
  1972. {
  1973. "code": ">>> input_shape = (2, 3, 4)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.GlobalAveragePooling1D()(x)\n>>> print(y.shape)\n(2, 4)"
  1974. }
  1975. ]
  1976. },
  1977. {
  1978. "name": "GlobalAveragePooling2D",
  1979. "module": "tensorflow.keras.layers",
  1980. "category": "Pool",
  1981. "description": "Global average pooling operation for spatial data.",
  1982. "attributes": [
  1983. {
  1984. "default": "channels_last",
  1985. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, height, width, channels)` while `channels_first`\n corresponds to inputs with shape\n `(batch, channels, height, width)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  1986. "name": "data_format"
  1987. },
  1988. {
  1989. "name": "keepdims",
  1990. "description": "A boolean, whether to keep the spatial dimensions or not.\n If `keepdims` is `False` (default), the rank of the tensor is reduced\n for spatial dimensions.\n If `keepdims` is `True`, the spatial dimensions are retained with\n length 1.\n The behavior is the same as for `tf.reduce_mean` or `np.mean`."
  1991. }
  1992. ],
  1993. "inputs": [
  1994. {
  1995. "description": "- If `data_format='channels_last'`:\n 4D tensor with shape `(batch_size, rows, cols, channels)`.\n- If `data_format='channels_first'`:\n 4D tensor with shape `(batch_size, channels, rows, cols)`.",
  1996. "name": "input"
  1997. }
  1998. ],
  1999. "outputs": [
  2000. {
  2001. "description": "- If `keepdims`=False:\n 2D tensor with shape `(batch_size, channels)`.\n- If `keepdims`=True:\n - If `data_format='channels_last'`:\n 4D tensor with shape `(batch_size, 1, 1, channels)`\n - If `data_format='channels_first'`:\n 4D tensor with shape `(batch_size, channels, 1, 1)`",
  2002. "name": "output"
  2003. }
  2004. ],
  2005. "examples": [
  2006. {
  2007. "code": ">>> input_shape = (2, 4, 5, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.GlobalAveragePooling2D()(x)\n>>> print(y.shape)\n(2, 3)"
  2008. }
  2009. ]
  2010. },
  2011. {
  2012. "name": "GlobalMaxPooling1D",
  2013. "module": "tensorflow.keras.layers",
  2014. "category": "Pool",
  2015. "description": "Global max pooling operation for 1D temporal data.\n\nDownsamples the input representation by taking the maximum value over\nthe time dimension.\n\nFor example:\n\n```\n>>> x = tf.constant([[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]])\n>>> x = tf.reshape(x, [3, 3, 1])\n>>> x\n<tf.Tensor: shape=(3, 3, 1), dtype=float32, numpy=\narray([[[1.], [2.], [3.]],\n [[4.], [5.], [6.]],\n [[7.], [8.], [9.]]], dtype=float32)>\n>>> max_pool_1d = tf.keras.layers.GlobalMaxPooling1D()\n>>> max_pool_1d(x)\n<tf.Tensor: shape=(3, 1), dtype=float32, numpy=\narray([[3.],\n [6.],\n [9.], dtype=float32)>\n```",
  2016. "attributes": [
  2017. {
  2018. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, steps, features)` while `channels_first`\n corresponds to inputs with shape\n `(batch, features, steps)`.",
  2019. "name": "data_format"
  2020. },
  2021. {
  2022. "name": "keepdims",
  2023. "description": "A boolean, whether to keep the temporal dimension or not.\n If `keepdims` is `False` (default), the rank of the tensor is reduced\n for spatial dimensions.\n If `keepdims` is `True`, the temporal dimension are retained with\n length 1.\n The behavior is the same as for `tf.reduce_max` or `np.max`."
  2024. }
  2025. ],
  2026. "inputs": [
  2027. {
  2028. "description": "- If `data_format='channels_last'`:\n 3D tensor with shape:\n `(batch_size, steps, features)`\n- If `data_format='channels_first'`:\n 3D tensor with shape:\n `(batch_size, features, steps)`",
  2029. "name": "input"
  2030. }
  2031. ],
  2032. "outputs": [
  2033. {
  2034. "description": "- If `keepdims`=False:\n 2D tensor with shape `(batch_size, features)`.\n- If `keepdims`=True:\n - If `data_format='channels_last'`:\n 3D tensor with shape `(batch_size, 1, features)`\n - If `data_format='channels_first'`:\n 3D tensor with shape `(batch_size, features, 1)`",
  2035. "name": "output"
  2036. }
  2037. ]
  2038. },
  2039. {
  2040. "name": "GlobalMaxPooling2D",
  2041. "module": "tensorflow.keras.layers",
  2042. "category": "Pool",
  2043. "description": "Global max pooling operation for spatial data.",
  2044. "attributes": [
  2045. {
  2046. "default": "channels_last",
  2047. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, height, width, channels)` while `channels_first`\n corresponds to inputs with shape\n `(batch, channels, height, width)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  2048. "name": "data_format"
  2049. },
  2050. {
  2051. "name": "keepdims",
  2052. "description": "A boolean, whether to keep the spatial dimensions or not.\n If `keepdims` is `False` (default), the rank of the tensor is reduced\n for spatial dimensions.\n If `keepdims` is `True`, the spatial dimensions are retained with\n length 1.\n The behavior is the same as for `tf.reduce_max` or `np.max`."
  2053. }
  2054. ],
  2055. "inputs": [
  2056. {
  2057. "description": "- If `data_format='channels_last'`:\n 4D tensor with shape `(batch_size, rows, cols, channels)`.\n- If `data_format='channels_first'`:\n 4D tensor with shape `(batch_size, channels, rows, cols)`.",
  2058. "name": "input"
  2059. }
  2060. ],
  2061. "outputs": [
  2062. {
  2063. "description": "- If `keepdims`=False:\n 2D tensor with shape `(batch_size, channels)`.\n- If `keepdims`=True:\n - If `data_format='channels_last'`:\n 4D tensor with shape `(batch_size, 1, 1, channels)`\n - If `data_format='channels_first'`:\n 4D tensor with shape `(batch_size, channels, 1, 1)`",
  2064. "name": "output"
  2065. }
  2066. ],
  2067. "examples": [
  2068. {
  2069. "code": ">>> input_shape = (2, 4, 5, 3)\n>>> x = tf.random.normal(input_shape)\n>>> y = tf.keras.layers.GlobalMaxPool2D()(x)\n>>> print(y.shape)\n(2, 3)"
  2070. }
  2071. ]
  2072. },
  2073. {
  2074. "name": "GRU",
  2075. "module": "tensorflow.keras.layers",
  2076. "category": "Layer",
  2077. "description": "Gated Recurrent Unit - Cho et al. 2014.\n\nSee [the Keras RNN API guide](https://www.tensorflow.org/guide/keras/rnn)\nfor details about the usage of RNN API.\n\nBased on available runtime hardware and constraints, this layer\nwill choose different implementations (cuDNN-based or pure-TensorFlow)\nto maximize the performance. If a GPU is available and all\nthe arguments to the layer meet the requirement of the cuDNN kernel\n(see below for details), the layer will use a fast cuDNN implementation.\n\nThe requirements to use the cuDNN implementation are:\n\n1. `activation` == `tanh`\n2. `recurrent_activation` == `sigmoid`\n3. `recurrent_dropout` == 0\n4. `unroll` is `False`\n5. `use_bias` is `True`\n6. `reset_after` is `True`\n7. Inputs, if use masking, are strictly right-padded.\n8. Eager execution is enabled in the outermost context.\n\nThere are two variants of the GRU implementation. The default one is based\non [v3](https://arxiv.org/abs/1406.1078v3) and has reset gate applied to\nhidden state before matrix multiplication. The other one is based on\n[original](https://arxiv.org/abs/1406.1078v1) and has the order reversed.\n\nThe second variant is compatible with CuDNNGRU (GPU-only) and allows\ninference on CPU. Thus it has separate biases for `kernel` and\n`recurrent_kernel`. To use this variant, set `reset_after=True` and\n`recurrent_activation='sigmoid'`.\n\nFor example:\n\n```\n>>> inputs = tf.random.normal([32, 10, 8])\n>>> gru = tf.keras.layers.GRU(4)\n>>> output = gru(inputs)\n>>> print(output.shape)\n(32, 4)\n>>> gru = tf.keras.layers.GRU(4, return_sequences=True, return_state=True)\n>>> whole_sequence_output, final_state = gru(inputs)\n>>> print(whole_sequence_output.shape)\n(32, 10, 4)\n>>> print(final_state.shape)\n(32, 4)\n```",
  2078. "attributes": [
  2079. {
  2080. "default": "tanh",
  2081. "description": "Activation function to use.",
  2082. "name": "activation"
  2083. },
  2084. {
  2085. "default": "hard_sigmoid",
  2086. "description": "Activation function to use\n for the recurrent step.",
  2087. "name": "recurrent_activation"
  2088. },
  2089. {
  2090. "default": true,
  2091. "description": "Boolean, (default `True`), whether the layer uses a bias vector.",
  2092. "name": "use_bias",
  2093. "visible": false
  2094. },
  2095. {
  2096. "default": {
  2097. "class_name": "VarianceScaling",
  2098. "config": {
  2099. "distribution": "uniform",
  2100. "mode": "fan_avg",
  2101. "scale": 1,
  2102. "seed": null
  2103. }
  2104. },
  2105. "description": "Initializer for the `kernel` weights matrix,\n used for the linear transformation of the inputs. Default:\n `glorot_uniform`.",
  2106. "name": "kernel_initializer",
  2107. "visible": false
  2108. },
  2109. {
  2110. "default": {
  2111. "class_name": "Orthogonal",
  2112. "config": {
  2113. "gain": 1,
  2114. "seed": null
  2115. }
  2116. },
  2117. "description": "Initializer for the `recurrent_kernel`\n weights matrix, used for the linear transformation of the recurrent\n state. Default: `orthogonal`.",
  2118. "name": "recurrent_initializer",
  2119. "visible": false
  2120. },
  2121. {
  2122. "default": {
  2123. "class_name": "Zeros",
  2124. "config": {}
  2125. },
  2126. "description": "Initializer for the bias vector. Default: `zeros`.",
  2127. "name": "bias_initializer",
  2128. "visible": false
  2129. },
  2130. {
  2131. "default": 0,
  2132. "description": "Float between 0 and 1. Fraction of the units to drop for the\n linear transformation of the inputs. Default: 0.",
  2133. "name": "dropout"
  2134. },
  2135. {
  2136. "default": 1,
  2137. "description": "Implementation mode, either 1 or 2.\n Mode 1 will structure its operations as a larger number of\n smaller dot products and additions, whereas mode 2 will\n batch them into fewer, larger operations. These modes will\n have different performance profiles on different hardware and\n for different applications. Default: 2.",
  2138. "name": "implementation"
  2139. },
  2140. {
  2141. "default": false,
  2142. "description": "Boolean. Whether to return the last output\n in the output sequence, or the full sequence. Default: `False`.",
  2143. "name": "return_sequences"
  2144. },
  2145. {
  2146. "default": false,
  2147. "description": "Boolean. Whether to return the last state in addition to the\n output. Default: `False`.",
  2148. "name": "return_state"
  2149. },
  2150. {
  2151. "default": false,
  2152. "description": "Boolean (default `False`).\n If True, process the input sequence backwards and return the\n reversed sequence.",
  2153. "name": "go_backwards"
  2154. },
  2155. {
  2156. "default": false,
  2157. "description": "Boolean (default False). If True, the last state\n for each sample at index i in a batch will be used as initial\n state for the sample of index i in the following batch.",
  2158. "name": "stateful"
  2159. },
  2160. {
  2161. "default": false,
  2162. "description": "Boolean (default False).\n If True, the network will be unrolled,\n else a symbolic loop will be used.\n Unrolling can speed-up a RNN,\n although it tends to be more memory-intensive.\n Unrolling is only suitable for short sequences.",
  2163. "name": "unroll"
  2164. },
  2165. {
  2166. "description": "Positive integer, dimensionality of the output space.",
  2167. "name": "units"
  2168. },
  2169. {
  2170. "description": "Regularizer function applied to the `kernel` weights\n matrix. Default: `None`.",
  2171. "name": "kernel_regularizer",
  2172. "visible": false
  2173. },
  2174. {
  2175. "description": "Regularizer function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  2176. "name": "recurrent_regularizer",
  2177. "visible": false
  2178. },
  2179. {
  2180. "description": "Regularizer function applied to the bias vector.",
  2181. "name": "bias_regularizer",
  2182. "visible": false
  2183. },
  2184. {
  2185. "description": "Regularizer function applied to the output of the\n layer (its \"activation\"). Default: `None`.",
  2186. "name": "activity_regularizer",
  2187. "visible": false
  2188. },
  2189. {
  2190. "description": "Constraint function applied to the `kernel` weights\n matrix. Default: `None`.",
  2191. "name": "kernel_constraint"
  2192. },
  2193. {
  2194. "description": "Constraint function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  2195. "name": "recurrent_constraint"
  2196. },
  2197. {
  2198. "description": "Constraint function applied to the bias vector. Default:\n `None`.",
  2199. "name": "bias_constraint"
  2200. },
  2201. {
  2202. "description": "Float between 0 and 1. Fraction of the units to drop\n for the linear transformation of the recurrent state. Default: 0.",
  2203. "name": "recurrent_dropout"
  2204. },
  2205. {
  2206. "description": "`None`.",
  2207. "name": "Default"
  2208. },
  2209. {
  2210. "description": "GRU convention (whether to apply reset gate after or\n before matrix multiplication). False = \"before\",\n True = \"after\" (default and cuDNN compatible).",
  2211. "name": "reset_after"
  2212. },
  2213. {
  2214. "description": "The shape format of the `inputs` and `outputs` tensors.\n If True, the inputs and outputs will be in shape\n `[timesteps, batch, feature]`, whereas in the False case, it will be\n `[batch, timesteps, feature]`. Using `time_major = True` is a bit more\n efficient because it avoids transposes at the beginning and end of the\n RNN calculation. However, most TensorFlow data is batch-major, so by\n default this function accepts input and emits output in batch-major\n form.",
  2215. "name": "time_major"
  2216. }
  2217. ],
  2218. "inputs": [
  2219. {
  2220. "name": "input"
  2221. },
  2222. {
  2223. "name": "kernel"
  2224. },
  2225. {
  2226. "name": "recurrent_kernel"
  2227. },
  2228. {
  2229. "name": "bias"
  2230. }
  2231. ],
  2232. "outputs": [
  2233. {
  2234. "name": "output"
  2235. }
  2236. ],
  2237. "references": [
  2238. {
  2239. "description": "[Learning Phrase Representations using RNN Encoder-Decoder for Statistical Machine Translation](https://arxiv.org/abs/1406.1078)"
  2240. },
  2241. {
  2242. "description": "[On the Properties of Neural Machine Translation: Encoder-Decoder Approaches](https://arxiv.org/abs/1409.1259)"
  2243. },
  2244. {
  2245. "description": "[Empirical Evaluation of Gated Recurrent Neural Networks on Sequence Modeling](https://arxiv.org/abs/1412.3555v1)"
  2246. },
  2247. {
  2248. "description": "[A Theoretically Grounded Application of Dropout in Recurrent Neural Networks](https://arxiv.org/abs/1512.05287)"
  2249. }
  2250. ]
  2251. },
  2252. {
  2253. "name": "GRUCell",
  2254. "module": "tensorflow.keras.layers",
  2255. "description": "Cell class for the GRU layer.\n\nSee [the Keras RNN API guide](https://www.tensorflow.org/guide/keras/rnn)\nfor details about the usage of RNN API.\n\nThis class processes one step within the whole time sequence input, whereas\n`tf.keras.layer.GRU` processes the whole sequence.\n\nFor example:\n\n```\n>>> inputs = tf.random.normal([32, 10, 8])\n>>> rnn = tf.keras.layers.RNN(tf.keras.layers.GRUCell(4))\n>>> output = rnn(inputs)\n>>> print(output.shape)\n(32, 4)\n>>> rnn = tf.keras.layers.RNN(\n... tf.keras.layers.GRUCell(4),\n... return_sequences=True,\n... return_state=True)\n>>> whole_sequence_output, final_state = rnn(inputs)\n>>> print(whole_sequence_output.shape)\n(32, 10, 4)\n>>> print(final_state.shape)\n(32, 4)\n```",
  2256. "attributes": [
  2257. {
  2258. "description": "Positive integer, dimensionality of the output space.",
  2259. "name": "units"
  2260. },
  2261. {
  2262. "description": "Activation function to use. Default: hyperbolic tangent\n (`tanh`). If you pass None, no activation is applied\n (ie. \"linear\" activation: `a(x) = x`).",
  2263. "name": "activation"
  2264. },
  2265. {
  2266. "description": "Activation function to use for the recurrent step.",
  2267. "name": "recurrent_activation"
  2268. },
  2269. {
  2270. "default": true,
  2271. "description": "Boolean, (default `True`), whether the layer uses a bias vector.",
  2272. "name": "use_bias",
  2273. "visible": false
  2274. },
  2275. {
  2276. "description": "Initializer for the `kernel` weights matrix,\n used for the linear transformation of the inputs. Default:\n `glorot_uniform`.",
  2277. "name": "kernel_initializer",
  2278. "visible": false
  2279. },
  2280. {
  2281. "description": "Initializer for the `recurrent_kernel`\n weights matrix, used for the linear transformation of the recurrent\n state. Default: `orthogonal`.",
  2282. "name": "recurrent_initializer",
  2283. "visible": false
  2284. },
  2285. {
  2286. "description": "Initializer for the bias vector. Default: `zeros`.",
  2287. "name": "bias_initializer",
  2288. "visible": false
  2289. },
  2290. {
  2291. "description": "Regularizer function applied to the `kernel` weights\n matrix. Default: `None`.",
  2292. "name": "kernel_regularizer",
  2293. "visible": false
  2294. },
  2295. {
  2296. "description": "Regularizer function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  2297. "name": "recurrent_regularizer",
  2298. "visible": false
  2299. },
  2300. {
  2301. "description": "Regularizer function applied to the bias vector.",
  2302. "name": "bias_regularizer",
  2303. "visible": false
  2304. },
  2305. {
  2306. "description": "Constraint function applied to the `kernel` weights\n matrix. Default: `None`.",
  2307. "name": "kernel_constraint"
  2308. },
  2309. {
  2310. "description": "Constraint function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  2311. "name": "recurrent_constraint"
  2312. },
  2313. {
  2314. "description": "Constraint function applied to the bias vector. Default:\n `None`.",
  2315. "name": "bias_constraint"
  2316. },
  2317. {
  2318. "default": 0,
  2319. "description": "Float between 0 and 1. Fraction of the units to drop for the\n linear transformation of the inputs. Default: 0.",
  2320. "name": "dropout"
  2321. },
  2322. {
  2323. "default": 0,
  2324. "description": "Float between 0 and 1. Fraction of the units to drop\n for the linear transformation of the recurrent state. Default: 0.",
  2325. "name": "recurrent_dropout"
  2326. },
  2327. {
  2328. "description": "Implementation mode, either 1 or 2.\n Mode 1 will structure its operations as a larger number of\n smaller dot products and additions, whereas mode 2 (default) will\n batch them into fewer, larger operations. These modes will\n have different performance profiles on different hardware and\n for different applications. Default: 2.",
  2329. "name": "implementation"
  2330. },
  2331. {
  2332. "description": "`None`.",
  2333. "name": "Default"
  2334. },
  2335. {
  2336. "description": "GRU convention (whether to apply reset gate after or\n before matrix multiplication). False = \"before\",\n True = \"after\" (default and cuDNN compatible).",
  2337. "name": "reset_after"
  2338. }
  2339. ]
  2340. },
  2341. {
  2342. "name": "HardSigmoid",
  2343. "category": "Activation"
  2344. },
  2345. {
  2346. "name": "InputLayer",
  2347. "module": "tensorflow.keras.layers",
  2348. "category": "Data",
  2349. "description": "Layer to be used as an entry point into a Network (a graph of layers).\n\nIt can either wrap an existing tensor (pass an `input_tensor` argument)\nor create a placeholder tensor (pass arguments `input_shape`, and\noptionally, `dtype`).\n\nIt is generally recommend to use the Keras Functional model via `Input`,\n(which creates an `InputLayer`) without directly using `InputLayer`.\n\nWhen using `InputLayer` with the Keras Sequential model, it can be skipped\nby moving the `input_shape` parameter to the first layer after the\n`InputLayer`.\n\nThis class can create placeholders for `tf.Tensors`, `tf.SparseTensors`, and\n`tf.RaggedTensors` by choosing `sparse=True` or `ragged=True`. Note that\n`sparse` and `ragged` can't be configured to `True` at the same time.",
  2350. "attributes": [
  2351. {
  2352. "description": "Shape tuple (not including the batch axis), or\n `TensorShape` instance (not including the batch axis).",
  2353. "name": "input_shape"
  2354. },
  2355. {
  2356. "description": "Optional input batch size (integer or `None`).",
  2357. "name": "batch_size"
  2358. },
  2359. {
  2360. "description": "Optional datatype of the input. When not provided, the Keras\n default `float` type will be used.",
  2361. "name": "dtype"
  2362. },
  2363. {
  2364. "description": "Optional tensor to use as layer input. If set, the layer\n will use the `tf.TypeSpec` of this tensor rather\n than creating a new placeholder tensor.",
  2365. "name": "input_tensor"
  2366. },
  2367. {
  2368. "description": "Boolean, whether the placeholder created is meant to be sparse.\n Default to `False`.",
  2369. "name": "sparse"
  2370. },
  2371. {
  2372. "description": "Boolean, whether the placeholder created is meant to be ragged.\n In this case, values of `None` in the `shape` argument represent\n ragged dimensions. For more information about `tf.RaggedTensor`, see\n [this guide](https://www.tensorflow.org/guide/ragged_tensor).\n Default to `False`.",
  2373. "name": "ragged"
  2374. },
  2375. {
  2376. "description": "Optional name of the layer (string).",
  2377. "name": "name"
  2378. },
  2379. {
  2380. "description": "A `tf.TypeSpec` object to create Input from. This\n `tf.TypeSpec` represents the entire batch. When provided, all other\n args except name must be `None`.",
  2381. "name": "type_spec"
  2382. }
  2383. ],
  2384. "examples": [
  2385. {
  2386. "code": "# With explicit InputLayer.\nmodel = tf.keras.Sequential([\n tf.keras.layers.InputLayer(input_shape=(4,)),\n tf.keras.layers.Dense(8)])\nmodel.compile(tf.keras.optimizers.RMSprop(0.001), loss='mse')\nmodel.fit(np.zeros((10, 4)),\n np.ones((10, 8)))\n\n# Without InputLayer and let the first layer to have the input_shape.\n# Keras will add a input for the model behind the scene.\nmodel = tf.keras.Sequential([\n tf.keras.layers.Dense(8, input_shape=(4,))])\nmodel.compile(tf.keras.optimizers.RMSprop(0.001), loss='mse')\nmodel.fit(np.zeros((10, 4)),\n np.ones((10, 8)))"
  2387. }
  2388. ]
  2389. },
  2390. {
  2391. "name": "InputSpec",
  2392. "module": "tensorflow.keras.layers",
  2393. "category": "Data",
  2394. "description": "Specifies the rank, dtype and shape of every input to a layer.\n\nLayers can expose (if appropriate) an `input_spec` attribute:\nan instance of `InputSpec`, or a nested structure of `InputSpec` instances\n(one per input tensor). These objects enable the layer to run input\ncompatibility checks for input structure, input rank, input shape, and\ninput dtype.\n\nA None entry in a shape is compatible with any dimension,\na None shape is compatible with any shape.",
  2395. "attributes": [
  2396. {
  2397. "description": "Expected DataType of the input.",
  2398. "name": "dtype"
  2399. },
  2400. {
  2401. "description": "Shape tuple, expected shape of the input\n (may include None for unchecked axes). Includes the batch size.",
  2402. "name": "shape"
  2403. },
  2404. {
  2405. "description": "Integer, expected rank of the input.",
  2406. "name": "ndim"
  2407. },
  2408. {
  2409. "description": "Integer, maximum rank of the input.",
  2410. "name": "max_ndim"
  2411. },
  2412. {
  2413. "description": "Integer, minimum rank of the input.",
  2414. "name": "min_ndim"
  2415. },
  2416. {
  2417. "description": "Dictionary mapping integer axes to\n a specific dimension value.",
  2418. "name": "axes"
  2419. },
  2420. {
  2421. "description": "If True, then allow inputs of rank N+1 as long\n as the last axis of the input is 1, as well as inputs of rank N-1\n as long as the last axis of the spec is 1.",
  2422. "name": "allow_last_axis_squeeze"
  2423. },
  2424. {
  2425. "description": "Expected key corresponding to this input when passing data as\n a dictionary.",
  2426. "name": "name"
  2427. }
  2428. ],
  2429. "examples": [
  2430. {
  2431. "code": "class MyLayer(Layer):\n def __init__(self):\n super(MyLayer, self).__init__()\n # The layer will accept inputs with\n # shape (?, 28, 28) & (?, 28, 28, 1)\n # and raise an appropriate error message otherwise.\n self.input_spec = InputSpec(\n shape=(None, 28, 28, 1),\n allow_last_axis_squeeze=True)"
  2432. }
  2433. ]
  2434. },
  2435. {
  2436. "name": "Lambda",
  2437. "module": "tensorflow.keras.layers",
  2438. "description": "Wraps arbitrary expressions as a `Layer` object.\n\nThe `Lambda` layer exists so that arbitrary expressions can be used\nas a `Layer` when constructing `Sequential`\nand Functional API models. `Lambda` layers are best suited for simple\noperations or quick experimentation. For more advanced use cases, follow\n[this guide](\nhttps://www.tensorflow.org/guide/keras/custom_layers_and_models)\nfor subclassing `tf.keras.layers.Layer`.\n\nWARNING: `tf.keras.layers.Lambda` layers have (de)serialization limitations!\n\nThe main reason to subclass `tf.keras.layers.Layer` instead of using a\n`Lambda` layer is saving and inspecting a Model. `Lambda` layers\nare saved by serializing the Python bytecode, which is fundamentally\nnon-portable. They should only be loaded in the same environment where\nthey were saved. Subclassed layers can be saved in a more portable way\nby overriding their `get_config` method. Models that rely on\nsubclassed Layers are also often easier to visualize and reason about.",
  2439. "attributes": [
  2440. {
  2441. "description": "The function to be evaluated. Takes input tensor as first\n argument.",
  2442. "name": "function"
  2443. },
  2444. {
  2445. "description": "Expected output shape from function. This argument can be\n inferred if not explicitly provided. Can be a tuple or function. If a\n tuple, it only specifies the first dimension onward;\n sample dimension is assumed either the same as the input:\n `output_shape = (input_shape[0], ) + output_shape` or, the input is\n `None` and the sample dimension is also `None`:\n `output_shape = (None, ) + output_shape` If a function, it specifies the\n entire shape as a function of the input shape:\n `output_shape = f(input_shape)`",
  2446. "name": "output_shape"
  2447. },
  2448. {
  2449. "description": "Optional dictionary of keyword arguments to be passed to the\n function.\nInput shape: Arbitrary. Use the keyword argument input_shape (tuple of\n integers, does not include the samples axis) when using this layer as the\n first layer in a model.\nOutput shape: Specified by `output_shape` argument",
  2450. "name": "arguments"
  2451. },
  2452. {
  2453. "description": "Either None (indicating no masking) or a callable with the same\n signature as the `compute_mask` layer method, or a tensor that will be\n returned as output mask regardless of what the input is.",
  2454. "name": "mask"
  2455. }
  2456. ],
  2457. "inputs": [
  2458. {
  2459. "description": "Arbitrary. Use the keyword argument input_shape (tuple of\nintegers, does not include the samples axis) when using this layer as the\nfirst layer in a model.",
  2460. "name": "inputs",
  2461. "list": true
  2462. }
  2463. ],
  2464. "outputs": [
  2465. {
  2466. "description": "Specified by `output_shape` argument",
  2467. "name": "output"
  2468. }
  2469. ],
  2470. "examples": [
  2471. {
  2472. "code": "# add a x -> x^2 layer\nmodel.add(Lambda(lambda x: x ** 2))"
  2473. },
  2474. {
  2475. "code": "# add a layer that returns the concatenation\n# of the positive part of the input and\n# the opposite of the negative part\n\ndef antirectifier(x):\n x -= K.mean(x, axis=1, keepdims=True)\n x = K.l2_normalize(x, axis=1)\n pos = K.relu(x)\n neg = K.relu(-x)\n return K.concatenate([pos, neg], axis=1)\n\nmodel.add(Lambda(antirectifier))"
  2476. }
  2477. ]
  2478. },
  2479. {
  2480. "name": "LeakyReLU",
  2481. "module": "tensorflow.keras.layers",
  2482. "category": "Activation",
  2483. "description": "Leaky version of a Rectified Linear Unit.\n\nIt allows a small gradient when the unit is not active:\n\n```\n f(x) = alpha * x if x < 0\n f(x) = x if x >= 0\n```",
  2484. "attributes": [
  2485. {
  2486. "description": "Float >= 0. Negative slope coefficient. Default to 0.3.",
  2487. "name": "alpha"
  2488. }
  2489. ],
  2490. "inputs": [
  2491. {
  2492. "description": "Arbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the batch axis)\nwhen using this layer as the first layer in a model.",
  2493. "name": "input"
  2494. }
  2495. ],
  2496. "outputs": [
  2497. {
  2498. "description": "Same shape as the input.",
  2499. "name": "output"
  2500. }
  2501. ],
  2502. "references": [
  2503. {
  2504. "description": "[Rectifier Nonlinearities Improve Neural Network Acoustic Models]( https://ai.stanford.edu/~amaas/papers/relu_hybrid_icml2013_final.pdf)"
  2505. }
  2506. ],
  2507. "examples": [
  2508. {
  2509. "code": ">>> layer = tf.keras.layers.LeakyReLU()\n>>> output = layer([-3.0, -1.0, 0.0, 2.0])\n>>> list(output.numpy())\n[-0.9, -0.3, 0.0, 2.0]\n>>> layer = tf.keras.layers.LeakyReLU(alpha=0.1)\n>>> output = layer([-3.0, -1.0, 0.0, 2.0])\n>>> list(output.numpy())\n[-0.3, -0.1, 0.0, 2.0]"
  2510. }
  2511. ]
  2512. },
  2513. {
  2514. "name": "LocallyConnected1D",
  2515. "module": "tensorflow.keras.layers",
  2516. "category": "Layer",
  2517. "description": "Locally-connected layer for 1D inputs.\n\nThe `LocallyConnected1D` layer works similarly to\nthe `Conv1D` layer, except that weights are unshared,\nthat is, a different set of filters is applied at each different patch\nof the input.\n\nNote: layer attributes cannot be modified after the layer has been called\nonce (except the `trainable` attribute).",
  2518. "attributes": [
  2519. {
  2520. "description": "Integer, the dimensionality of the output space (i.e. the\n number of output filters in the convolution).",
  2521. "name": "filters"
  2522. },
  2523. {
  2524. "description": "An integer or tuple/list of a single integer, specifying\n the length of the 1D convolution window.",
  2525. "name": "kernel_size"
  2526. },
  2527. {
  2528. "description": "An integer or tuple/list of a single integer, specifying the\n stride length of the convolution.",
  2529. "name": "strides"
  2530. },
  2531. {
  2532. "description": "Currently only supports `\"valid\"` (case-insensitive). `\"same\"`\n may be supported in the future. `\"valid\"` means no padding.",
  2533. "name": "padding"
  2534. },
  2535. {
  2536. "description": "Activation function to use. If you don't specify anything,\n no activation is applied (ie. \"linear\" activation: `a(x) = x`).",
  2537. "name": "activation"
  2538. },
  2539. {
  2540. "description": "Boolean, whether the layer uses a bias vector.",
  2541. "name": "use_bias"
  2542. },
  2543. {
  2544. "description": "Initializer for the `kernel` weights matrix.",
  2545. "name": "kernel_initializer",
  2546. "visible": false
  2547. },
  2548. {
  2549. "description": "Initializer for the bias vector.",
  2550. "name": "bias_initializer",
  2551. "visible": false
  2552. },
  2553. {
  2554. "description": "Regularizer function applied to the `kernel` weights\n matrix.",
  2555. "name": "kernel_regularizer",
  2556. "visible": false
  2557. },
  2558. {
  2559. "description": "Regularizer function applied to the bias vector.",
  2560. "name": "bias_regularizer",
  2561. "visible": false
  2562. },
  2563. {
  2564. "description": "Regularizer function applied to the output of the\n layer (its \"activation\")..",
  2565. "name": "activity_regularizer",
  2566. "visible": false
  2567. },
  2568. {
  2569. "description": "Constraint function applied to the kernel matrix.",
  2570. "name": "kernel_constraint"
  2571. },
  2572. {
  2573. "description": "Constraint function applied to the bias vector.",
  2574. "name": "bias_constraint"
  2575. },
  2576. {
  2577. "default": "channels_last",
  2578. "description": "A string, one of `channels_last` (default) or\n `channels_first`. The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape `(batch, length,\n channels)` while `channels_first` corresponds to inputs with shape\n `(batch, channels, length)`. It defaults to the `image_data_format`\n value found in your Keras config file at `~/.keras/keras.json`. If you\n never set it, then it will be \"channels_last\".",
  2579. "name": "data_format"
  2580. },
  2581. {
  2582. "description": "implementation mode, either `1`, `2`, or `3`. `1` loops\n over input spatial locations to perform the forward pass. It is\n memory-efficient but performs a lot of (small) ops. `2` stores layer\n weights in a dense but sparsely-populated 2D matrix and implements the\n forward pass as a single matrix-multiply. It uses a lot of RAM but\n performs few (large) ops. `3` stores layer weights in a sparse tensor\n and implements the forward pass as a single sparse matrix-multiply.\n How to choose:\n `1`: large, dense models,\n `2`: small models,\n `3`: large, sparse models, where \"large\" stands for large\n input/output activations (i.e. many `filters`, `input_filters`,\n large `input_size`, `output_size`), and \"sparse\" stands for few\n connections between inputs and outputs, i.e. small ratio\n `filters * input_filters * kernel_size / (input_size * strides)`,\n where inputs to and outputs of the layer are assumed to have\n shapes `(input_size, input_filters)`, `(output_size, filters)`\n respectively. It is recommended to benchmark each in the setting\n of interest to pick the most efficient one (in terms of speed and\n memory usage). Correct choice of implementation can lead to\n dramatic speed improvements (e.g. 50X), potentially at the expense\n of RAM. Also, only `padding=\"valid\"` is supported by\n `implementation=1`.",
  2583. "name": "implementation"
  2584. }
  2585. ],
  2586. "inputs": [
  2587. {
  2588. "description": "3D tensor with shape: `(batch_size, steps, input_dim)`",
  2589. "name": "input"
  2590. }
  2591. ],
  2592. "outputs": [
  2593. {
  2594. "description": "3D tensor with shape: `(batch_size, new_steps, filters)` `steps` value\n might have changed due to padding or strides.",
  2595. "name": "output"
  2596. }
  2597. ],
  2598. "examples": [
  2599. {
  2600. "code": " # apply a unshared weight convolution 1d of length 3 to a sequence with\n # 10 timesteps, with 64 output filters\n model = Sequential()\n model.add(LocallyConnected1D(64, 3, input_shape=(10, 32)))\n # now model.output_shape == (None, 8, 64)\n # add a new conv1d on top\n model.add(LocallyConnected1D(32, 3))\n # now model.output_shape == (None, 6, 32)"
  2601. }
  2602. ]
  2603. },
  2604. {
  2605. "name": "LocallyConnected2D",
  2606. "module": "tensorflow.keras.layers",
  2607. "category": "Layer",
  2608. "description": "Locally-connected layer for 2D inputs.\n\nThe `LocallyConnected2D` layer works similarly\nto the `Conv2D` layer, except that weights are unshared,\nthat is, a different set of filters is applied at each\ndifferent patch of the input.\n\nNote: layer attributes cannot be modified after the layer has been called\nonce (except the `trainable` attribute).",
  2609. "attributes": [
  2610. {
  2611. "description": "Integer, the dimensionality of the output space (i.e. the\n number of output filters in the convolution).",
  2612. "name": "filters"
  2613. },
  2614. {
  2615. "description": "An integer or tuple/list of 2 integers, specifying the\n width and height of the 2D convolution window. Can be a single integer\n to specify the same value for all spatial dimensions.",
  2616. "name": "kernel_size"
  2617. },
  2618. {
  2619. "description": "An integer or tuple/list of 2 integers, specifying the strides\n of the convolution along the width and height. Can be a single integer\n to specify the same value for all spatial dimensions.",
  2620. "name": "strides"
  2621. },
  2622. {
  2623. "description": "Currently only support `\"valid\"` (case-insensitive). `\"same\"`\n will be supported in future. `\"valid\"` means no padding.",
  2624. "name": "padding"
  2625. },
  2626. {
  2627. "default": "channels_last",
  2628. "description": "A string, one of `channels_last` (default) or\n `channels_first`. The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape `(batch, height,\n width, channels)` while `channels_first` corresponds to inputs with\n shape\n `(batch, channels, height, width)`. It defaults to the\n `image_data_format` value found in your Keras config file at\n `~/.keras/keras.json`. If you never set it, then it will be\n \"channels_last\".",
  2629. "name": "data_format"
  2630. },
  2631. {
  2632. "description": "Activation function to use. If you don't specify anything,\n no activation is applied (ie. \"linear\" activation: `a(x) = x`).",
  2633. "name": "activation"
  2634. },
  2635. {
  2636. "description": "Boolean, whether the layer uses a bias vector.",
  2637. "name": "use_bias",
  2638. "visible": false
  2639. },
  2640. {
  2641. "description": "Initializer for the `kernel` weights matrix.",
  2642. "name": "kernel_initializer",
  2643. "visible": false
  2644. },
  2645. {
  2646. "description": "Initializer for the bias vector.",
  2647. "name": "bias_initializer",
  2648. "visible": false
  2649. },
  2650. {
  2651. "description": "Regularizer function applied to the `kernel` weights\n matrix.",
  2652. "name": "kernel_regularizer",
  2653. "visible": false
  2654. },
  2655. {
  2656. "description": "Regularizer function applied to the bias vector.",
  2657. "name": "bias_regularizer",
  2658. "visible": false
  2659. },
  2660. {
  2661. "description": "Regularizer function applied to the output of the\n layer (its \"activation\").",
  2662. "name": "activity_regularizer"
  2663. },
  2664. {
  2665. "description": "Constraint function applied to the kernel matrix.",
  2666. "name": "kernel_constraint"
  2667. },
  2668. {
  2669. "description": "Constraint function applied to the bias vector.",
  2670. "name": "bias_constraint"
  2671. },
  2672. {
  2673. "description": "implementation mode, either `1`, `2`, or `3`. `1` loops\n over input spatial locations to perform the forward pass. It is\n memory-efficient but performs a lot of (small) ops. `2` stores layer\n weights in a dense but sparsely-populated 2D matrix and implements the\n forward pass as a single matrix-multiply. It uses a lot of RAM but\n performs few (large) ops. `3` stores layer weights in a sparse tensor\n and implements the forward pass as a single sparse matrix-multiply.\n How to choose:\n `1`: large, dense models,\n `2`: small models,\n `3`: large, sparse models, where \"large\" stands for large\n input/output activations (i.e. many `filters`, `input_filters`,\n large `np.prod(input_size)`, `np.prod(output_size)`), and \"sparse\"\n stands for few connections between inputs and outputs, i.e. small\n ratio `filters * input_filters * np.prod(kernel_size) /\n (np.prod(input_size) * np.prod(strides))`, where inputs to and\n outputs of the layer are assumed to have shapes `input_size +\n (input_filters,)`, `output_size + (filters,)` respectively. It is\n recommended to benchmark each in the setting of interest to pick\n the most efficient one (in terms of speed and memory usage).\n Correct choice of implementation can lead to dramatic speed\n improvements (e.g. 50X), potentially at the expense of RAM. Also,\n only `padding=\"valid\"` is supported by `implementation=1`.",
  2674. "name": "implementation"
  2675. }
  2676. ],
  2677. "inputs": [
  2678. {
  2679. "description": "4D tensor with shape: `(samples, channels, rows, cols)` if\n data_format='channels_first'\nor 4D tensor with shape: `(samples, rows, cols, channels)` if\n data_format='channels_last'.",
  2680. "name": "input"
  2681. }
  2682. ],
  2683. "outputs": [
  2684. {
  2685. "description": "4D tensor with shape: `(samples, filters, new_rows, new_cols)` if\n data_format='channels_first'\nor 4D tensor with shape: `(samples, new_rows, new_cols, filters)` if\n data_format='channels_last'. `rows` and `cols` values might have\n changed due to padding.",
  2686. "name": "output"
  2687. }
  2688. ],
  2689. "examples": [
  2690. {
  2691. "code": " # apply a 3x3 unshared weights convolution with 64 output filters on a\n 32x32 image\n # with `data_format=\"channels_last\"`:\n model = Sequential()\n model.add(LocallyConnected2D(64, (3, 3), input_shape=(32, 32, 3)))\n # now model.output_shape == (None, 30, 30, 64)\n # notice that this layer will consume (30*30)*(3*3*3*64) + (30*30)*64\n parameters\n\n # add a 3x3 unshared weights convolution on top, with 32 output filters:\n model.add(LocallyConnected2D(32, (3, 3)))\n # now model.output_shape == (None, 28, 28, 32)"
  2692. }
  2693. ]
  2694. },
  2695. {
  2696. "name": "LSTM",
  2697. "module": "tensorflow.keras.layers",
  2698. "category": "Layer",
  2699. "description": "Long Short-Term Memory layer - Hochreiter 1997.\n\nSee [the Keras RNN API guide](https://www.tensorflow.org/guide/keras/rnn)\nfor details about the usage of RNN API.\n\nBased on available runtime hardware and constraints, this layer\nwill choose different implementations (cuDNN-based or pure-TensorFlow)\nto maximize the performance. If a GPU is available and all\nthe arguments to the layer meet the requirement of the cuDNN kernel\n(see below for details), the layer will use a fast cuDNN implementation.\n\nThe requirements to use the cuDNN implementation are:\n\n1. `activation` == `tanh`\n2. `recurrent_activation` == `sigmoid`\n3. `recurrent_dropout` == 0\n4. `unroll` is `False`\n5. `use_bias` is `True`\n6. Inputs, if use masking, are strictly right-padded.\n7. Eager execution is enabled in the outermost context.\n\nFor example:\n\n```\n>>> inputs = tf.random.normal([32, 10, 8])\n>>> lstm = tf.keras.layers.LSTM(4)\n>>> output = lstm(inputs)\n>>> print(output.shape)\n(32, 4)\n>>> lstm = tf.keras.layers.LSTM(4, return_sequences=True, return_state=True)\n>>> whole_seq_output, final_memory_state, final_carry_state = lstm(inputs)\n>>> print(whole_seq_output.shape)\n(32, 10, 4)\n>>> print(final_memory_state.shape)\n(32, 4)\n>>> print(final_carry_state.shape)\n(32, 4)\n```",
  2700. "attributes": [
  2701. {
  2702. "description": "Positive integer, dimensionality of the output space.",
  2703. "name": "units"
  2704. },
  2705. {
  2706. "default": "tanh",
  2707. "description": "Activation function to use.",
  2708. "name": "activation"
  2709. },
  2710. {
  2711. "default": "hard_sigmoid",
  2712. "description": "Activation function to use for the recurrent step.",
  2713. "name": "recurrent_activation"
  2714. },
  2715. {
  2716. "description": "Boolean (default `True`), whether the layer uses a bias vector.",
  2717. "name": "use_bias",
  2718. "visible": false
  2719. },
  2720. {
  2721. "description": "Initializer for the `kernel` weights matrix, used for\n the linear transformation of the inputs. Default: `glorot_uniform`.",
  2722. "name": "kernel_initializer",
  2723. "visible": false
  2724. },
  2725. {
  2726. "description": "Initializer for the `recurrent_kernel` weights\n matrix, used for the linear transformation of the recurrent state.",
  2727. "name": "recurrent_initializer",
  2728. "visible": false
  2729. },
  2730. {
  2731. "description": "Initializer for the bias vector. Default: `zeros`.",
  2732. "name": "bias_initializer",
  2733. "visible": false
  2734. },
  2735. {
  2736. "default": true,
  2737. "description": "Boolean (default `True`). If True, add 1 to the bias of\n the forget gate at initialization. Setting it to true will also force\n `bias_initializer=\"zeros\"`. This is recommended in [Jozefowicz et\n al.](http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf).",
  2738. "name": "unit_forget_bias"
  2739. },
  2740. {
  2741. "description": "Regularizer function applied to the `kernel` weights\n matrix. Default: `None`.",
  2742. "name": "kernel_regularizer",
  2743. "visible": false
  2744. },
  2745. {
  2746. "description": "Regularizer function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  2747. "name": "recurrent_regularizer",
  2748. "visible": false
  2749. },
  2750. {
  2751. "description": "Regularizer function applied to the bias vector.",
  2752. "name": "bias_regularizer",
  2753. "visible": false
  2754. },
  2755. {
  2756. "description": "Regularizer function applied to the output of the\n layer (its \"activation\"). Default: `None`.",
  2757. "name": "activity_regularizer",
  2758. "visible": false
  2759. },
  2760. {
  2761. "description": "Constraint function applied to the `kernel` weights\n matrix. Default: `None`.",
  2762. "name": "kernel_constraint",
  2763. "visible": false
  2764. },
  2765. {
  2766. "description": "Constraint function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  2767. "name": "recurrent_constraint",
  2768. "visible": false
  2769. },
  2770. {
  2771. "description": "Constraint function applied to the bias vector. Default:\n `None`.",
  2772. "name": "bias_constraint",
  2773. "visible": false
  2774. },
  2775. {
  2776. "default": 0,
  2777. "description": "Float between 0 and 1. Fraction of the units to drop for the\n linear transformation of the inputs. Default: 0.",
  2778. "name": "dropout"
  2779. },
  2780. {
  2781. "default": 0,
  2782. "description": "Float between 0 and 1. Fraction of the units to drop\n for the linear transformation of the recurrent state. Default: 0.",
  2783. "name": "recurrent_dropout"
  2784. },
  2785. {
  2786. "default": 1,
  2787. "description": "Implementation mode, either 1 or 2. Mode 1 will structure\n its operations as a larger number of smaller dot products and additions,\n whereas mode 2 will batch them into fewer, larger operations. These modes\n will have different performance profiles on different hardware and for\n different applications. Default: 2.",
  2788. "name": "implementation"
  2789. },
  2790. {
  2791. "default": false,
  2792. "description": "Boolean. Whether to return the last output in the output\n sequence, or the full sequence. Default: `False`.",
  2793. "name": "return_sequences"
  2794. },
  2795. {
  2796. "default": false,
  2797. "description": "Boolean. Whether to return the last state in addition to the\n output. Default: `False`.",
  2798. "name": "return_state"
  2799. },
  2800. {
  2801. "default": false,
  2802. "description": "Boolean (default `False`). If True, process the input\n sequence backwards and return the reversed sequence.",
  2803. "name": "go_backwards"
  2804. },
  2805. {
  2806. "default": false,
  2807. "description": "Boolean (default `False`). If True, the last state for each\n sample at index i in a batch will be used as initial state for the sample\n of index i in the following batch.",
  2808. "name": "stateful"
  2809. },
  2810. {
  2811. "default": false,
  2812. "description": "Boolean (default `False`). If True, the network will be unrolled,\n else a symbolic loop will be used. Unrolling can speed-up a RNN,\n although it tends to be more memory-intensive. Unrolling is only\n suitable for short sequences.",
  2813. "name": "unroll"
  2814. },
  2815. {
  2816. "description": "`None`.",
  2817. "name": "Default"
  2818. },
  2819. {
  2820. "description": "The shape format of the `inputs` and `outputs` tensors.\n If True, the inputs and outputs will be in shape\n `[timesteps, batch, feature]`, whereas in the False case, it will be\n `[batch, timesteps, feature]`. Using `time_major = True` is a bit more\n efficient because it avoids transposes at the beginning and end of the\n RNN calculation. However, most TensorFlow data is batch-major, so by\n default this function accepts input and emits output in batch-major\n form.",
  2821. "name": "time_major"
  2822. }
  2823. ],
  2824. "inputs": [
  2825. {
  2826. "name": "input"
  2827. },
  2828. {
  2829. "name": "kernel"
  2830. },
  2831. {
  2832. "name": "recurrent_kernel"
  2833. },
  2834. {
  2835. "name": "bias"
  2836. }
  2837. ],
  2838. "outputs": [
  2839. {
  2840. "name": "output"
  2841. }
  2842. ],
  2843. "references": [
  2844. {
  2845. "description": "[Long short-term memory](http://www.bioinf.jku.at/publications/older/2604.pdf)"
  2846. },
  2847. {
  2848. "description": "[Learning to forget: Continual prediction with LSTM](http://www.mitpressjournals.org/doi/pdf/10.1162/089976600300015015)"
  2849. },
  2850. {
  2851. "description": "[Supervised sequence labeling with recurrent neural networks](http://www.cs.toronto.edu/~graves/preprint.pdf)"
  2852. },
  2853. {
  2854. "description": "[A Theoretically Grounded Application of Dropout in Recurrent Neural Networks](https://arxiv.org/abs/1512.05287)"
  2855. }
  2856. ]
  2857. },
  2858. {
  2859. "name": "LSTMCell",
  2860. "module": "tensorflow.keras.layers",
  2861. "description": "Cell class for the LSTM layer.\n\nSee [the Keras RNN API guide](https://www.tensorflow.org/guide/keras/rnn)\nfor details about the usage of RNN API.\n\nThis class processes one step within the whole time sequence input, whereas\n`tf.keras.layer.LSTM` processes the whole sequence.\n\nFor example:\n\n```\n>>> inputs = tf.random.normal([32, 10, 8])\n>>> rnn = tf.keras.layers.RNN(tf.keras.layers.LSTMCell(4))\n>>> output = rnn(inputs)\n>>> print(output.shape)\n(32, 4)\n>>> rnn = tf.keras.layers.RNN(\n... tf.keras.layers.LSTMCell(4),\n... return_sequences=True,\n... return_state=True)\n>>> whole_seq_output, final_memory_state, final_carry_state = rnn(inputs)\n>>> print(whole_seq_output.shape)\n(32, 10, 4)\n>>> print(final_memory_state.shape)\n(32, 4)\n>>> print(final_carry_state.shape)\n(32, 4)\n```",
  2862. "attributes": [
  2863. {
  2864. "description": "Positive integer, dimensionality of the output space.",
  2865. "name": "units"
  2866. },
  2867. {
  2868. "description": "`a(x) = x`).",
  2869. "name": "activation"
  2870. },
  2871. {
  2872. "description": "Activation function to use for the recurrent step.",
  2873. "name": "recurrent_activation"
  2874. },
  2875. {
  2876. "default": true,
  2877. "description": "Boolean, (default `True`), whether the layer uses a bias vector.",
  2878. "name": "use_bias"
  2879. },
  2880. {
  2881. "description": "Initializer for the `kernel` weights matrix, used for\n the linear transformation of the inputs. Default: `glorot_uniform`.",
  2882. "name": "kernel_initializer"
  2883. },
  2884. {
  2885. "description": "Initializer for the `recurrent_kernel` weights\n matrix, used for the linear transformation of the recurrent state.",
  2886. "name": "recurrent_initializer"
  2887. },
  2888. {
  2889. "description": "Initializer for the bias vector. Default: `zeros`.",
  2890. "name": "bias_initializer"
  2891. },
  2892. {
  2893. "description": "Boolean (default `True`). If True, add 1 to the bias of\n the forget gate at initialization. Setting it to true will also force\n `bias_initializer=\"zeros\"`. This is recommended in [Jozefowicz et\n al.](http://www.jmlr.org/proceedings/papers/v37/jozefowicz15.pdf)",
  2894. "name": "unit_forget_bias"
  2895. },
  2896. {
  2897. "description": "Regularizer function applied to the `kernel` weights\n matrix. Default: `None`.",
  2898. "name": "kernel_regularizer"
  2899. },
  2900. {
  2901. "description": "Regularizer function applied to\n the `recurrent_kernel` weights matrix. Default: `None`.",
  2902. "name": "recurrent_regularizer"
  2903. },
  2904. {
  2905. "description": "Regularizer function applied to the bias vector.",
  2906. "name": "bias_regularizer"
  2907. },
  2908. {
  2909. "description": "Constraint function applied to the `kernel` weights\n matrix. Default: `None`.",
  2910. "name": "kernel_constraint"
  2911. },
  2912. {
  2913. "description": "Constraint function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  2914. "name": "recurrent_constraint"
  2915. },
  2916. {
  2917. "description": "Constraint function applied to the bias vector. Default:\n `None`.",
  2918. "name": "bias_constraint"
  2919. },
  2920. {
  2921. "default": 0,
  2922. "description": "Float between 0 and 1. Fraction of the units to drop for the\n linear transformation of the inputs. Default: 0.",
  2923. "name": "dropout"
  2924. },
  2925. {
  2926. "default": 0,
  2927. "description": "Float between 0 and 1. Fraction of the units to drop\n for the linear transformation of the recurrent state. Default: 0.",
  2928. "name": "recurrent_dropout"
  2929. },
  2930. {
  2931. "description": "Implementation mode, either 1 or 2.\n Mode 1 will structure its operations as a larger number of smaller dot\n products and additions, whereas mode 2 (default) will batch them into\n fewer, larger operations. These modes will have different performance\n profiles on different hardware and for different applications. Default: 2.",
  2932. "name": "implementation"
  2933. },
  2934. {
  2935. "description": "`None`.",
  2936. "name": "Default"
  2937. }
  2938. ]
  2939. },
  2940. {
  2941. "name": "Masking",
  2942. "module": "tensorflow.keras.layers",
  2943. "description": "Masks a sequence by using a mask value to skip timesteps.\n\nFor each timestep in the input tensor (dimension #1 in the tensor),\nif all values in the input tensor at that timestep\nare equal to `mask_value`, then the timestep will be masked (skipped)\nin all downstream layers (as long as they support masking).\n\nIf any downstream layer does not support masking yet receives such\nan input mask, an exception will be raised.",
  2944. "attributes": [
  2945. {
  2946. "description": "Either None or mask value to skip\n",
  2947. "name": "mask_value"
  2948. }
  2949. ],
  2950. "examples": [
  2951. {
  2952. "summary": "Consider a Numpy data array `x` of shape `(samples, timesteps, features)`,\nto be fed to an LSTM layer. You want to mask timestep #3 and #5 because you\nlack data for these timesteps. You can:\n- Set `x[:, 3, :] = 0.` and `x[:, 5, :] = 0.`\n- Insert a `Masking` layer with `mask_value=0.` before the LSTM layer:",
  2953. "code": "samples, timesteps, features = 32, 10, 8\ninputs = np.random.random([samples, timesteps, features]).astype(np.float32)\ninputs[:, 3, :] = 0.\ninputs[:, 5, :] = 0.\n\nmodel = tf.keras.models.Sequential()\nmodel.add(tf.keras.layers.Masking(mask_value=0.,\n input_shape=(timesteps, features)))\nmodel.add(tf.keras.layers.LSTM(32))\n\noutput = model(inputs)\n# The time step 3 and 5 will be skipped from LSTM calculation."
  2954. }
  2955. ]
  2956. },
  2957. {
  2958. "name": "Maximum",
  2959. "module": "tensorflow.keras.layers",
  2960. "category": "Tensor",
  2961. "description": "Layer that computes the maximum (element-wise) a list of inputs.\n\nIt takes as input a list of tensors, all of the same shape, and returns\na single tensor (also of the same shape).\n\n```\n>>> tf.keras.layers.Maximum()([np.arange(5).reshape(5, 1),\n... np.arange(5, 10).reshape(5, 1)])\n<tf.Tensor: shape=(5, 1), dtype=int64, numpy=\narray([[5],\n [6],\n [7],\n [8],\n [9]])>\n```\n\n```\n>>> x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2))\n>>> x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))\n>>> maxed = tf.keras.layers.Maximum()([x1, x2])\n>>> maxed.shape\nTensorShape([5, 8])\n```",
  2962. "inputs": [
  2963. {
  2964. "name": "inputs",
  2965. "list": true
  2966. }
  2967. ],
  2968. "outputs": [
  2969. {
  2970. "name": "output"
  2971. }
  2972. ]
  2973. },
  2974. {
  2975. "name": "MaxPooling1D",
  2976. "module": "tensorflow.keras.layers",
  2977. "category": "Pool",
  2978. "description": "Max pooling operation for 1D temporal data.\n\nDownsamples the input representation by taking the maximum value over a\nspatial window of size `pool_size`. The window is shifted by `strides`. The\nresulting output, when using the `\"valid\"` padding option, has a shape of:\n`output_shape = (input_shape - pool_size + 1) / strides)`\n\nThe resulting output shape when using the `\"same\"` padding option is:\n`output_shape = input_shape / strides`\n\nFor example, for `strides=1` and `padding=\"valid\"`:\n\n```\n>>> x = tf.constant([1., 2., 3., 4., 5.])\n>>> x = tf.reshape(x, [1, 5, 1])\n>>> max_pool_1d = tf.keras.layers.MaxPooling1D(pool_size=2,\n... strides=1, padding='valid')\n>>> max_pool_1d(x)\n<tf.Tensor: shape=(1, 4, 1), dtype=float32, numpy=\narray([[[2.],\n [3.],\n [4.],\n [5.]]], dtype=float32)>\n```\n\nFor example, for `strides=2` and `padding=\"valid\"`:\n\n```\n>>> x = tf.constant([1., 2., 3., 4., 5.])\n>>> x = tf.reshape(x, [1, 5, 1])\n>>> max_pool_1d = tf.keras.layers.MaxPooling1D(pool_size=2,\n... strides=2, padding='valid')\n>>> max_pool_1d(x)\n<tf.Tensor: shape=(1, 2, 1), dtype=float32, numpy=\narray([[[2.],\n [4.]]], dtype=float32)>\n```\n\nFor example, for `strides=1` and `padding=\"same\"`:\n\n```\n>>> x = tf.constant([1., 2., 3., 4., 5.])\n>>> x = tf.reshape(x, [1, 5, 1])\n>>> max_pool_1d = tf.keras.layers.MaxPooling1D(pool_size=2,\n... strides=1, padding='same')\n>>> max_pool_1d(x)\n<tf.Tensor: shape=(1, 5, 1), dtype=float32, numpy=\narray([[[2.],\n [3.],\n [4.],\n [5.],\n [5.]]], dtype=float32)>\n```",
  2979. "attributes": [
  2980. {
  2981. "default": "channels_last",
  2982. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, steps, features)` while `channels_first`\n corresponds to inputs with shape\n `(batch, features, steps)`.",
  2983. "name": "data_format"
  2984. },
  2985. {
  2986. "default": "valid",
  2987. "description": "One of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding evenly to\n the left/right or up/down of the input such that output has the same\n height/width dimension as the input.",
  2988. "name": "padding"
  2989. },
  2990. {
  2991. "default": [
  2992. 2,
  2993. 2
  2994. ],
  2995. "description": "Integer, size of the max pooling window.",
  2996. "name": "pool_size"
  2997. },
  2998. {
  2999. "default": [
  3000. 2,
  3001. 2
  3002. ],
  3003. "description": "Integer, or None. Specifies how much the pooling window moves\n for each pooling step.\n If None, it will default to `pool_size`.",
  3004. "name": "strides"
  3005. }
  3006. ],
  3007. "inputs": [
  3008. {
  3009. "description": "- If `data_format='channels_last'`:\n 3D tensor with shape `(batch_size, steps, features)`.\n- If `data_format='channels_first'`:\n 3D tensor with shape `(batch_size, features, steps)`.",
  3010. "name": "input"
  3011. }
  3012. ],
  3013. "outputs": [
  3014. {
  3015. "description": "- If `data_format='channels_last'`:\n 3D tensor with shape `(batch_size, downsampled_steps, features)`.\n- If `data_format='channels_first'`:\n 3D tensor with shape `(batch_size, features, downsampled_steps)`.",
  3016. "name": "output"
  3017. }
  3018. ]
  3019. },
  3020. {
  3021. "name": "MaxPooling2D",
  3022. "module": "tensorflow.keras.layers",
  3023. "category": "Pool",
  3024. "description": "Max pooling operation for 2D spatial data.\n\nDownsamples the input along its spatial dimensions (height and width)\nby taking the maximum value over an input window\n(of size defined by `pool_size`) for each channel of the input.\nThe window is shifted by `strides` along each dimension.\n\nThe resulting output,\nwhen using the `\"valid\"` padding option, has a spatial shape\n(number of rows or columns) of:\n`output_shape = math.floor((input_shape - pool_size) / strides) + 1`\n(when `input_shape >= pool_size`)\n\nThe resulting output shape when using the `\"same\"` padding option is:\n`output_shape = math.floor((input_shape - 1) / strides) + 1`\n\nFor example, for `strides=(1, 1)` and `padding=\"valid\"`:\n\n```\n>>> x = tf.constant([[1., 2., 3.],\n... [4., 5., 6.],\n... [7., 8., 9.]])\n>>> x = tf.reshape(x, [1, 3, 3, 1])\n>>> max_pool_2d = tf.keras.layers.MaxPooling2D(pool_size=(2, 2),\n... strides=(1, 1), padding='valid')\n>>> max_pool_2d(x)\n<tf.Tensor: shape=(1, 2, 2, 1), dtype=float32, numpy=\n array([[[[5.],\n [6.]],\n [[8.],\n [9.]]]], dtype=float32)>\n```\n\nFor example, for `strides=(2, 2)` and `padding=\"valid\"`:\n\n```\n>>> x = tf.constant([[1., 2., 3., 4.],\n... [5., 6., 7., 8.],\n... [9., 10., 11., 12.]])\n>>> x = tf.reshape(x, [1, 3, 4, 1])\n>>> max_pool_2d = tf.keras.layers.MaxPooling2D(pool_size=(2, 2),\n... strides=(2, 2), padding='valid')\n>>> max_pool_2d(x)\n<tf.Tensor: shape=(1, 1, 2, 1), dtype=float32, numpy=\n array([[[[6.],\n [8.]]]], dtype=float32)>\n```\n\nUsage Example:\n\n```\n>>> input_image = tf.constant([[[[1.], [1.], [2.], [4.]],\n... [[2.], [2.], [3.], [2.]],\n... [[4.], [1.], [1.], [1.]],\n... [[2.], [2.], [1.], [4.]]]])\n>>> output = tf.constant([[[[1], [0]],\n... [[0], [1]]]])\n>>> model = tf.keras.models.Sequential()\n>>> model.add(tf.keras.layers.MaxPooling2D(pool_size=(2, 2),\n... input_shape=(4, 4, 1)))\n>>> model.compile('adam', 'mean_squared_error')\n>>> model.predict(input_image, steps=1)\narray([[[[2.],\n [4.]],\n [[4.],\n [4.]]]], dtype=float32)\n```\n\nFor example, for stride=(1, 1) and padding=\"same\":\n\n```\n>>> x = tf.constant([[1., 2., 3.],\n... [4., 5., 6.],\n... [7., 8., 9.]])\n>>> x = tf.reshape(x, [1, 3, 3, 1])\n>>> max_pool_2d = tf.keras.layers.MaxPooling2D(pool_size=(2, 2),\n... strides=(1, 1), padding='same')\n>>> max_pool_2d(x)\n<tf.Tensor: shape=(1, 3, 3, 1), dtype=float32, numpy=\n array([[[[5.],\n [6.],\n [6.]],\n [[8.],\n [9.],\n [9.]],\n [[8.],\n [9.],\n [9.]]]], dtype=float32)>\n```",
  3025. "attributes": [
  3026. {
  3027. "default": "channels_last",
  3028. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, height, width, channels)` while `channels_first`\n corresponds to inputs with shape\n `(batch, channels, height, width)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  3029. "name": "data_format"
  3030. },
  3031. {
  3032. "default": "valid",
  3033. "description": "One of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding evenly to\n the left/right or up/down of the input such that output has the same\n height/width dimension as the input.",
  3034. "name": "padding"
  3035. },
  3036. {
  3037. "default": [
  3038. 2,
  3039. 2
  3040. ],
  3041. "description": "integer or tuple of 2 integers,\n window size over which to take the maximum.\n `(2, 2)` will take the max value over a 2x2 pooling window.\n If only one integer is specified, the same window length\n will be used for both dimensions.",
  3042. "name": "pool_size"
  3043. },
  3044. {
  3045. "default": [
  3046. 2,
  3047. 2
  3048. ],
  3049. "description": "Integer, tuple of 2 integers, or None.\n Strides values. Specifies how far the pooling window moves\n for each pooling step. If None, it will default to `pool_size`.",
  3050. "name": "strides"
  3051. }
  3052. ],
  3053. "inputs": [
  3054. {
  3055. "description": "- If `data_format='channels_last'`:\n 4D tensor with shape `(batch_size, rows, cols, channels)`.\n- If `data_format='channels_first'`:\n 4D tensor with shape `(batch_size, channels, rows, cols)`.",
  3056. "name": "input"
  3057. }
  3058. ],
  3059. "outputs": [
  3060. {
  3061. "description": "- If `data_format='channels_last'`:\n 4D tensor with shape `(batch_size, pooled_rows, pooled_cols, channels)`.\n- If `data_format='channels_first'`:\n 4D tensor with shape `(batch_size, channels, pooled_rows, pooled_cols)`.",
  3062. "name": "output"
  3063. }
  3064. ]
  3065. },
  3066. {
  3067. "name": "MaxPooling3D",
  3068. "module": "tensorflow.keras.layers",
  3069. "category": "Pool",
  3070. "description": "Max pooling operation for 3D data (spatial or spatio-temporal).\n\nDownsamples the input along its spatial dimensions (depth, height, and\nwidth) by taking the maximum value over an input window (of size defined by\n`pool_size`) for each channel of the input. The window is shifted by\n`strides` along each dimension.",
  3071. "attributes": [
  3072. {
  3073. "description": "Tuple of 3 integers,\n factors by which to downscale (dim1, dim2, dim3).\n `(2, 2, 2)` will halve the size of the 3D input in each dimension.",
  3074. "name": "pool_size"
  3075. },
  3076. {
  3077. "description": "tuple of 3 integers, or None. Strides values.",
  3078. "name": "strides"
  3079. },
  3080. {
  3081. "description": "One of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding evenly to\n the left/right or up/down of the input such that output has the same\n height/width dimension as the input.",
  3082. "name": "padding"
  3083. },
  3084. {
  3085. "default": "channels_last",
  3086. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch, spatial_dim1, spatial_dim2, spatial_dim3, channels)`\n while `channels_first` corresponds to inputs with shape\n `(batch, channels, spatial_dim1, spatial_dim2, spatial_dim3)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  3087. "name": "data_format"
  3088. }
  3089. ],
  3090. "inputs": [
  3091. {
  3092. "description": "- If `data_format='channels_last'`:\n 5D tensor with shape:\n `(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)`\n- If `data_format='channels_first'`:\n 5D tensor with shape:\n `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)`",
  3093. "name": "input"
  3094. }
  3095. ],
  3096. "outputs": [
  3097. {
  3098. "description": "- If `data_format='channels_last'`:\n 5D tensor with shape:\n `(batch_size, pooled_dim1, pooled_dim2, pooled_dim3, channels)`\n- If `data_format='channels_first'`:\n 5D tensor with shape:\n `(batch_size, channels, pooled_dim1, pooled_dim2, pooled_dim3)`",
  3099. "name": "output"
  3100. }
  3101. ],
  3102. "examples": [
  3103. {
  3104. "code": "depth = 30\nheight = 30\nwidth = 30\ninput_channels = 3\n\ninputs = tf.keras.Input(shape=(depth, height, width, input_channels))\nlayer = tf.keras.layers.MaxPooling3D(pool_size=3)\noutputs = layer(inputs) # Shape: (batch_size, 10, 10, 10, 3)"
  3105. }
  3106. ]
  3107. },
  3108. {
  3109. "name": "MultiHeadAttention",
  3110. "module": "tensorflow.keras.layers",
  3111. "description": "MultiHeadAttention layer.\n\nThis is an implementation of multi-headed attention as described in the\npaper \"Attention is all you Need\" (Vaswani et al., 2017).\nIf `query`, `key,` `value` are the same, then\nthis is self-attention. Each timestep in `query` attends to the\ncorresponding sequence in `key`, and returns a fixed-width vector.\n\nThis layer first projects `query`, `key` and `value`. These are\n(effectively) a list of tensors of length `num_attention_heads`, where the\ncorresponding shapes are `(batch_size, <query dimensions>, key_dim)`,\n`(batch_size, <key/value dimensions>, key_dim)`,\n`(batch_size, <key/value dimensions>, value_dim)`.\n\nThen, the query and key tensors are dot-producted and scaled. These are\nsoftmaxed to obtain attention probabilities. The value tensors are then\ninterpolated by these probabilities, then concatenated back to a single\ntensor.\n\nFinally, the result tensor with the last dimension as value_dim can take an\nlinear projection and return.\n\nWhen using MultiHeadAttention inside a custom Layer, the custom Layer must\nimplement `build()` and call MultiHeadAttention's `_build_from_signature()`.\nThis enables weights to be restored correctly when the model is loaded.\nTODO(b/172609172): link to documentation about calling custom build\nfunctions when used in a custom Layer.",
  3112. "attributes": [
  3113. {
  3114. "description": "Number of attention heads.",
  3115. "name": "num_heads"
  3116. },
  3117. {
  3118. "description": "Size of each attention head for query and key.",
  3119. "name": "key_dim"
  3120. },
  3121. {
  3122. "description": "Size of each attention head for value.",
  3123. "name": "value_dim"
  3124. },
  3125. {
  3126. "description": "Dropout probability.",
  3127. "name": "dropout"
  3128. },
  3129. {
  3130. "description": "Boolean, whether the dense layers use bias vectors/matrices.",
  3131. "name": "use_bias"
  3132. },
  3133. {
  3134. "description": "The expected shape of an output tensor, besides the batch\n and sequence dims. If not specified, projects back to the key feature\n dim.",
  3135. "name": "output_shape"
  3136. },
  3137. {
  3138. "description": "axes over which the attention is applied. `None` means\n attention over all axes, but batch, heads, and features.",
  3139. "name": "attention_axes"
  3140. },
  3141. {
  3142. "description": "Initializer for dense layer kernels.",
  3143. "name": "kernel_initializer"
  3144. },
  3145. {
  3146. "description": "Initializer for dense layer biases.",
  3147. "name": "bias_initializer"
  3148. },
  3149. {
  3150. "description": "Regularizer for dense layer kernels.",
  3151. "name": "kernel_regularizer"
  3152. },
  3153. {
  3154. "description": "Regularizer for dense layer biases.",
  3155. "name": "bias_regularizer"
  3156. },
  3157. {
  3158. "description": "Regularizer for dense layer activity.",
  3159. "name": "activity_regularizer"
  3160. },
  3161. {
  3162. "description": "Constraint for dense layer kernels.",
  3163. "name": "kernel_constraint"
  3164. },
  3165. {
  3166. "description": "Constraint for dense layer kernels.",
  3167. "name": "bias_constraint"
  3168. }
  3169. ],
  3170. "examples": [
  3171. {
  3172. "summary": "Performs 1D cross-attention over two sequence inputs with an attention mask.\nReturns the additional attention weights over heads.",
  3173. "code": ">>> layer = MultiHeadAttention(num_heads=2, key_dim=2)\n>>> target = tf.keras.Input(shape=[8, 16])\n>>> source = tf.keras.Input(shape=[4, 16])\n>>> output_tensor, weights = layer(target, source,\n... return_attention_scores=True)\n>>> print(output_tensor.shape)\n(None, 8, 16)\n>>> print(weights.shape)\n(None, 2, 8, 4)"
  3174. },
  3175. {
  3176. "summary": "Performs 2D self-attention over a 5D input tensor on axes 2 and 3.",
  3177. "code": ">>> layer = MultiHeadAttention(\n... num_heads=2, key_dim=2, attention_axes=(2, 3))\n>>> input_tensor = tf.keras.Input(shape=[5, 3, 4, 16])\n>>> output_tensor = layer(input_tensor, input_tensor)\n>>> print(output_tensor.shape)\n(None, 5, 3, 4, 16)"
  3178. }
  3179. ]
  3180. },
  3181. {
  3182. "name": "Multiply",
  3183. "module": "tensorflow.keras.layers",
  3184. "description": "Layer that multiplies (element-wise) a list of inputs.\n\nIt takes as input a list of tensors, all of the same shape, and returns\na single tensor (also of the same shape).\n\n```\n>>> tf.keras.layers.Multiply()([np.arange(5).reshape(5, 1),\n... np.arange(5, 10).reshape(5, 1)])\n<tf.Tensor: shape=(5, 1), dtype=int64, numpy=\narray([[ 0],\n [ 6],\n [14],\n [24],\n [36]])>\n```\n\n```\n>>> x1 = tf.keras.layers.Dense(8)(np.arange(10).reshape(5, 2))\n>>> x2 = tf.keras.layers.Dense(8)(np.arange(10, 20).reshape(5, 2))\n>>> multiplied = tf.keras.layers.Multiply()([x1, x2])\n>>> multiplied.shape\nTensorShape([5, 8])\n```",
  3185. "inputs": [
  3186. {
  3187. "name": "inputs",
  3188. "list": true
  3189. }
  3190. ],
  3191. "outputs": [
  3192. {
  3193. "name": "output"
  3194. }
  3195. ]
  3196. },
  3197. {
  3198. "name": "Permute",
  3199. "module": "tensorflow.keras.layers",
  3200. "category": "Shape",
  3201. "description": "Permutes the dimensions of the input according to a given pattern.\n\nUseful e.g. connecting RNNs and convnets.",
  3202. "attributes": [
  3203. {
  3204. "description": "Tuple of integers. Permutation pattern does not include the\n samples dimension. Indexing starts at 1.\n For instance, `(2, 1)` permutes the first and second dimensions\n of the input.",
  3205. "name": "dims"
  3206. }
  3207. ],
  3208. "inputs": [
  3209. {
  3210. "description": "Arbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the samples axis)\nwhen using this layer as the first layer in a model.",
  3211. "name": "input"
  3212. }
  3213. ],
  3214. "outputs": [
  3215. {
  3216. "description": "Same as the input shape, but with the dimensions re-ordered according\nto the specified pattern.",
  3217. "name": "output"
  3218. }
  3219. ],
  3220. "examples": [
  3221. {
  3222. "code": "model = Sequential()\nmodel.add(Permute((2, 1), input_shape=(10, 64)))\n# now: model.output_shape == (None, 64, 10)\n# note: `None` is the batch dimension"
  3223. }
  3224. ]
  3225. },
  3226. {
  3227. "name": "PReLU",
  3228. "module": "tensorflow.keras.layers",
  3229. "category": "Activation",
  3230. "description": "Parametric Rectified Linear Unit.\n\nIt follows:\n\n```\n f(x) = alpha * x for x < 0\n f(x) = x for x >= 0\n```\n\nwhere `alpha` is a learned array with the same shape as x.",
  3231. "attributes": [
  3232. {
  3233. "description": "Initializer function for the weights.",
  3234. "name": "alpha_initializer"
  3235. },
  3236. {
  3237. "description": "Regularizer for the weights.",
  3238. "name": "alpha_regularizer",
  3239. "visible": false
  3240. },
  3241. {
  3242. "description": "Constraint for the weights.",
  3243. "name": "alpha_constraint"
  3244. },
  3245. {
  3246. "description": "The axes along which to share learnable\n parameters for the activation function.\n For example, if the incoming feature maps\n are from a 2D convolution\n with output shape `(batch, height, width, channels)`,\n and you wish to share parameters across space\n so that each filter only has one set of parameters,\n set `shared_axes=[1, 2]`.",
  3247. "name": "shared_axes"
  3248. }
  3249. ],
  3250. "inputs": [
  3251. {
  3252. "description": "Arbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the samples axis)\nwhen using this layer as the first layer in a model.",
  3253. "name": "input"
  3254. },
  3255. {
  3256. "name": "params"
  3257. }
  3258. ],
  3259. "outputs": [
  3260. {
  3261. "description": "Same shape as the input.",
  3262. "name": "output"
  3263. }
  3264. ],
  3265. "references": [
  3266. {
  3267. "description": "[Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification](https://arxiv.org/abs/1502.01852)"
  3268. }
  3269. ]
  3270. },
  3271. {
  3272. "name": "ReLU",
  3273. "module": "tensorflow.keras.layers",
  3274. "category": "Activation",
  3275. "description": "Rectified Linear Unit activation function.\n\nWith default values, it returns element-wise `max(x, 0)`.\n\nOtherwise, it follows:\n\n```\n f(x) = max_value if x >= max_value\n f(x) = x if threshold <= x < max_value\n f(x) = negative_slope * (x - threshold) otherwise\n```",
  3276. "attributes": [
  3277. {
  3278. "description": "Float >= 0. Maximum activation value. Default to None, which\n means unlimited.",
  3279. "name": "max_value"
  3280. },
  3281. {
  3282. "description": "Float >= 0. Negative slope coefficient. Default to 0.",
  3283. "name": "negative_slope"
  3284. },
  3285. {
  3286. "description": "Float >= 0. Threshold value for thresholded activation. Default\n to 0.",
  3287. "name": "threshold"
  3288. }
  3289. ],
  3290. "inputs": [
  3291. {
  3292. "description": "Arbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the batch axis)\nwhen using this layer as the first layer in a model.",
  3293. "name": "input"
  3294. }
  3295. ],
  3296. "outputs": [
  3297. {
  3298. "description": "Same shape as the input.",
  3299. "name": "output"
  3300. }
  3301. ],
  3302. "examples": [
  3303. {
  3304. "code": ">>> layer = tf.keras.layers.ReLU()\n>>> output = layer([-3.0, -1.0, 0.0, 2.0])\n>>> list(output.numpy())\n[0.0, 0.0, 0.0, 2.0]\n>>> layer = tf.keras.layers.ReLU(max_value=1.0)\n>>> output = layer([-3.0, -1.0, 0.0, 2.0])\n>>> list(output.numpy())\n[0.0, 0.0, 0.0, 1.0]\n>>> layer = tf.keras.layers.ReLU(negative_slope=1.0)\n>>> output = layer([-3.0, -1.0, 0.0, 2.0])\n>>> list(output.numpy())\n[-3.0, -1.0, 0.0, 2.0]\n>>> layer = tf.keras.layers.ReLU(threshold=1.5)\n>>> output = layer([-3.0, -1.0, 1.0, 2.0])\n>>> list(output.numpy())\n[0.0, 0.0, 0.0, 2.0]"
  3305. }
  3306. ]
  3307. },
  3308. {
  3309. "name": "RepeatVector",
  3310. "module": "tensorflow.keras.layers",
  3311. "category": "Shape",
  3312. "description": "Repeats the input n times.",
  3313. "attributes": [
  3314. {
  3315. "description": "Integer, repetition factor.\nInput shape: 2D tensor of shape `(num_samples, features)`.\nOutput shape: 3D tensor of shape `(num_samples, n, features)`.",
  3316. "name": "n"
  3317. }
  3318. ],
  3319. "inputs": [
  3320. {
  3321. "description": "2D tensor of shape `(num_samples, features)`.",
  3322. "name": "input"
  3323. }
  3324. ],
  3325. "outputs": [
  3326. {
  3327. "description": "3D tensor of shape `(num_samples, n, features)`.",
  3328. "name": "output"
  3329. }
  3330. ],
  3331. "examples": [
  3332. {
  3333. "code": "model = Sequential()\nmodel.add(Dense(32, input_dim=32))\n# now: model.output_shape == (None, 32)\n# note: `None` is the batch dimension\n\nmodel.add(RepeatVector(3))\n# now: model.output_shape == (None, 3, 32)"
  3334. }
  3335. ]
  3336. },
  3337. {
  3338. "name": "Reshape",
  3339. "module": "tensorflow.keras.layers",
  3340. "category": "Shape",
  3341. "description": "Layer that reshapes inputs into the given shape.",
  3342. "attributes": [
  3343. {
  3344. "description": "target shape. Tuple of integers.\n Does not include the batch axis.\n",
  3345. "name": "target_shape"
  3346. }
  3347. ],
  3348. "inputs": [
  3349. {
  3350. "description": "Arbitrary, although all dimensions in the input shape must be known/fixed.\nUse the keyword argument `input_shape` (tuple of integers, does not\ninclude the samples/batch size axis) when using this layer as the first\nlayer in a model.",
  3351. "name": "input"
  3352. }
  3353. ],
  3354. "outputs": [
  3355. {
  3356. "description": "`(batch_size,) + target_shape`",
  3357. "name": "output"
  3358. }
  3359. ],
  3360. "examples": [
  3361. {
  3362. "code": ">>> # as first layer in a Sequential model\n>>> model = tf.keras.Sequential()\n>>> model.add(tf.keras.layers.Reshape((3, 4), input_shape=(12,)))\n>>> # model.output_shape == (None, 3, 4), `None` is the batch size.\n>>> model.output_shape\n(None, 3, 4)"
  3363. },
  3364. {
  3365. "code": ">>> # as intermediate layer in a Sequential model\n>>> model.add(tf.keras.layers.Reshape((6, 2)))\n>>> model.output_shape\n(None, 6, 2)"
  3366. },
  3367. {
  3368. "code": ">>> # also supports shape inference using `-1` as dimension\n>>> model.add(tf.keras.layers.Reshape((-1, 2, 2)))\n>>> model.output_shape\n(None, 3, 2, 2)"
  3369. }
  3370. ]
  3371. },
  3372. {
  3373. "name": "RNN",
  3374. "module": "tensorflow.keras.layers",
  3375. "category": "Layer",
  3376. "description": "Base class for recurrent layers.\n\nSee [the Keras RNN API guide](https://www.tensorflow.org/guide/keras/rnn)\nfor details about the usage of RNN API.",
  3377. "attributes": [
  3378. {
  3379. "default": false,
  3380. "description": "Boolean (default `False`). Whether to return the last\n output in the output sequence, or the full sequence.",
  3381. "name": "return_sequences"
  3382. },
  3383. {
  3384. "default": false,
  3385. "description": "Boolean (default `False`). Whether to return the last state\n in addition to the output.",
  3386. "name": "return_state"
  3387. },
  3388. {
  3389. "default": false,
  3390. "description": "Boolean (default `False`).\n If True, process the input sequence backwards and return the\n reversed sequence.",
  3391. "name": "go_backwards"
  3392. },
  3393. {
  3394. "default": false,
  3395. "description": "Boolean (default `False`). If True, the last state\n for each sample at index i in a batch will be used as initial\n state for the sample of index i in the following batch.",
  3396. "name": "stateful"
  3397. },
  3398. {
  3399. "default": false,
  3400. "description": "Boolean (default `False`).\n If True, the network will be unrolled, else a symbolic loop will be\n used. Unrolling can speed-up a RNN, although it tends to be more\n memory-intensive. Unrolling is only suitable for short sequences.",
  3401. "name": "unroll"
  3402. },
  3403. {
  3404. "description": "A RNN cell instance or a list of RNN cell instances.\n A RNN cell is a class that has:\n - A `call(input_at_t, states_at_t)` method, returning\n `(output_at_t, states_at_t_plus_1)`. The call method of the\n cell can also take the optional argument `constants`, see\n section \"Note on passing external constants\" below.\n - A `state_size` attribute. This can be a single integer\n (single state) in which case it is the size of the recurrent\n state. This can also be a list/tuple of integers (one size per state).\n The `state_size` can also be TensorShape or tuple/list of\n TensorShape, to represent high dimension state.\n - A `output_size` attribute. This can be a single integer or a\n TensorShape, which represent the shape of the output. For backward\n compatible reason, if this attribute is not available for the\n cell, the value will be inferred by the first element of the\n `state_size`.\n - A `get_initial_state(inputs=None, batch_size=None, dtype=None)`\n method that creates a tensor meant to be fed to `call()` as the\n initial state, if the user didn't specify any initial state via other\n means. The returned initial state should have a shape of\n [batch_size, cell.state_size]. The cell might choose to create a\n tensor full of zeros, or full of other values based on the cell's\n implementation.\n `inputs` is the input tensor to the RNN layer, which should\n contain the batch size as its shape[0], and also dtype. Note that\n the shape[0] might be `None` during the graph construction. Either\n the `inputs` or the pair of `batch_size` and `dtype` are provided.\n `batch_size` is a scalar tensor that represents the batch size\n of the inputs. `dtype` is `tf.DType` that represents the dtype of\n the inputs.\n For backward compatibility, if this method is not implemented\n by the cell, the RNN layer will create a zero filled tensor with the\n size of [batch_size, cell.state_size].\n In the case that `cell` is a list of RNN cell instances, the cells\n will be stacked on top of each other in the RNN, resulting in an\n efficient stacked RNN.",
  3405. "name": "cell"
  3406. },
  3407. {
  3408. "description": "dimensionality of the input (integer).\n This argument (or alternatively,\n the keyword argument `input_shape`)\n is required when using this layer as the first layer in a model.",
  3409. "name": "input_dim"
  3410. },
  3411. {
  3412. "description": "Length of input sequences, to be specified\n when it is constant.\n This argument is required if you are going to connect\n `Flatten` then `Dense` layers upstream\n (without it, the shape of the dense outputs cannot be computed).\n Note that if the recurrent layer is not the first layer\n in your model, you would need to specify the input length\n at the level of the first layer\n (e.g. via the `input_shape` argument)\n",
  3413. "name": "input_length"
  3414. },
  3415. {
  3416. "description": "The shape format of the `inputs` and `outputs` tensors.\n If True, the inputs and outputs will be in shape\n `(timesteps, batch, ...)`, whereas in the False case, it will be\n `(batch, timesteps, ...)`. Using `time_major = True` is a bit more\n efficient because it avoids transposes at the beginning and end of the\n RNN calculation. However, most TensorFlow data is batch-major, so by\n default this function accepts input and emits output in batch-major\n form.",
  3417. "name": "time_major"
  3418. },
  3419. {
  3420. "description": "Boolean (default `False`).\n Whether the output should use zeros for the masked timesteps. Note that\n this field is only used when `return_sequences` is True and mask is\n provided. It can useful if you want to reuse the raw output sequence of\n the RNN without interference from the masked timesteps, eg, merging\n bidirectional RNNs.",
  3421. "name": "zero_output_for_mask"
  3422. }
  3423. ],
  3424. "inputs": [
  3425. {
  3426. "description": "N-D tensor with shape `[batch_size, timesteps, ...]` or\n`[timesteps, batch_size, ...]` when time_major is True.",
  3427. "name": "input"
  3428. }
  3429. ],
  3430. "outputs": [
  3431. {
  3432. "description": "- If `return_state`: a list of tensors. The first tensor is\n the output. The remaining tensors are the last states,\n each with shape `[batch_size, state_size]`, where `state_size` could\n be a high dimension tensor shape.\n - If `return_sequences`: N-D tensor with shape\n `[batch_size, timesteps, output_size]`, where `output_size` could\n be a high dimension tensor shape, or\n `[timesteps, batch_size, output_size]` when `time_major` is True.\n - Else, N-D tensor with shape `[batch_size, output_size]`, where\n `output_size` could be a high dimension tensor shape.\n\nMasking:\n This layer supports masking for input data with a variable number\n of timesteps. To introduce masks to your data,\n use an [tf.keras.layers.Embedding] layer with the `mask_zero` parameter\n set to `True`.\n\nNote on using statefulness in RNNs:\n You can set RNN layers to be 'stateful', which means that the states\n computed for the samples in one batch will be reused as initial states\n for the samples in the next batch. This assumes a one-to-one mapping\n between samples in different successive batches.\n\n To enable statefulness:\n - Specify `stateful=True` in the layer constructor.\n - Specify a fixed batch size for your model, by passing\n If sequential model:\n `batch_input_shape=(...)` to the first layer in your model.\n Else for functional model with 1 or more Input layers:\n `batch_shape=(...)` to all the first layers in your model.\n This is the expected shape of your inputs\n *including the batch size*.\n It should be a tuple of integers, e.g. `(32, 10, 100)`.\n - Specify `shuffle=False` when calling `fit()`.\n\n To reset the states of your model, call `.reset_states()` on either\n a specific layer, or on your entire model.\n\nNote on specifying the initial state of RNNs:\n You can specify the initial state of RNN layers symbolically by\n calling them with the keyword argument `initial_state`. The value of\n `initial_state` should be a tensor or list of tensors representing\n the initial state of the RNN layer.\n\n You can specify the initial state of RNN layers numerically by\n calling `reset_states` with the keyword argument `states`. The value of\n `states` should be a numpy array or list of numpy arrays representing\n the initial state of the RNN layer.\n\nNote on passing external constants to RNNs:\n You can pass \"external\" constants to the cell using the `constants`\n keyword argument of `RNN.__call__` (as well as `RNN.call`) method. This\n requires that the `cell.call` method accepts the same keyword argument\n `constants`. Such constants can be used to condition the cell\n transformation on additional static inputs (not changing over time),\n a.k.a. an attention mechanism.",
  3433. "name": "output"
  3434. }
  3435. ],
  3436. "examples": [
  3437. {
  3438. "code": "# First, let's define a RNN Cell, as a layer subclass.\n\nclass MinimalRNNCell(keras.layers.Layer):\n\n def __init__(self, units, **kwargs):\n self.units = units\n self.state_size = units\n super(MinimalRNNCell, self).__init__(**kwargs)\n\n def build(self, input_shape):\n self.kernel = self.add_weight(shape=(input_shape[-1], self.units),\n initializer='uniform',\n name='kernel')\n self.recurrent_kernel = self.add_weight(\n shape=(self.units, self.units),\n initializer='uniform',\n name='recurrent_kernel')\n self.built = True\n\n def call(self, inputs, states):\n prev_output = states[0]\n h = backend.dot(inputs, self.kernel)\n output = h + backend.dot(prev_output, self.recurrent_kernel)\n return output, [output]\n\n# Let's use this cell in a RNN layer:\n\ncell = MinimalRNNCell(32)\nx = keras.Input((None, 5))\nlayer = RNN(cell)\ny = layer(x)\n\n# Here's how to use the cell to build a stacked RNN:\n\ncells = [MinimalRNNCell(32), MinimalRNNCell(64)]\nx = keras.Input((None, 5))\nlayer = RNN(cells)\ny = layer(x)"
  3439. }
  3440. ]
  3441. },
  3442. {
  3443. "name": "SeparableConv1D",
  3444. "module": "tensorflow.keras.layers",
  3445. "category": "Layer",
  3446. "description": "Depthwise separable 1D convolution.\n\nThis layer performs a depthwise convolution that acts separately on\nchannels, followed by a pointwise convolution that mixes channels.\nIf `use_bias` is True and a bias initializer is provided,\nit adds a bias vector to the output.\nIt then optionally applies an activation function to produce the final\noutput.",
  3447. "attributes": [
  3448. {
  3449. "description": "Integer, the dimensionality of the output space (i.e. the number\n of filters in the convolution).",
  3450. "name": "filters"
  3451. },
  3452. {
  3453. "description": "A single integer specifying the spatial\n dimensions of the filters.",
  3454. "name": "kernel_size"
  3455. },
  3456. {
  3457. "description": "A single integer specifying the strides\n of the convolution.\n Specifying any `stride` value != 1 is incompatible with specifying\n any `dilation_rate` value != 1.",
  3458. "name": "strides"
  3459. },
  3460. {
  3461. "description": "One of `\"valid\"`, `\"same\"`, or `\"causal\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding with zeros\n evenly to the left/right or up/down of the input such that output has\n the same height/width dimension as the input. `\"causal\"` results in\n causal (dilated) convolutions, e.g. `output[t]` does not depend on\n `input[t+1:]`.",
  3462. "name": "padding"
  3463. },
  3464. {
  3465. "description": "A string, one of `channels_last` (default) or\n `channels_first`. The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch_size, length, channels)` while `channels_first` corresponds to\n inputs with shape `(batch_size, channels, length)`.",
  3466. "name": "data_format"
  3467. },
  3468. {
  3469. "description": "A single integer, specifying\n the dilation rate to use for dilated convolution.",
  3470. "name": "dilation_rate"
  3471. },
  3472. {
  3473. "description": "The number of depthwise convolution output channels for\n each input channel. The total number of depthwise convolution output\n channels will be equal to `num_filters_in * depth_multiplier`.",
  3474. "name": "depth_multiplier"
  3475. },
  3476. {
  3477. "description": "Activation function to use.\n If you don't specify anything, no activation is applied\n (see `keras.activations`).",
  3478. "name": "activation"
  3479. },
  3480. {
  3481. "description": "Boolean, whether the layer uses a bias.",
  3482. "name": "use_bias"
  3483. },
  3484. {
  3485. "description": "An initializer for the depthwise convolution kernel\n (see `keras.initializers`). If None, then the default initializer\n ('glorot_uniform') will be used.",
  3486. "name": "depthwise_initializer"
  3487. },
  3488. {
  3489. "description": "An initializer for the pointwise convolution kernel\n (see `keras.initializers`). If None, then the default initializer\n ('glorot_uniform') will be used.",
  3490. "name": "pointwise_initializer"
  3491. },
  3492. {
  3493. "description": "An initializer for the bias vector. If None, the default\n initializer ('zeros') will be used (see `keras.initializers`).",
  3494. "name": "bias_initializer"
  3495. },
  3496. {
  3497. "description": "Optional regularizer for the depthwise\n convolution kernel (see `keras.regularizers`).",
  3498. "name": "depthwise_regularizer"
  3499. },
  3500. {
  3501. "description": "Optional regularizer for the pointwise\n convolution kernel (see `keras.regularizers`).",
  3502. "name": "pointwise_regularizer"
  3503. },
  3504. {
  3505. "description": "Optional regularizer for the bias vector\n (see `keras.regularizers`).",
  3506. "name": "bias_regularizer"
  3507. },
  3508. {
  3509. "description": "Optional regularizer function for the output\n (see `keras.regularizers`).",
  3510. "name": "activity_regularizer"
  3511. },
  3512. {
  3513. "description": "Optional projection function to be applied to the\n depthwise kernel after being updated by an `Optimizer` (e.g. used for\n norm constraints or value constraints for layer weights). The function\n must take as input the unprojected variable and must return the\n projected variable (which must have the same shape). Constraints are\n not safe to use when doing asynchronous distributed training\n (see `keras.constraints`).",
  3514. "name": "depthwise_constraint"
  3515. },
  3516. {
  3517. "description": "Optional projection function to be applied to the\n pointwise kernel after being updated by an `Optimizer`\n (see `keras.constraints`).",
  3518. "name": "pointwise_constraint"
  3519. },
  3520. {
  3521. "description": "Optional projection function to be applied to the\n bias after being updated by an `Optimizer`\n (see `keras.constraints`).",
  3522. "name": "bias_constraint"
  3523. },
  3524. {
  3525. "description": "Boolean, if `True` the weights of this layer will be marked as\n trainable (and listed in `layer.trainable_weights`).",
  3526. "name": "trainable"
  3527. }
  3528. ],
  3529. "inputs": [
  3530. {
  3531. "description": "3D tensor with shape:\n`(batch_size, channels, steps)` if data_format='channels_first'\nor 3D tensor with shape:\n`(batch_size, steps, channels)` if data_format='channels_last'.",
  3532. "name": "input"
  3533. }
  3534. ],
  3535. "outputs": [
  3536. {
  3537. "description": "3D tensor with shape:\n`(batch_size, filters, new_steps)` if data_format='channels_first'\nor 3D tensor with shape:\n`(batch_size, new_steps, filters)` if data_format='channels_last'.\n`new_steps` value might have changed due to padding or strides.",
  3538. "name": "output"
  3539. }
  3540. ]
  3541. },
  3542. {
  3543. "name": "SeparableConv2D",
  3544. "module": "tensorflow.keras.layers",
  3545. "category": "Layer",
  3546. "description": "Depthwise separable 2D convolution.\n\nSeparable convolutions consist of first performing\na depthwise spatial convolution\n(which acts on each input channel separately)\nfollowed by a pointwise convolution which mixes the resulting\noutput channels. The `depth_multiplier` argument controls how many\noutput channels are generated per input channel in the depthwise step.\n\nIntuitively, separable convolutions can be understood as\na way to factorize a convolution kernel into two smaller kernels,\nor as an extreme version of an Inception block.",
  3547. "attributes": [
  3548. {
  3549. "default": "linear",
  3550. "description": "Activation function to use.\n If you don't specify anything, no activation is applied\n (see `keras.activations`).",
  3551. "name": "activation"
  3552. },
  3553. {
  3554. "default": "valid",
  3555. "description": "one of `\"valid\"` or `\"same\"` (case-insensitive).\n `\"valid\"` means no padding. `\"same\"` results in padding with zeros\n evenly to the left/right or up/down of the input such that output has\n the same height/width dimension as the input.",
  3556. "name": "padding"
  3557. },
  3558. {
  3559. "default": true,
  3560. "description": "Boolean, whether the layer uses a bias vector.",
  3561. "name": "use_bias",
  3562. "visible": false
  3563. },
  3564. {
  3565. "default": "channels_last",
  3566. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch_size, height, width, channels)` while `channels_first`\n corresponds to inputs with shape\n `(batch_size, channels, height, width)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  3567. "name": "data_format"
  3568. },
  3569. {
  3570. "default": [
  3571. 1,
  3572. 1
  3573. ],
  3574. "description": "An integer or tuple/list of 2 integers,\n specifying the strides of the convolution along the height and width.\n Can be a single integer to specify the same value for\n all spatial dimensions. Current implementation only supports equal\n length strides in the row and column dimensions.\n Specifying any stride value != 1 is incompatible with specifying\n any `dilation_rate` value != 1.",
  3575. "name": "strides"
  3576. },
  3577. {
  3578. "default": [
  3579. 1,
  3580. 1
  3581. ],
  3582. "description": "An integer or tuple/list of 2 integers, specifying\n the dilation rate to use for dilated convolution.",
  3583. "name": "dilation_rate"
  3584. },
  3585. {
  3586. "default": 1,
  3587. "description": "The number of depthwise convolution output channels\n for each input channel.\n The total number of depthwise convolution output\n channels will be equal to `filters_in * depth_multiplier`.",
  3588. "name": "depth_multiplier"
  3589. },
  3590. {
  3591. "default": {
  3592. "class_name": "VarianceScaling",
  3593. "config": {
  3594. "distribution": "uniform",
  3595. "mode": "fan_avg",
  3596. "scale": 1,
  3597. "seed": null
  3598. }
  3599. },
  3600. "description": "An initializer for the pointwise convolution kernel\n (see `keras.initializers`). If None, then the default initializer\n ('glorot_uniform') will be used.",
  3601. "name": "pointwise_initializer",
  3602. "visible": false
  3603. },
  3604. {
  3605. "default": {
  3606. "class_name": "VarianceScaling",
  3607. "config": {
  3608. "distribution": "uniform",
  3609. "mode": "fan_avg",
  3610. "scale": 1,
  3611. "seed": null
  3612. }
  3613. },
  3614. "description": "An initializer for the depthwise convolution kernel\n (see `keras.initializers`). If None, then the default initializer\n ('glorot_uniform') will be used.",
  3615. "name": "depthwise_initializer",
  3616. "visible": false
  3617. },
  3618. {
  3619. "default": {
  3620. "class_name": "Zeros",
  3621. "config": {}
  3622. },
  3623. "description": "An initializer for the bias vector. If None, the default\n initializer ('zeros') will be used (see `keras.initializers`).",
  3624. "name": "bias_initializer",
  3625. "visible": false
  3626. },
  3627. {
  3628. "default": {
  3629. "class_name": "VarianceScaling",
  3630. "config": {
  3631. "distribution": "uniform",
  3632. "mode": "fan_avg",
  3633. "scale": 1,
  3634. "seed": null
  3635. }
  3636. },
  3637. "name": "kernel_initializer",
  3638. "visible": false
  3639. },
  3640. {
  3641. "description": "Integer, the dimensionality of the output space\n (i.e. the number of output filters in the convolution).",
  3642. "name": "filters"
  3643. },
  3644. {
  3645. "description": "An integer or tuple/list of 2 integers, specifying the\n height and width of the 2D convolution window.\n Can be a single integer to specify the same value for\n all spatial dimensions.",
  3646. "name": "kernel_size"
  3647. },
  3648. {
  3649. "description": "Regularizer function applied to\n the depthwise kernel matrix (see `keras.regularizers`).",
  3650. "name": "depthwise_regularizer",
  3651. "visible": false
  3652. },
  3653. {
  3654. "description": "Regularizer function applied to\n the pointwise kernel matrix (see `keras.regularizers`).",
  3655. "name": "pointwise_regularizer",
  3656. "visible": false
  3657. },
  3658. {
  3659. "description": "Regularizer function applied to the bias vector\n (see `keras.regularizers`).",
  3660. "name": "bias_regularizer",
  3661. "visible": false
  3662. },
  3663. {
  3664. "description": "Regularizer function applied to\n the output of the layer (its \"activation\")\n (see `keras.regularizers`).",
  3665. "name": "activity_regularizer",
  3666. "visible": false
  3667. },
  3668. {
  3669. "description": "Constraint function applied to\n the depthwise kernel matrix\n (see `keras.constraints`).",
  3670. "name": "depthwise_constraint",
  3671. "visible": false
  3672. },
  3673. {
  3674. "description": "Constraint function applied to\n the pointwise kernel matrix\n (see `keras.constraints`).",
  3675. "name": "pointwise_constraint"
  3676. },
  3677. {
  3678. "description": "Constraint function applied to the bias vector\n (see `keras.constraints`).",
  3679. "name": "bias_constraint"
  3680. }
  3681. ],
  3682. "inputs": [
  3683. {
  3684. "description": "4D tensor with shape:\n`(batch_size, channels, rows, cols)` if data_format='channels_first'\nor 4D tensor with shape:\n`(batch_size, rows, cols, channels)` if data_format='channels_last'.",
  3685. "name": "input"
  3686. },
  3687. {
  3688. "name": "kernel"
  3689. },
  3690. {
  3691. "name": "bias"
  3692. }
  3693. ],
  3694. "outputs": [
  3695. {
  3696. "description": "4D tensor with shape:\n`(batch_size, filters, new_rows, new_cols)` if\ndata_format='channels_first'\nor 4D tensor with shape:\n`(batch_size, new_rows, new_cols, filters)` if\ndata_format='channels_last'. `rows` and `cols` values might have changed\ndue to padding.",
  3697. "name": "output"
  3698. }
  3699. ]
  3700. },
  3701. {
  3702. "name": "Sigmoid",
  3703. "category": "Activation"
  3704. },
  3705. {
  3706. "name": "SimpleRNN",
  3707. "module": "tensorflow.keras.layers",
  3708. "category": "Layer",
  3709. "description": "Fully-connected RNN where the output is to be fed back to input.\n\nSee [the Keras RNN API guide](https://www.tensorflow.org/guide/keras/rnn)\nfor details about the usage of RNN API.",
  3710. "attributes": [
  3711. {
  3712. "default": false,
  3713. "description": "Boolean. Whether to return the last output\n in the output sequence, or the full sequence. Default: `False`.",
  3714. "name": "return_sequences"
  3715. },
  3716. {
  3717. "default": false,
  3718. "description": "Boolean. Whether to return the last state\n in addition to the output. Default: `False`",
  3719. "name": "return_state"
  3720. },
  3721. {
  3722. "default": false,
  3723. "description": "Boolean (default False).\n If True, process the input sequence backwards and return the\n reversed sequence.",
  3724. "name": "go_backwards"
  3725. },
  3726. {
  3727. "default": false,
  3728. "description": "Boolean (default False). If True, the last state\n for each sample at index i in a batch will be used as initial\n state for the sample of index i in the following batch.",
  3729. "name": "stateful"
  3730. },
  3731. {
  3732. "default": false,
  3733. "description": "Boolean (default False).\n If True, the network will be unrolled,\n else a symbolic loop will be used.\n Unrolling can speed-up a RNN,\n although it tends to be more memory-intensive.\n Unrolling is only suitable for short sequences.",
  3734. "name": "unroll"
  3735. },
  3736. {
  3737. "default": "tanh",
  3738. "description": "Activation function to use.",
  3739. "name": "activation"
  3740. },
  3741. {
  3742. "default": true,
  3743. "description": "Boolean, (default `True`), whether the layer uses a bias vector.",
  3744. "name": "use_bias",
  3745. "visible": false
  3746. },
  3747. {
  3748. "default": {
  3749. "class_name": "VarianceScaling",
  3750. "config": {
  3751. "distribution": "uniform",
  3752. "mode": "fan_avg",
  3753. "scale": 1,
  3754. "seed": null
  3755. }
  3756. },
  3757. "description": "Initializer for the `kernel` weights matrix,\n used for the linear transformation of the inputs. Default:\n `glorot_uniform`.",
  3758. "name": "kernel_initializer",
  3759. "visible": false
  3760. },
  3761. {
  3762. "default": {
  3763. "class_name": "Orthogonal",
  3764. "config": {
  3765. "gain": 1,
  3766. "seed": null
  3767. }
  3768. },
  3769. "description": "Initializer for the `recurrent_kernel`\n weights matrix, used for the linear transformation of the recurrent\n state. Default: `orthogonal`.",
  3770. "name": "recurrent_initializer",
  3771. "visible": false
  3772. },
  3773. {
  3774. "default": {
  3775. "class_name": "Zeros",
  3776. "config": {}
  3777. },
  3778. "description": "Initializer for the bias vector. Default: `zeros`.",
  3779. "name": "bias_initializer",
  3780. "visible": false
  3781. },
  3782. {
  3783. "default": 0,
  3784. "description": "Float between 0 and 1.\n Fraction of the units to drop for the linear transformation of the\n inputs. Default: 0.",
  3785. "name": "dropout"
  3786. },
  3787. {
  3788. "default": 0,
  3789. "description": "Float between 0 and 1.\n Fraction of the units to drop for the linear transformation of the\n recurrent state. Default: 0.",
  3790. "name": "recurrent_dropout"
  3791. },
  3792. {
  3793. "description": "Positive integer, dimensionality of the output space.",
  3794. "name": "units"
  3795. },
  3796. {
  3797. "description": "Regularizer function applied to the `kernel` weights\n matrix. Default: `None`.",
  3798. "name": "kernel_regularizer",
  3799. "visible": false
  3800. },
  3801. {
  3802. "description": "Regularizer function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  3803. "name": "recurrent_regularizer",
  3804. "visible": false
  3805. },
  3806. {
  3807. "description": "Regularizer function applied to the bias vector.",
  3808. "name": "bias_regularizer",
  3809. "visible": false
  3810. },
  3811. {
  3812. "description": "Regularizer function applied to the output of the\n layer (its \"activation\"). Default: `None`.",
  3813. "name": "activity_regularizer",
  3814. "visible": false
  3815. },
  3816. {
  3817. "description": "Constraint function applied to the `kernel` weights\n matrix. Default: `None`.",
  3818. "name": "kernel_constraint"
  3819. },
  3820. {
  3821. "description": "Constraint function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  3822. "name": "recurrent_constraint"
  3823. },
  3824. {
  3825. "description": "Constraint function applied to the bias vector. Default:\n `None`.",
  3826. "name": "bias_constraint"
  3827. },
  3828. {
  3829. "description": "`None`.",
  3830. "name": "Default"
  3831. }
  3832. ],
  3833. "inputs": [
  3834. {
  3835. "name": "input"
  3836. },
  3837. {
  3838. "name": "kernel"
  3839. },
  3840. {
  3841. "name": "recurrent_kernel"
  3842. },
  3843. {
  3844. "name": "bias"
  3845. }
  3846. ],
  3847. "outputs": [
  3848. {
  3849. "name": "output"
  3850. }
  3851. ],
  3852. "examples": [
  3853. {
  3854. "code": "inputs = np.random.random([32, 10, 8]).astype(np.float32)\nsimple_rnn = tf.keras.layers.SimpleRNN(4)\n\noutput = simple_rnn(inputs) # The output has shape `[32, 4]`.\n\nsimple_rnn = tf.keras.layers.SimpleRNN(\n 4, return_sequences=True, return_state=True)\n\n# whole_sequence_output has shape `[32, 10, 4]`.\n# final_state has shape `[32, 4]`.\nwhole_sequence_output, final_state = simple_rnn(inputs)"
  3855. }
  3856. ]
  3857. },
  3858. {
  3859. "name": "SimpleRNNCell",
  3860. "module": "tensorflow.keras.layers",
  3861. "description": "Cell class for SimpleRNN.\n\nSee [the Keras RNN API guide](https://www.tensorflow.org/guide/keras/rnn)\nfor details about the usage of RNN API.\n\nThis class processes one step within the whole time sequence input, whereas\n`tf.keras.layer.SimpleRNN` processes the whole sequence.",
  3862. "attributes": [
  3863. {
  3864. "description": "Positive integer, dimensionality of the output space.",
  3865. "name": "units"
  3866. },
  3867. {
  3868. "description": "Activation function to use.",
  3869. "name": "activation"
  3870. },
  3871. {
  3872. "description": "Boolean, (default `True`), whether the layer uses a bias vector.",
  3873. "name": "use_bias",
  3874. "visible": false
  3875. },
  3876. {
  3877. "description": "Initializer for the `kernel` weights matrix,\n used for the linear transformation of the inputs. Default:\n `glorot_uniform`.",
  3878. "name": "kernel_initializer",
  3879. "visible": false
  3880. },
  3881. {
  3882. "description": "Initializer for the `recurrent_kernel`\n weights matrix, used for the linear transformation of the recurrent\n state. Default: `orthogonal`.",
  3883. "name": "recurrent_initializer",
  3884. "visible": false
  3885. },
  3886. {
  3887. "description": "Initializer for the bias vector. Default: `zeros`.",
  3888. "name": "bias_initializer",
  3889. "visible": false
  3890. },
  3891. {
  3892. "description": "Regularizer function applied to the `kernel` weights\n matrix. Default: `None`.",
  3893. "name": "kernel_regularizer",
  3894. "visible": false
  3895. },
  3896. {
  3897. "description": "Regularizer function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  3898. "name": "recurrent_regularizer",
  3899. "visible": false
  3900. },
  3901. {
  3902. "description": "Regularizer function applied to the bias vector.",
  3903. "name": "bias_regularizer",
  3904. "visible": false
  3905. },
  3906. {
  3907. "description": "Constraint function applied to the `kernel` weights\n matrix. Default: `None`.",
  3908. "name": "kernel_constraint"
  3909. },
  3910. {
  3911. "description": "Constraint function applied to the\n `recurrent_kernel` weights matrix. Default: `None`.",
  3912. "name": "recurrent_constraint"
  3913. },
  3914. {
  3915. "description": "Constraint function applied to the bias vector. Default:\n `None`.",
  3916. "name": "bias_constraint"
  3917. },
  3918. {
  3919. "default": 0,
  3920. "description": "Float between 0 and 1. Fraction of the units to drop for the\n linear transformation of the inputs. Default: 0.",
  3921. "name": "dropout"
  3922. },
  3923. {
  3924. "default": 0,
  3925. "description": "Float between 0 and 1. Fraction of the units to drop\n for the linear transformation of the recurrent state. Default: 0.",
  3926. "name": "recurrent_dropout"
  3927. },
  3928. {
  3929. "description": "`None`.",
  3930. "name": "Default"
  3931. }
  3932. ],
  3933. "examples": [
  3934. {
  3935. "code": "inputs = np.random.random([32, 10, 8]).astype(np.float32)\nrnn = tf.keras.layers.RNN(tf.keras.layers.SimpleRNNCell(4))\n\noutput = rnn(inputs) # The output has shape `[32, 4]`.\n\nrnn = tf.keras.layers.RNN(\n tf.keras.layers.SimpleRNNCell(4),\n return_sequences=True,\n return_state=True)\n\n# whole_sequence_output has shape `[32, 10, 4]`.\n# final_state has shape `[32, 4]`.\nwhole_sequence_output, final_state = rnn(inputs)"
  3936. }
  3937. ]
  3938. },
  3939. {
  3940. "name": "Softmax",
  3941. "module": "tensorflow.keras.layers",
  3942. "category": "Activation",
  3943. "description": "Softmax activation function.\n\nExample without mask:\n\n```\n>>> inp = np.asarray([1., 2., 1.])\n>>> layer = tf.keras.layers.Softmax()\n>>> layer(inp).numpy()\narray([0.21194157, 0.5761169 , 0.21194157], dtype=float32)\n>>> mask = np.asarray([True, False, True], dtype=bool)\n>>> layer(inp, mask).numpy()\narray([0.5, 0. , 0.5], dtype=float32)\n```",
  3944. "inputs": [
  3945. {
  3946. "name": "input",
  3947. "description": "Arbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the samples axis)\nwhen using this layer as the first layer in a model."
  3948. }
  3949. ],
  3950. "outputs": [
  3951. {
  3952. "name": "output",
  3953. "description": "Same shape as the input."
  3954. }
  3955. ],
  3956. "attributes": [
  3957. {
  3958. "name": "axis",
  3959. "description": "Integer, or list of Integers, axis along which the softmax\n normalization is applied."
  3960. }
  3961. ]
  3962. },
  3963. {
  3964. "name": "SoftPlus",
  3965. "category": "Activation"
  3966. },
  3967. {
  3968. "name": "SoftSign",
  3969. "category": "Activation"
  3970. },
  3971. {
  3972. "name": "SpatialDropout1D",
  3973. "module": "tensorflow.keras.layers",
  3974. "category": "Dropout",
  3975. "description": "Spatial 1D version of Dropout.\n\nThis version performs the same function as Dropout, however, it drops\nentire 1D feature maps instead of individual elements. If adjacent frames\nwithin feature maps are strongly correlated (as is normally the case in\nearly convolution layers) then regular dropout will not regularize the\nactivations and will otherwise just result in an effective learning rate\ndecrease. In this case, SpatialDropout1D will help promote independence\nbetween feature maps and should be used instead.",
  3976. "attributes": [
  3977. {
  3978. "description": "Float between 0 and 1. Fraction of the input units to drop.",
  3979. "name": "rate"
  3980. }
  3981. ],
  3982. "inputs": [
  3983. {
  3984. "description": "3D tensor with shape: `(samples, timesteps, channels)`\nOutput shape: Same as input.\nReferences: - [Efficient Object Localization Using Convolutional\n Networks](https://arxiv.org/abs/1411.4280)",
  3985. "name": "input"
  3986. }
  3987. ],
  3988. "outputs": [
  3989. {
  3990. "description": "Same as input.",
  3991. "name": "output"
  3992. }
  3993. ],
  3994. "references": [
  3995. {
  3996. "description": "[Efficient Object Localization Using Convolutional Networks](https://arxiv.org/abs/1411.4280)"
  3997. }
  3998. ]
  3999. },
  4000. {
  4001. "name": "SpatialDropout2D",
  4002. "module": "tensorflow.keras.layers",
  4003. "category": "Dropout",
  4004. "description": "Spatial 2D version of Dropout.\n\nThis version performs the same function as Dropout, however, it drops\nentire 2D feature maps instead of individual elements. If adjacent pixels\nwithin feature maps are strongly correlated (as is normally the case in\nearly convolution layers) then regular dropout will not regularize the\nactivations and will otherwise just result in an effective learning rate\ndecrease. In this case, SpatialDropout2D will help promote independence\nbetween feature maps and should be used instead.",
  4005. "attributes": [
  4006. {
  4007. "description": "Float between 0 and 1. Fraction of the input units to drop.",
  4008. "name": "rate"
  4009. },
  4010. {
  4011. "description": "'channels_first' or 'channels_last'. In 'channels_first'\n mode, the channels dimension (the depth) is at index 1, in\n 'channels_last' mode is it at index 3. It defaults to the\n `image_data_format` value found in your Keras config file at\n `~/.keras/keras.json`. If you never set it, then it will be\n \"channels_last\".",
  4012. "name": "data_format"
  4013. }
  4014. ],
  4015. "inputs": [
  4016. {
  4017. "description": "4D tensor with shape: `(samples, channels, rows, cols)` if\n data_format='channels_first'\n or 4D tensor with shape: `(samples, rows, cols, channels)` if\n data_format='channels_last'.\nOutput shape: Same as input.\nReferences: - [Efficient Object Localization Using Convolutional\n Networks](https://arxiv.org/abs/1411.4280)",
  4018. "name": "input"
  4019. }
  4020. ],
  4021. "outputs": [
  4022. {
  4023. "description": "Same as input.",
  4024. "name": "output"
  4025. }
  4026. ],
  4027. "references": [
  4028. {
  4029. "description": "[Efficient Object Localization Using Convolutional Networks](https://arxiv.org/abs/1411.4280)"
  4030. }
  4031. ]
  4032. },
  4033. {
  4034. "name": "SpatialDropout3D",
  4035. "module": "tensorflow.keras.layers",
  4036. "category": "Dropout",
  4037. "description": "Spatial 3D version of Dropout.\n\nThis version performs the same function as Dropout, however, it drops\nentire 3D feature maps instead of individual elements. If adjacent voxels\nwithin feature maps are strongly correlated (as is normally the case in\nearly convolution layers) then regular dropout will not regularize the\nactivations and will otherwise just result in an effective learning rate\ndecrease. In this case, SpatialDropout3D will help promote independence\nbetween feature maps and should be used instead.",
  4038. "attributes": [
  4039. {
  4040. "description": "Float between 0 and 1. Fraction of the input units to drop.",
  4041. "name": "rate"
  4042. },
  4043. {
  4044. "description": "'channels_first' or 'channels_last'. In 'channels_first'\n mode, the channels dimension (the depth) is at index 1, in\n 'channels_last' mode is it at index 4. It defaults to the\n `image_data_format` value found in your Keras config file at\n `~/.keras/keras.json`. If you never set it, then it will be\n \"channels_last\".",
  4045. "name": "data_format"
  4046. }
  4047. ],
  4048. "inputs": [
  4049. {
  4050. "description": "5D tensor with shape: `(samples, channels, dim1, dim2, dim3)` if\n data_format='channels_first'\n or 5D tensor with shape: `(samples, dim1, dim2, dim3, channels)` if\n data_format='channels_last'.\nOutput shape: Same as input.\nReferences: - [Efficient Object Localization Using Convolutional\n Networks](https://arxiv.org/abs/1411.4280)",
  4051. "name": "input"
  4052. }
  4053. ],
  4054. "outputs": [
  4055. {
  4056. "description": "Same as input.",
  4057. "name": "output"
  4058. }
  4059. ],
  4060. "references": [
  4061. {
  4062. "description": "[Efficient Object Localization Using Convolutional Networks](https://arxiv.org/abs/1411.4280)"
  4063. }
  4064. ]
  4065. },
  4066. {
  4067. "name": "StackedRNNCells",
  4068. "module": "tensorflow.keras.layers",
  4069. "description": "Wrapper allowing a stack of RNN cells to behave as a single cell.\n\nUsed to implement efficient stacked RNNs.",
  4070. "attributes": [
  4071. {
  4072. "description": "List of RNN cell instances.",
  4073. "name": "cells"
  4074. }
  4075. ],
  4076. "examples": [
  4077. {
  4078. "code": "batch_size = 3\nsentence_max_length = 5\nn_features = 2\nnew_shape = (batch_size, sentence_max_length, n_features)\nx = tf.constant(np.reshape(np.arange(30), new_shape), dtype = tf.float32)\n\nrnn_cells = [tf.keras.layers.LSTMCell(128) for _ in range(2)]\nstacked_lstm = tf.keras.layers.StackedRNNCells(rnn_cells)\nlstm_layer = tf.keras.layers.RNN(stacked_lstm)\n\nresult = lstm_layer(x)"
  4079. }
  4080. ]
  4081. },
  4082. {
  4083. "name": "Subtract",
  4084. "module": "tensorflow.keras.layers",
  4085. "description": "Layer that subtracts two inputs.\n\nIt takes as input a list of tensors of size 2, both of the same shape, and\nreturns a single tensor, (inputs[0] - inputs[1]), also of the same shape.",
  4086. "inputs": [
  4087. {
  4088. "name": "x"
  4089. },
  4090. {
  4091. "name": "y"
  4092. }
  4093. ],
  4094. "outputs": [
  4095. {
  4096. "name": "z"
  4097. }
  4098. ],
  4099. "examples": [
  4100. {
  4101. "code": " import keras\n\n input1 = keras.layers.Input(shape=(16,))\n x1 = keras.layers.Dense(8, activation='relu')(input1)\n input2 = keras.layers.Input(shape=(32,))\n x2 = keras.layers.Dense(8, activation='relu')(input2)\n # Equivalent to subtracted = keras.layers.subtract([x1, x2])\n subtracted = keras.layers.Subtract()([x1, x2])\n\n out = keras.layers.Dense(4)(subtracted)\n model = keras.models.Model(inputs=[input1, input2], outputs=out)"
  4102. }
  4103. ]
  4104. },
  4105. {
  4106. "name": "TanH",
  4107. "category": "Activation"
  4108. },
  4109. {
  4110. "name": "ThresholdedReLU",
  4111. "module": "tensorflow.keras.layers",
  4112. "category": "Activation",
  4113. "description": "Thresholded Rectified Linear Unit.\n\nIt follows:\n\n```\n f(x) = x for x > theta\n f(x) = 0 otherwise`\n```",
  4114. "attributes": [
  4115. {
  4116. "description": "Float >= 0. Threshold location of activation.",
  4117. "name": "theta"
  4118. }
  4119. ],
  4120. "inputs": [
  4121. {
  4122. "description": "Arbitrary. Use the keyword argument `input_shape`\n(tuple of integers, does not include the samples axis)\nwhen using this layer as the first layer in a model.",
  4123. "name": "input"
  4124. }
  4125. ],
  4126. "outputs": [
  4127. {
  4128. "description": "Same shape as the input.",
  4129. "name": "output"
  4130. }
  4131. ],
  4132. "references": [
  4133. {
  4134. "description": "[Zero-Bias Autoencoders and the Benefits of Co-Adapting Features]( https://arxiv.org/abs/1402.3337)"
  4135. }
  4136. ]
  4137. },
  4138. {
  4139. "name": "TimeDistributed",
  4140. "module": "tensorflow.keras.layers",
  4141. "category": "Wrapper",
  4142. "description": "This wrapper allows to apply a layer to every temporal slice of an input.\n\nEvery input should be at least 3D, and the dimension of index one of the\nfirst input will be considered to be the temporal dimension.\n\nConsider a batch of 32 video samples, where each sample is a 128x128 RGB\nimage with `channels_last` data format, across 10 timesteps.\nThe batch input shape is `(32, 10, 128, 128, 3)`.\n\nYou can then use `TimeDistributed` to apply the same `Conv2D` layer to each\nof the 10 timesteps, independently:\n\n```\n>>> inputs = tf.keras.Input(shape=(10, 128, 128, 3))\n>>> conv_2d_layer = tf.keras.layers.Conv2D(64, (3, 3))\n>>> outputs = tf.keras.layers.TimeDistributed(conv_2d_layer)(inputs)\n>>> outputs.shape\nTensorShape([None, 10, 126, 126, 64])\n```\n\nBecause `TimeDistributed` applies the same instance of `Conv2D` to each of\nthe timestamps, the same set of weights are used at each timestamp.",
  4143. "attributes": [
  4144. {
  4145. "description": "a `tf.keras.layers.Layer` instance.",
  4146. "name": "layer"
  4147. }
  4148. ],
  4149. "inputs": [
  4150. {
  4151. "name": "input"
  4152. }
  4153. ],
  4154. "outputs": [
  4155. {
  4156. "name": "output"
  4157. }
  4158. ]
  4159. },
  4160. {
  4161. "name": "UpSampling1D",
  4162. "module": "tensorflow.keras.layers",
  4163. "category": "Layer",
  4164. "description": "Upsampling layer for 1D inputs.\n\nRepeats each temporal step `size` times along the time axis.",
  4165. "attributes": [
  4166. {
  4167. "default": "channels_last",
  4168. "name": "data_format"
  4169. },
  4170. {
  4171. "description": "Integer. Upsampling factor.",
  4172. "name": "size"
  4173. }
  4174. ],
  4175. "inputs": [
  4176. {
  4177. "description": "3D tensor with shape: `(batch_size, steps, features)`.",
  4178. "name": "input"
  4179. }
  4180. ],
  4181. "outputs": [
  4182. {
  4183. "description": "3D tensor with shape: `(batch_size, upsampled_steps, features)`.",
  4184. "name": "output"
  4185. }
  4186. ],
  4187. "examples": [
  4188. {
  4189. "code": ">>> input_shape = (2, 2, 3)\n>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)\n>>> print(x)\n[[[ 0 1 2]\n [ 3 4 5]]\n [[ 6 7 8]\n [ 9 10 11]]]\n>>> y = tf.keras.layers.UpSampling1D(size=2)(x)\n>>> print(y)\ntf.Tensor(\n [[[ 0 1 2]\n [ 0 1 2]\n [ 3 4 5]\n [ 3 4 5]]\n [[ 6 7 8]\n [ 6 7 8]\n [ 9 10 11]\n [ 9 10 11]]], shape=(2, 4, 3), dtype=int64)"
  4190. }
  4191. ]
  4192. },
  4193. {
  4194. "name": "UpSampling2D",
  4195. "module": "tensorflow.keras.layers",
  4196. "category": "Layer",
  4197. "description": "Upsampling layer for 2D inputs.\n\nRepeats the rows and columns of the data\nby `size[0]` and `size[1]` respectively.",
  4198. "attributes": [
  4199. {
  4200. "default": "channels_last",
  4201. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch_size, height, width, channels)` while `channels_first`\n corresponds to inputs with shape\n `(batch_size, channels, height, width)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  4202. "name": "data_format"
  4203. },
  4204. {
  4205. "description": "Int, or tuple of 2 integers.\n The upsampling factors for rows and columns.",
  4206. "name": "size"
  4207. },
  4208. {
  4209. "description": "A string, one of `\"area\"`, `\"bicubic\"`, `\"bilinear\"`,\n `\"gaussian\"`, `\"lanczos3\"`, `\"lanczos5\"`, `\"mitchellcubic\"`,\n `\"nearest\"`.",
  4210. "name": "interpolation"
  4211. }
  4212. ],
  4213. "inputs": [
  4214. {
  4215. "description": "4D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, rows, cols, channels)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, channels, rows, cols)`",
  4216. "name": "input"
  4217. }
  4218. ],
  4219. "outputs": [
  4220. {
  4221. "description": "4D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, upsampled_rows, upsampled_cols, channels)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, channels, upsampled_rows, upsampled_cols)`",
  4222. "name": "output"
  4223. }
  4224. ],
  4225. "examples": [
  4226. {
  4227. "code": ">>> input_shape = (2, 2, 1, 3)\n>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)\n>>> print(x)\n[[[[ 0 1 2]]\n [[ 3 4 5]]]\n [[[ 6 7 8]]\n [[ 9 10 11]]]]\n>>> y = tf.keras.layers.UpSampling2D(size=(1, 2))(x)\n>>> print(y)\ntf.Tensor(\n [[[[ 0 1 2]\n [ 0 1 2]]\n [[ 3 4 5]\n [ 3 4 5]]]\n [[[ 6 7 8]\n [ 6 7 8]]\n [[ 9 10 11]\n [ 9 10 11]]]], shape=(2, 2, 2, 3), dtype=int64)"
  4228. }
  4229. ]
  4230. },
  4231. {
  4232. "name": "UpSampling3D",
  4233. "module": "tensorflow.keras.layers",
  4234. "category": "Layer",
  4235. "description": "Upsampling layer for 3D inputs.\n\nRepeats the 1st, 2nd and 3rd dimensions\nof the data by `size[0]`, `size[1]` and `size[2]` respectively.",
  4236. "attributes": [
  4237. {
  4238. "default": "channels_last",
  4239. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)`\n while `channels_first` corresponds to inputs with shape\n `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  4240. "name": "data_format"
  4241. },
  4242. {
  4243. "description": "Int, or tuple of 3 integers.\n The upsampling factors for dim1, dim2 and dim3.",
  4244. "name": "size"
  4245. }
  4246. ],
  4247. "inputs": [
  4248. {
  4249. "description": "5D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, dim1, dim2, dim3, channels)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, channels, dim1, dim2, dim3)`",
  4250. "name": "input"
  4251. }
  4252. ],
  4253. "outputs": [
  4254. {
  4255. "description": "5D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, upsampled_dim1, upsampled_dim2, upsampled_dim3,\n channels)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, channels, upsampled_dim1, upsampled_dim2,\n upsampled_dim3)`",
  4256. "name": "output"
  4257. }
  4258. ],
  4259. "examples": [
  4260. {
  4261. "code": ">>> input_shape = (2, 1, 2, 1, 3)\n>>> x = tf.constant(1, shape=input_shape)\n>>> y = tf.keras.layers.UpSampling3D(size=2)(x)\n>>> print(y.shape)\n(2, 2, 4, 2, 3)"
  4262. }
  4263. ]
  4264. },
  4265. {
  4266. "name": "ZeroPadding1D",
  4267. "module": "tensorflow.keras.layers",
  4268. "category": "Tensor",
  4269. "description": "Zero-padding layer for 1D input (e.g. temporal sequence).",
  4270. "attributes": [
  4271. {
  4272. "description": "Int, or tuple of int (length 2), or dictionary.\n - If int:\n How many zeros to add at the beginning and end of\n the padding dimension (axis 1).\n - If tuple of int (length 2):\n How many zeros to add at the beginning and the end of\n the padding dimension (`(left_pad, right_pad)`).",
  4273. "name": "padding"
  4274. }
  4275. ],
  4276. "inputs": [
  4277. {
  4278. "description": "3D tensor with shape `(batch_size, axis_to_pad, features)`",
  4279. "name": "input"
  4280. }
  4281. ],
  4282. "outputs": [
  4283. {
  4284. "description": "3D tensor with shape `(batch_size, padded_axis, features)`",
  4285. "name": "output"
  4286. }
  4287. ],
  4288. "examples": [
  4289. {
  4290. "code": ">>> input_shape = (2, 2, 3)\n>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)\n>>> print(x)\n[[[ 0 1 2]\n [ 3 4 5]]\n [[ 6 7 8]\n [ 9 10 11]]]\n>>> y = tf.keras.layers.ZeroPadding1D(padding=2)(x)\n>>> print(y)\ntf.Tensor(\n [[[ 0 0 0]\n [ 0 0 0]\n [ 0 1 2]\n [ 3 4 5]\n [ 0 0 0]\n [ 0 0 0]]\n [[ 0 0 0]\n [ 0 0 0]\n [ 6 7 8]\n [ 9 10 11]\n [ 0 0 0]\n [ 0 0 0]]], shape=(2, 6, 3), dtype=int64)"
  4291. }
  4292. ]
  4293. },
  4294. {
  4295. "name": "ZeroPadding2D",
  4296. "module": "tensorflow.keras.layers",
  4297. "category": "Tensor",
  4298. "description": "Zero-padding layer for 2D input (e.g. picture).\n\nThis layer can add rows and columns of zeros\nat the top, bottom, left and right side of an image tensor.",
  4299. "attributes": [
  4300. {
  4301. "description": "Int, or tuple of 2 ints, or tuple of 2 tuples of 2 ints.\n - If int: the same symmetric padding\n is applied to height and width.\n - If tuple of 2 ints:\n interpreted as two different\n symmetric padding values for height and width:\n `(symmetric_height_pad, symmetric_width_pad)`.\n - If tuple of 2 tuples of 2 ints:\n interpreted as\n `((top_pad, bottom_pad), (left_pad, right_pad))`",
  4302. "name": "padding"
  4303. },
  4304. {
  4305. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch_size, height, width, channels)` while `channels_first`\n corresponds to inputs with shape\n `(batch_size, channels, height, width)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  4306. "name": "data_format"
  4307. }
  4308. ],
  4309. "inputs": [
  4310. {
  4311. "description": "4D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, rows, cols, channels)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, channels, rows, cols)`",
  4312. "name": "input"
  4313. }
  4314. ],
  4315. "outputs": [
  4316. {
  4317. "description": "4D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, padded_rows, padded_cols, channels)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, channels, padded_rows, padded_cols)`",
  4318. "name": "output"
  4319. }
  4320. ],
  4321. "examples": [
  4322. {
  4323. "code": ">>> input_shape = (1, 1, 2, 2)\n>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)\n>>> print(x)\n[[[[0 1]\n [2 3]]]]\n>>> y = tf.keras.layers.ZeroPadding2D(padding=1)(x)\n>>> print(y)\ntf.Tensor(\n [[[[0 0]\n [0 0]\n [0 0]\n [0 0]]\n [[0 0]\n [0 1]\n [2 3]\n [0 0]]\n [[0 0]\n [0 0]\n [0 0]\n [0 0]]]], shape=(1, 3, 4, 2), dtype=int64)"
  4324. }
  4325. ]
  4326. },
  4327. {
  4328. "name": "ZeroPadding3D",
  4329. "module": "tensorflow.keras.layers",
  4330. "category": "Tensor",
  4331. "description": "Zero-padding layer for 3D data (spatial or spatio-temporal).",
  4332. "attributes": [
  4333. {
  4334. "description": "Int, or tuple of 3 ints, or tuple of 3 tuples of 2 ints.\n - If int: the same symmetric padding\n is applied to height and width.\n - If tuple of 3 ints:\n interpreted as two different\n symmetric padding values for height and width:\n `(symmetric_dim1_pad, symmetric_dim2_pad, symmetric_dim3_pad)`.\n - If tuple of 3 tuples of 2 ints:\n interpreted as\n `((left_dim1_pad, right_dim1_pad), (left_dim2_pad,\n right_dim2_pad), (left_dim3_pad, right_dim3_pad))`",
  4335. "name": "padding"
  4336. },
  4337. {
  4338. "description": "A string,\n one of `channels_last` (default) or `channels_first`.\n The ordering of the dimensions in the inputs.\n `channels_last` corresponds to inputs with shape\n `(batch_size, spatial_dim1, spatial_dim2, spatial_dim3, channels)`\n while `channels_first` corresponds to inputs with shape\n `(batch_size, channels, spatial_dim1, spatial_dim2, spatial_dim3)`.\n It defaults to the `image_data_format` value found in your\n Keras config file at `~/.keras/keras.json`.\n If you never set it, then it will be \"channels_last\".",
  4339. "name": "data_format"
  4340. }
  4341. ],
  4342. "inputs": [
  4343. {
  4344. "description": "5D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, first_axis_to_pad, second_axis_to_pad,\n third_axis_to_pad, depth)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, depth, first_axis_to_pad, second_axis_to_pad,\n third_axis_to_pad)`",
  4345. "name": "input"
  4346. }
  4347. ],
  4348. "outputs": [
  4349. {
  4350. "description": "5D tensor with shape:\n- If `data_format` is `\"channels_last\"`:\n `(batch_size, first_padded_axis, second_padded_axis,\n third_axis_to_pad, depth)`\n- If `data_format` is `\"channels_first\"`:\n `(batch_size, depth, first_padded_axis, second_padded_axis,\n third_axis_to_pad)`",
  4351. "name": "output"
  4352. }
  4353. ],
  4354. "examples": [
  4355. {
  4356. "code": ">>> input_shape = (1, 1, 2, 2, 3)\n>>> x = np.arange(np.prod(input_shape)).reshape(input_shape)\n>>> y = tf.keras.layers.ZeroPadding3D(padding=2)(x)\n>>> print(y.shape)\n(1, 5, 6, 6, 3)"
  4357. }
  4358. ]
  4359. },
  4360. {
  4361. "name": "Attention",
  4362. "module": "tensorflow.keras.layers",
  4363. "inputs": [
  4364. {
  4365. "name": "query",
  4366. "type": "Tensor[]"
  4367. },
  4368. {
  4369. "name": "value",
  4370. "type": "Tensor[]"
  4371. }
  4372. ],
  4373. "outputs": [
  4374. {
  4375. "name": "output"
  4376. }
  4377. ],
  4378. "description": "Dot-product attention layer, a.k.a. Luong-style attention.\n\nInputs are `query` tensor of shape `[batch_size, Tq, dim]`, `value` tensor\nof shape `[batch_size, Tv, dim]` and `key` tensor of shape\n`[batch_size, Tv, dim]`. The calculation follows the steps:\n\n1. Calculate scores with shape `[batch_size, Tq, Tv]` as a `query`-`key` dot\n product: `scores = tf.matmul(query, key, transpose_b=True)`.\n2. Use scores to calculate a distribution with shape\n `[batch_size, Tq, Tv]`: `distribution = tf.nn.softmax(scores)`.\n3. Use `distribution` to create a linear combination of `value` with\n shape `[batch_size, Tq, dim]`:\n `return tf.matmul(distribution, value)`.",
  4379. "attributes": [
  4380. {
  4381. "name": "use_scale",
  4382. "description": "If `True`, will create a scalar variable to scale the attention\n scores."
  4383. },
  4384. {
  4385. "name": "causal",
  4386. "description": "Boolean. Set to `True` for decoder self-attention. Adds a mask\n such that position `i` cannot attend to positions `j > i`. This prevents\n the flow of information from the future towards the past. Defaults to\n `False`."
  4387. },
  4388. {
  4389. "name": "dropout",
  4390. "description": "Float between 0 and 1. Fraction of the units to drop for the\n attention scores. Defaults to 0.0."
  4391. },
  4392. {
  4393. "name": "inputs",
  4394. "description": "List of the following tensors:\n * query: Query `Tensor` of shape `[batch_size, Tq, dim]`.\n * value: Value `Tensor` of shape `[batch_size, Tv, dim]`.\n * key: Optional key `Tensor` of shape `[batch_size, Tv, dim]`. If not\n given, will use `value` for both `key` and `value`, which is the\n most common case."
  4395. },
  4396. {
  4397. "name": "mask",
  4398. "description": "List of the following tensors:\n * query_mask: A boolean mask `Tensor` of shape `[batch_size, Tq]`.\n If given, the output will be zero at the positions where\n `mask==False`.\n * value_mask: A boolean mask `Tensor` of shape `[batch_size, Tv]`.\n If given, will apply the mask such that values at positions where\n `mask==False` do not contribute to the result."
  4399. },
  4400. {
  4401. "name": "return_attention_scores",
  4402. "description": "bool, it `True`, returns the attention scores\n (after masking and softmax) as an additional output argument."
  4403. },
  4404. {
  4405. "name": "training",
  4406. "description": "Python boolean indicating whether the layer should behave in\n training mode (adding dropout) or in inference mode (no dropout)."
  4407. },
  4408. {
  4409. "name": "score_mode",
  4410. "description": "Function to use to compute attention scores, one of\n `{\"dot\", \"concat\"}`. `\"dot\"` refers to the dot product between the query\n and key vectors. `\"concat\"` refers to the hyperbolic tangent of the\n concatenation of the query and key vectors.\n\nCall Args:"
  4411. },
  4412. {
  4413. "name": "use_causal_mask",
  4414. "description": "Boolean. Set to `True` for decoder self-attention. Adds a\n mask such that position `i` cannot attend to positions `j > i`. This\n prevents the flow of information from the future towards the past.\n Defaults to `False`.\n\nOutput:\n\n Attention outputs of shape `[batch_size, Tq, dim]`.\n [Optional] Attention scores after masking and softmax with shape\n `[batch_size, Tq, Tv]`.\n\nThe meaning of `query`, `value` and `key` depend on the application. In the\ncase of text similarity, for example, `query` is the sequence embeddings of\nthe first piece of text and `value` is the sequence embeddings of the second\npiece of text. `key` is usually the same tensor as `value`.\n\nHere is a code example for using `Attention` in a CNN+Attention network:\n\n```python\n# Variable-length int sequences.\nquery_input = tf.keras.Input(shape=(None,), dtype='int32')\nvalue_input = tf.keras.Input(shape=(None,), dtype='int32')\n\n# Embedding lookup.\ntoken_embedding = tf.keras.layers.Embedding(input_dim=1000, output_dim=64)\n# Query embeddings of shape [batch_size, Tq, dimension].\nquery_embeddings = token_embedding(query_input)\n# Value embeddings of shape [batch_size, Tv, dimension].\nvalue_embeddings = token_embedding(value_input)\n\n# CNN layer.\ncnn_layer = tf.keras.layers.Conv1D(\n filters=100,\n kernel_size=4,\n # Use 'same' padding so outputs have the same shape as inputs.\n padding='same')\n# Query encoding of shape [batch_size, Tq, filters].\nquery_seq_encoding = cnn_layer(query_embeddings)\n# Value encoding of shape [batch_size, Tv, filters].\nvalue_seq_encoding = cnn_layer(value_embeddings)\n\n# Query-value attention of shape [batch_size, Tq, filters].\nquery_value_attention_seq = tf.keras.layers.Attention()(\n [query_seq_encoding, value_seq_encoding])\n\n# Reduce over the sequence axis to produce encodings of shape\n# [batch_size, filters].\nquery_encoding = tf.keras.layers.GlobalAveragePooling1D()(\n query_seq_encoding)\nquery_value_attention = tf.keras.layers.GlobalAveragePooling1D()(\n query_value_attention_seq)\n\n# Concatenate query and document encodings to produce a DNN input layer.\ninput_layer = tf.keras.layers.Concatenate()(\n [query_encoding, query_value_attention])\n\n# Add DNN layers, and create Model.\n# ...\n```"
  4415. }
  4416. ]
  4417. },
  4418. {
  4419. "name": "nn.relu",
  4420. "category": "Activation",
  4421. "inputs": [
  4422. {
  4423. "name": "input"
  4424. }
  4425. ],
  4426. "outputs": [
  4427. {
  4428. "name": "output"
  4429. }
  4430. ]
  4431. },
  4432. {
  4433. "name": "math.add",
  4434. "inputs": [
  4435. {
  4436. "name": "x",
  4437. "type": "Tensor"
  4438. },
  4439. {
  4440. "name": "y",
  4441. "type": "Tensor"
  4442. }
  4443. ],
  4444. "outputs": [
  4445. {
  4446. "name": "z"
  4447. }
  4448. ]
  4449. },
  4450. {
  4451. "name": "__operators__.add",
  4452. "inputs": [
  4453. {
  4454. "name": "x",
  4455. "type": "Tensor"
  4456. },
  4457. {
  4458. "name": "y",
  4459. "type": "Tensor"
  4460. }
  4461. ],
  4462. "outputs": [
  4463. {
  4464. "name": "z"
  4465. }
  4466. ]
  4467. },
  4468. {
  4469. "name": "linalg.matmul",
  4470. "attributes": [
  4471. {
  4472. "name": "transpose_a",
  4473. "type": "boolean"
  4474. },
  4475. {
  4476. "name": "transpose_b",
  4477. "type": "boolean"
  4478. }
  4479. ],
  4480. "inputs": [
  4481. {
  4482. "name": "a",
  4483. "type": "Tensor"
  4484. },
  4485. {
  4486. "name": "b",
  4487. "type": "Tensor"
  4488. }
  4489. ],
  4490. "outputs": [
  4491. {
  4492. "name": "c",
  4493. "type": "Tensor"
  4494. }
  4495. ]
  4496. },
  4497. {
  4498. "name": "nn.abs",
  4499. "inputs": [
  4500. {
  4501. "name": "input"
  4502. }
  4503. ],
  4504. "outputs": [
  4505. {
  4506. "name": "output"
  4507. }
  4508. ]
  4509. },
  4510. {
  4511. "name": "math.sigmoid",
  4512. "category": "Activation",
  4513. "inputs": [
  4514. {
  4515. "name": "input"
  4516. }
  4517. ],
  4518. "outputs": [
  4519. {
  4520. "name": "output"
  4521. }
  4522. ]
  4523. },
  4524. {
  4525. "name": "reshape",
  4526. "category": "Shape",
  4527. "inputs": [
  4528. {
  4529. "name": "input"
  4530. }
  4531. ],
  4532. "outputs": [
  4533. {
  4534. "name": "output"
  4535. }
  4536. ]
  4537. },
  4538. {
  4539. "name": "concat",
  4540. "category": "Tensor",
  4541. "inputs": [
  4542. {
  4543. "name": "inputs",
  4544. "list": true
  4545. }
  4546. ],
  4547. "outputs": [
  4548. {
  4549. "name": "output"
  4550. }
  4551. ]
  4552. },
  4553. {
  4554. "name": "compat.v1.transpose",
  4555. "category": "Shape",
  4556. "inputs": [
  4557. {
  4558. "name": "input"
  4559. }
  4560. ],
  4561. "outputs": [
  4562. {
  4563. "name": "output"
  4564. }
  4565. ]
  4566. }
  4567. ]