0% found this document useful (0 votes)
13 views23 pages

NNDL Lab Record

Record work

Uploaded by

nareshamgoth04
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
13 views23 pages

NNDL Lab Record

Record work

Uploaded by

nareshamgoth04
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
pots : QIBGIAGGRA [Link]-_OL a geting OP “the Spysien MDE envionment and executing Python Progyarm ingiall golution : rheve adie 3 voays +0 — U ype System methocd -1 + UBing Anaconda Tnstal) Spyder TDE oT) —the Anaconda - = navigator 1 open he Anaconda novigatov application 2-40 to the Envivonments tal 4 Select the environment where you want tO iwSial) Spyies 10 & seosch for 'SPyelev’ ty the Seasich loo) fb click on he “ingtaiy! button newt 10 Spyder dy mSiall t+ Method-2 : TnSto\\ SPyciev TPE using Pip, the Python Package - eras) a * OPen the —teymival OY command PyOmpt Avanthi Institute of Engineering & Technology Gunthapally (V), Abdullapurmet (M) Near Ramol Filmolty, RRDist, Hyderabad Command -to ‘mn a. Tyre the —fottowing TOE’ pip tnsiall Pychev 3. Once the ISHallation %3 complete, you Spystev TOE Prom ~he -texminal oy 0 prompt by rq ‘Spydey Method -3 : Frm he of ficial Spyder PDE « Pu can also download and isiall Spyder FOE dhecily trom +he official website . 1. Go-40 +he website at WAEPS sf frocow9. Spycier -ide pag |. a click on +he dovonlvad button 3 Select your o5 trom +e dropdown menu fe I. chooSe appropriate § vesision of spysier Epe oy gow Sj a bP. Download the ‘nstallaton Pile and wun tH eestg) 2 Pysiom: program : kgo to ‘File’ >'new rile’ +0 create a new Python - - gevipt write Some code in tre Script edttoy 3 Sow the Script +2 a file wrth —he “oy * ex4enSion | tor ex, you can Gove it 8 “[Link]® . of Engineering & Technol. Fvantht intizate of Foatneering & Technology roto. + 6A 1 Exot. No. ly TO YUN —the Script, 90 to preeess Fir. this ‘Run*= “Run he file” oF Skewte he pyrron Sevipe and alispley the output rer) in the console tnchividual Js. gor can also use the console -to Yun individua hnes Of code. ro do his, type dhe code in the console ond press entey “the output wih be Aisplayect th the console Trograrnme y Rame= “vivee Nome pint CHello student 2) mint C’ yous home : 3 Name) Engineering & Technolo Avanthi Ee Gnas ne cere Gunthapaly (0 mano > 6680 Expt. No 2s anstalting Kevas, Tengorflow anc Pysorch braves ond mayen ge of hem solution ™ Stalling Kesag GER? G00 official Ine www Python. 0 SHep-8: Cate vidual environment e:\=pip Install Kexag inside he eP-3: Ackvate the envivonment by movie command "Kexasenv' foldey and type the be loo s\env\ sevipts \netivate Anstall —rensortiow. ; rensorPioo 78 one of he we need ~10 insiall before Keres “an be Instatled backend engines —thot 1; TYPE Command create a virtual environment cilomkdiy +egt C:\> cd 43 ci\> pip insta\l +ensorflow sep-a, Type command to eveote A vivtual envivin- -ment. with Python Python-am venv tf —vittual env PEP-3: “YPC commond +o actvateg -rhe environment _ source +£- virtual — env | bin] actvate Avanthi Institute of Engineering & Technology Gunthapaly (V), Abdullapurmet (M) Near Ramoj Filmeity, [Link], Hyderabad TYPE command +0 fnStall Tensorfinw without PO Support CN> PIP tnstaly - upgrade tensorflovs use the Same command for upderting rensorf low. ( Een eseictie ee A Envivoment by the +yPe Ones to +egt yous environment, open EN Python bash ; CV > Python Type command fox import ~the senor flow Packages into the. python. impovt enSorfious ag tf Hype command Know versidn Piint Cveusion of Tensorfiow ¢ 4 exsion ~) Python leis instaijoton the otowsing PyHhnon Nbra vies + ‘Avanthi Institute of Engineering & Technology Gunthapally (V), Abdullapurmet (M) Near Ramo! Fimoty, [Link]., Hyderetad proce SS > S440 Command line sv iMSlall a new Itbyaxy that you tyP2 the -fotowing os ‘y He Bersih command C:\SPHthon—m pip inslall enlame Replace name pee Ey ey) which ingial. '. ingsal na ©\ pusnon mn opip install HY [Link]\l pandas - = ndas c:\> python -m Pip ‘he Mmstal 3. Tngiall Scfiert - leosin e:\> python —ro pip ansiall Seiki —leasn , Tngtait motplotlilo c:\> python om Pip insiall mot plod egera SC ¢:\> Python —™ pip Ynstal) seipy iin) Seakon ci\= python pip insall Sealovrn ‘Avanthi Institute of Engineering & Technology Gunthapally (Vj, Abdullapurmet (Mt) Near Ramoli Filmy, [Link], Hyderabad quinoa» 668% Soto 03. ot Gj roriying “the convolution Neusal network on vision proiolems Solution: Sep-1 Import the neccesasy Nabrasies import mumnfoy ag np import esas trom e108. datasets import mnhist Prom xesia8 « mmocelgtenport rroctel. * Hepa: Creole the toain data ana est ote ist. load - Cx brain, Ytrain), Cx test Y- eg) = a's datat > Step-3 : checking data format ng ~ Tous iva) —colg= 23,88 — 4K image - cata ema! Ge eechanrels— first xeaoiin ex —-brotn reshape Cxtra%n. shape C01,1, 'mg vows, img cols) : x tege =X-test. veshape Cx test Shape COI 1, Gere nag col) input = oa 70095, emp _col, i) else. Yetrain= - X ABE fnput = ‘Avanthi Institute of Engineering & Technology Gunthapally(V) Abdulapurmet(M) Near Remoj Fimely, [Link], Hyderabad ‘Float 3a’) Leste = X-*BL. agtuny ¢ ain = x- ain. astupe ( "Float aa’) een |= ane Legd = 65 tain = Kexo$. utils. to — categurical Cy-tr0%n ) a y. ¢ on d 4eje = KeNAZ. US. -L0 ~ categorical (y-test) d- d j inp x = input Cshape =tnpx) foyer! = convaD (sa, kexnel Side =(39), achvertion - 5) Gnpx) aay Chonan ™ layess & = convad (6%, (3.3), achuation = "10 peeetey loye73 = moxpooling a0 C pool —siae = (23) Clayen a) Noyes ¢ = Dvopout Coe) Clotes) 3) joyes 5 = Hatéen() Closes: layes 6 = Dense Camo achvation =' si oD) Cay 6) oye 7 = Dense Cio achuetion - "s04trrox') Clays 6) Step -4 : cag compile and f4 Purckon | ede} — mode) =rmode) (Linput x), lays 4) J des. compile CopHinides = Keres, ophmi aed. Adacoitenc) fo: = i SS = KeHa8. logges, Ca Aeqorical —Cr0sen —y, ‘Avanthi Institute of Engineering & Technology Gunthapally (V), Atdullapurmet (M) Near Ramoii Filmeity, [Link], Hyderesten metyvics Laccusia Poceusiacy ) procel «fi Cain yetrain, epochs=!a, latch - Size function : Glep-® + Evaluate vesilo' Geox =model. evaluate Cx teste y-test- Pint C'v0ss =', score £6) Print Caceusacy =! scove fii) ) thi Institute of Engineering & Technology 1 (0), Asidlapurmet(M) Nr Ramo Fmt, RRO, Hyder page clossifrcation on MNIST dataset Conn model ery Pull connected ayes) wrth d q solution : sep Tmport the necessany librowies port Mumpy ag np tmport tensovtlow 3 : tmnpor $ Jyom tensor flow. Kesas 12, motels, eaaaes Wnport loyes SeP-B : Wad she Pre procegg the MNIST Cataget Coin. troges train labels), Cert images, 434 labels) = dotosets, mnist. Wad —datat) -tyain- tages , ees — i one images (awh.o E3t— fmnages | ant. ain. images = np. expand — dims(train- images, oxig=-1) test images =p. expand — dims (test - images, axis =-1) SP-3: Build the cnn mode) model = mdclels. sequential( ) roodel add Cloyes13. convad (sa, (33) acHvation = ‘elu, input - Shape = Cag, ag.) 2}. add Clayess. moxpooling anCCa, a) Medel. ade Cloyens. convai) (64.(33), actvertion ='7e1u’)) rset. ada Cloyers. Hattent }) ‘Avanthi Institute of Engineering & Technology Gunthapally (Vj, Abdullapurmet (M) Near Ramoli Fimcity, [Link]., Hyderabad ave 9 model: cla Clayess. Nense (oy, ackvedion mode! aca ( foyens. Dense Civ, ackvaton Limax’) §4ep-4 s compile -the mode} model. compile Cophmigesr= ‘adam! 1055 =! Spas Crosseneropy), metrics = [ ‘aceusracy’) ) sep-# “ain —the mode} model. f+ Cerin images, Aroiin- labels, epochs =m, batch Side = 64, valiclation— split = 0-1) SHep-6 : Ewluote he mpde) onthe test Set 4054-1085, fe3t Saccwsacy 2model. evaluate Cxest - *MAGS e384 _ label) print (“Test aegha aon. ert — aceusiaey ) Sep-4 : mare predictipn3 On new eee prediction’ = model. predict (-tege— images fira]_) Predicted — labels —[Link] (preclickons, oxis =i) Prin C* pyedlicled tabel4:" predicted - lavels) Print C “TwWe foloel4." tegt_labels [:m)) int (* predicted labelg:* predicted —labels’) Pink CrTvUe labels:” test images [:n')) ‘Avanthi Institute of Engineering & Technology Ginthapaly(¥),Abilanmot (a) Near Ramo) Fimdty, RRLDist, Hyderabad pegcrip tion = rma clogsiticaton mist clatoset onthe box Staorting point nleusal example and a great how to butld a convolutonal a classic undies Stancting network CenN) with a fatty connected tay ecog nrbon ‘Avanthi Institute of Engineering & Technology ‘Gunthapally (V), Abdullapurmet (M) Near Ramoji Filmeity, RLR Dist, Hyderabad pane: 66a 0% Expt Ne G) -aerlying ee eep ee ral nine eee of NUp ¢ ae oe include Degcviphon § deep leosining models see | t Recwirent Neusial Networks Cenns) . RNNS ae clesigned to handle sequent) where axé data, mang them wey guided for Ntp to3KS she wcler of words matted. P7100e33 input dot hidden Sats Step-by-step media while men to caplune — context Spl: RNNS RNNS oie ates gree to handle Sequential data, TKD then well - Suitect Por Nip to3kg whee ae the orces of words matte 18 Applications : -branglotion Cea, -qoogke!s transfor mes heZec} mode) ‘Bem’ for Nim) Tee generation (eg, openaz'S ep Eee) > Question Efrsosing Ceq. 4pm¥lely Beer tage model "BERT Joy QA) ‘Avanthi Institute of Engineeri cunt ee, for glep-A> Bidlivechonal ENco« Jey Repregentahongs rransPormen3 CSERD Beer ts a -brans-forvrres -boged langue angua pretrained ona lasige covpug of ee sTeet Completion sent geneiaton Ce gy eveative cori Hing code yenes— > lang uage translation S1ep-3: Convolutional neusja) nletwork3 boy Nup: Athvough move) Commonly used Pox Computers i530 CNNS con be adapted +0 Ntp ta8ks Applications : saeet cla9sificakon > Sentiment analysis SEP: Sequence —-to- Sequence models~ Sequence —to- Sequence models uge encodey _ de coder omchiectwies +0 handle bans forming one Sequence fato anotres;, Such 03 machind ranslehon and Summosigotion -ka3k3 Yet involve ‘Avanthi Institute of Engineering & AUT oracle mene applicakons » smaochine -bhansletoo > Tevet most aalion SHep-8 2 Attention mechorisrs: atiention mechani8m§ adie not mode in improv bat reg have been fast rument modelS performance Of vosiioug Nip ta3K3 and of the allo modelS of —focug ory specific posts © they uindesHand 9 herr cusing pwoees Sing enhancing uncexSianding and pertermance -spgcoiong > language translation > eet GEosiabon Avanthi Institute of Engineering & Technology Gunthapaly(V), Abduilapurmet (tM) Near Ramo Fimoty, RRDIst, Hyderabad TrAIN A Sentiment analygtg model On Imoe 0 ae uge ANN Layeig with Ls™|4aev Notes Solution A Vibvosie8 Step! Impoye the necessary import +ensorvfiny as +f mbd. ¥ from tensorfiow - Kesa3. datagets *mport Step-a: Load and preprocess the M06 dataget nurn - words =1000 Cerin - data, train label3), (4egb— data. +3 mE jabelS) = e bg) feb load data Crum words = nure—107 max -length = 2h0 -hain- data = pad —Sequennces (Cerain_ data, moxlen ae max - length) +egt— data =pad_ sequences (4eit- data, maxlen = max length) Hep-3; Build +he eNN model with LS™ oy Gav aes embedding _ dim=100 model - sequential ¢> ‘Avanthi Institute of Engineering & Technology Gunthapaly(V), Abdulapurmat(M) Near Ramo} Fin, RR Di Hyder output — model. add Cembe: iding Gnput -dim = num word S, ¢ aim, inpuk -length = max—length)) modal. add CqQvCunits =6u, dropout = 0-8, TECUmren ®= yo pout = 0.3) ' gi grnot model. ada (pense (unit$ =i, ackvaron= 9 Slep-u = compile ancl rain he model batch-dSiae =1a8 epochs =% wmode). -# (train. data, Yygin_labelSbatch-Si ge epochS= epochs vali dahon=split a) =b-s Step: Evaluate the mode] on the test Set 4e3t loss te3t— aeeuracy ‘=model. evaluate (test -data, tegt— label 3) Wink (-1e5L [Link]:', te5e aceusacy ) eaciption 0 train a senkment avalysis mode) onthe MDG dataset using RNN ones 8 with Lsm/qao Und, vel} use FeENSflgvd and Keegy. the IMDB dotoset Conai movie yeviewS labeled 03 positive OF hegertive Sertimend ‘Avanthi Institute of Engineering & Technology Gurthapaly(V),Abdulepumet(M) Nr Remo} Flay, RARDist, Hysrabee Applying the nutoencocdes aleorritfoeng fog encocting the qeal-worlad cata Solution : Stepas colect and prepyocess Data preparation data you he veal world Y : a ane data *5 want to encode. engusie that the ae As ee 5 sulable —Brmet and novmalae tt d awe ye He Step-a : Quild +he autoencocles mode! Cea . ines encode? model using a neusial networ WKe tensorfiow and Kees import tenSoyflow a8 tf , from tensor Piovo .kesja8. \oyesis Import Jopude, DENSE. * ‘npul- Shae = < yous, input - Side > fi a ; t_ ctimension > latent dim = modeladd (nense(ainé. inpub- dim= latent - mode}. ada Cleakyret v Calpha=o.0D) mide). add (atch novraligeton Crnomentum 0.8) model. add Coense (m3) model add Cleaxyeery Catpha=0.01)) mode}, adel (nense Cioa4)) wrode). add (Dense Cagxa grt, achvaton tanh!) model. ace (ReSpenseshape (Casas) euHN mode) dim) ‘Avanthi Institute of Engineering & Technology Gunithapally (Vj, Abdullapurmet (NM) Near Ramo} Fimely, [Link], Hyderabad deh utia — digeviminatoy Geng shaped mode | = Sequensal C y ie wondelvaclel Coden Cinput shape = fing shape)? mode), add (pense (ma) vnedels add Creakyeerv Calpha = 0:00) wuecelell Gena (ane) model ach) Crense C1, ackveton="5 yetsin mode} Bay moid')) Step-3: cefine the -cAn mode} by combinivy) the Generator] and discriminator def build _gan Coenesiator. di seriminatoa)* disoiminetes trainable = False rode] =Sequentall ) mode! x. add Cgenesiator) model: add (discriminate) fetun rvcie! Sep-y : ayain the -GAN mode) # Detne hypesipediometen3 latent dim=100 pa Shape = CAs, 28,1) gendtortor = build - generator Coden _ dim) Asia = duilde disevimimatey Cimg- shape) Avanthi Institute of Engineering & Technology Feary (V) Abdulapurmet (M) Neat Ramo Ficty, RRLDIt, Hyderabad 4Taiwing loop 0 epochs = ior batch- Sige = 6y half - botch = batch-siae Ia fey epoch in yange Cepochs): Tan he cdisoiminatoy tak [Link].-vandlint COx_-[Link] £6] balk betel “Veal inages = gen x bain Lid] ulSe = npesonclorn. netenaiNCUNMeRapp. batch, latent — aid) genwiated - *mages = pensar: predict Cnoise) 1085-70) = digeyiminarter. tevain —on- batchCrea|- images np. ones(ChalP batch, 1) d_toss- fake = discriminatiy. Erain—on-botch Cgensiated z images, npr ze08 Chal? baich.'))) d_losg= 0: * Mp. add (a-tosg_ rea el — loss—faxe) # trdin the generator 1n03S@ =np- Yandom. rormal (01, Chetch_ S1ae. lent dim)) vals ~ labelS =np.0ne3CC batch, $i Ae.1)) 91055 = gan,-tvain- on- batch Choise, valid —\akel 8) ‘Avanthi Institute of Engineering & Technology Gunopaly(V), Abana (h) Noar Remo Fie, RR Ds, Hyderabas ription ° a a pours Newoorks CaAns) ae a Powel Gendietve -Aclves Sia ful ebags of cleep leosning ynvciel 08K, Incluctng image genesrtion me aged for vosiiou$ ised AS and unsupe leosinin)) Institute of Engineering & Technology Gunthapally (V), Abdullapurmet (M) Near Ramo Filmely, [Link]., Hyderabad

You might also like