HW 5 2022-Python代写
时间:2022-11-22
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 3/14
SWbmiUUion for HW 5 iU noV [eV aXailable. When iVÁU read[, [oW UhoWld folloY Vhe HW
UWbmiUUion inUVrWcVionU gWide Vo UWbmiV [oWr aUUignmenV.
GFOFSBM OPUFT:
Ԏ. YoW can alYa[U aUUWme VhaV [oWr code Yill be called YiVh argWmenVU of Vhe
correcV V[pe b[ Vhe VeUVU.
Ԁ. There shoWld be no print statements an[Yhere in the solWtions that [oW
sWbmit. EXer[ fWncVion UhoWld alYa[U reVWrn (or [ield) a XalWe Yhen called.
ԃ. If [oW donÁV WnderUVand YhaV a qWeUVion iU aUking [oW Vo do, Vake a look aV Vhe
VeUVU Vo Uee if VhaV clearU iV Wp.
ԅ. Each UVep of VhiU aUUignmenV bWildU on Vhe preXioWU. YoW can and UhoWld make
WUe of [oWr fWncVionU in oVher fWncVionU.
0. OWFSWJFX PG UIF QFSDFQUSPO: TIF
TJNQMFTU OFVSBM OFUXPSL
BBTJDT
In conVraUV Vo Vhe preXioWU homeYork aUUignmenVU Yhere [oW Yere VaUked YiVh
implemenVing modelU VhaV made predicVionU direcVl[ baUed on Vhe coWnVU and
aUUociaVed probabiliVieU of feaVWreU in a corpWU, in VhiU aUUignmenV [oW Yill
implemenV a model VhaV approZimaVeU claUUificaVion deciUion boWndarieU Xia
UWperXiUed learning YiVh reinforcemenV.
The baUic idea iU VhiU:
Each label-feaVWre pair in Vhe Vraining daVa iU aUUigned a YeighV b[ Vhe model.a
To claUUif[ an inpWV, Vhe model lookU aV Vhe UWm of feaVWre YeighVU giXen each
poUUible label; Vhe label YiVh Vhe maZimal UWm iU Vhe predicVion.a
DWring Vraining, Vhe model predicVU Vhe higheUV Ucoring label for each Vraining
inUVance giXen iVU cWrrenV YeighVU. If Vhe predicVion iU correcV, noVhing happenU
and Vhe Vraining loop conVinWeU Vo Vhe neZV Vraining inUVance. If Vhe predicVion iU
incorrecV, Vhe YeighVU are adjWUVed eiVher Wp (for Vhe feaVWre YeighVU aUUociaVed
YiVh Vhe correcV label) or doYn (for Vhe feaVWre YeighVU aUUociaVed YiVh Vhe
incorrecVl[ predicVed label), changed b[ Vhe amoWnV of Vhe learning raVe.
We keep iVeraVing oXer Vhe enVire Vraining daVaUeV (each Vime Vhe model lookU aV a
Vraining daVa inUVance iU called a step and each iVeraVion oXer Vhe enVire daVaUeV iU
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 4/14
called an epoch) and WpdaVing YeighVU WnVil Ye reach a predefined limiV of
epochU.a
YoW can refer Vo Vhe UlideU for lecVWreU 15 and 16 Vo geV a more deVailed UenUe of hoY
VhiU model YorkU, Yh[ iV YorkU, and YhaV iVU draYbackU are.a
AWFSBHJOH
BecaWUe Vhe Xanilla implemenVaVion of percepVron aimU Vo maZimall[ fiV Vo Vhe
Vraining daVa, iV haU a Vendenc[ Vo oXerfiV Vo Vhe characVeriUVicU of Vhe daVaUeV and
ma[ noV generali\e Yell Vo WnUeen daVa. ThiU iU parVicWlarl[ VrWe Yhen Vhe Vraining
daVaUeV iU Umall.a
In VhiU aUUignmenV [oW Yill implemenV a UlighVl[ more compleZ XerUion of Vhe
percepVron called Vhe aXeraged percepVron, and WUe iV Vo idenVif[ Vhe langWage of a
UnippeV of VeZV. ThiU model folloYU Vhe Uame Vraining proVocol aU Vhe regWlar
percepVron YiVh one imporVanV modificaVion: dWring Vraining Ye keep a rWnning UWm
of Vhe YeighVU of each feaVWre aV each Vraining UVep. AV Vhe end of Vraining Ye Vhen
diXide each of VhoUe UWmU b[ Vhe VoVal nWmber of UVepU Vo geV an aXerage feaVWre
YeighV VhroWghoWV Vhe enVire Vraining loop.a
AddiVionall[, [oW Yill implemenV a modified XerUion of Vhe ScoringMeVricU claUU from
HW4 VhaV compWVeU performance meVricU releXanV Vo mWlViclaUU claUUificaVion
problemU. Namel[, [oW Yill implemenV Vhe Macro-F1 Ucore and per-label confWUion
raVeU Vo beVVer WnderUVand Yhere and Yh[ [oWr model iU miUclaUUif[ing.a
DBUB
The daVaUeV for VhiU aUUignmenV comeU from neYU arVicleU acroUU 17 langWageU,
UaXed aU a line UeparaVed and Vab delimiVed VUX file. Each roY conVainU Vhe firUV 25
characVerU of a paragraph from a neYU arVicle aU Yell aU Vhe ISO 639-2 code for Vhe
langWage of Vhe UenVence. a

Like in HW3, [oW Yill WUe inUVanceU of Vhe claUU Vo
repreUenV each roY in Vhe daVaUeV dWring Vraining and eXalWaVing. ThiU claUU conVainU
fieldU for Vhe label of Vhe inUVance (in VhiU caUe VhaV Yill be Vhe inUVanceÁU langWage
code) and Vhe feaVWreU, repreUenVed aU a Xariable-lengVh VWple of UVringU. AlVhoWgh
Ye can eZVracV VheUe feaVWreU from Vhe raY VeZV in man[ poUUible Ya[U, an effecViXe
Ya[ iU Vo UpliV Vhe VeZV inVo characVer-leXel ngramU.a
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 5/14
WiVh a correcV implemenVaVion, [oW UhoWld find VhaV [oWr model performU qWiVe Yell
in idenVif[ing Vhe langWage of [oWr inpWV VeZV.
1. CIBSBJHSBNFFBUVSFEYUSBDUPS BOE
IOTUBODFCPVOUFS
Before Ye geV inVo Vhe ke[ parVU of Vhe aUUignmenV, Vhere are VYo claUUeU VhaV [oW
need Vo define VhaV Yill be WUed laVer on. TheUe are concepVWall[ qWiVe Uimilar Vo Vhe
and claUUeU encoWnVered in
HW3 bWV modified Vo fiV in VhiU homeYork.a
EYUSBDUJOH GFBUVSFT
BecaWUe Ye are claUUif[ing oXer man[ poUUible langWageU, each YiVh Vheir oYn
WniqWe XocabWlar[, iV iU impracVical Vo Vrain a model YiVh UWfficienVl[ large Vraining
daVa Vo capVWre Vhe leZicon of each langWage. ThiU meanU VhaV if Ye York YiVh Voken-
leXel feaVWreU (YheVher WnigramU or ngramU), Ye Yill encoWnVer a large nWmber of
feaVWreU in Vhe deX and VeUV daVaUeVU VhaV Yere noV preUenV in Vhe Vraining daVa and
VhWU are WninformaViXe. To remed[ VhiU and aXoid dealing YiVh Vokeni\aVion aV all, Ye
can UignificanVl[ redWce oWr feaVWre UeV Ui\e b[ inUVead looking aV characVer-leXel
feaVWreU. For eZample, Vhe UVring , Yhen conXerVed Vo characVer ngramU
of lengVh 2, YoWld be repreUenVed aU
. AlVhoWgh differenV langWage familieU do WUe differenV UcripVU, Vhe VoVal
nWmber of, Ua[, characVer-leXel bigramU iU far loYer Vhan Vhe VoVal nWmber of Voken-
leXel bigramU.a
When loading Vhe langWage idenVificaVion (LID) daVa, [oW Yill Vherefore need Vo
feaVWri\e Vhe VeZV inVo characVer-leXel bigramU. ThiU UhoWld be performed WUing Vhe
proXided claUU, Yhich haU onl[ one meVhod:
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 6/14
GiXen a , reVWrn a aU
folloYU:
Ԏ. The aVVribWVe iU Vhe aVVribWVe of Vhe

Ԁ. The aaVVribWVe conVainU Vhe WniqWe characVer bigramU generaVed from
Vhe field of Vhe . The order of Vhe
feaVWreU doeU noV maVVer, and [oW UhoWld noV pad Vhe beginning or end of Vhe
UVring Yhen generaVing bigramU. NoVe VhaV Yhen creaVing a
, [oW can proXide an[ iVerable of UVringU for Vhe
feaVWreU: a generaVor, a liUV, a UeV, eVc. IV Yill be conXerVed inVo a VWple
aWVomaVicall[.
YoW can aUUWme VhaV Vhe XalWe of Vhe aVVribWVe of Vhe
[oW are proXided iU a UVring of lengVh VYo or greaVer.
CoWnting instances
For deVerminiUVic behaXior, Ye YanV Vo haXe a canonical liUV of all Vhe labelU in Vhe
Vraining daVa. YoW Yill implemenV a Xer[ Uimple claUU VhaV proXideU
VhiU. The claUU haU VYo meVhodU VhaV [oW need Vo implemenV:

UUe VhiU meVhod Vo iVeraVe oXer Vhe daVaUeV and popWlaVe [oWr
daVa UVrWcVWreU aU needed.

ReVWrn a liUV of Vhe WniqWe labelU in Vhe daVa in Vhe UorVed order proXided b[
Vhe helper fWncVion Ye proXide, Yhich reqWireU a
oXer all of Vhe labelU. YoW need Vo creaVe VhiU liUV and UVore iV aV Vhe
end of ; [oWr ameVhod UhoWld noV call
, bWV raVher jWUV reVWrn a liUV UVored in .
2. PFSDFQUSPO USBJOJOH
There are VYo componenVU of VhiU UVep: compleVing Vhe proXided meVhodU in Vhe
model claUU, and YriVing Vhe Vraining loop VhaV iU locaVed in a UVandalone
fWncVion oWVUide of Vhe model claUU. DonÁV implemenV aXeraging aV firUV. Make UWre
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 7/14
[oWÁre paUUing Vhe VeUVU VhaV jWUV eXalWaVe [oWr YeighV WpdaVeU, and Vhen add
aXeraging in Vo [oWr eZiUVing codebaUe.a
TIF DMBTT

)
, bWV [oW UhoWldnÁV be paUUing an[
addiVional parameVerU Vo Vhe model.a
Taking a look aV Vhe meVhod of Vhe PercepVron claUU, Ye can Uee VhaV
VhereÁU onl[ one argWmenV being paUUed Yhen inUVanViaVing: a liUV of Vhe labelU
[oWr model Yill be claUUif[ing oXer (proXided b[ . AU [oW York
on compleVing Vhe proXided meVhodU, [oW ma[ YanV Vo add more inUVance
XariableU or daVa UVrWcVWreU Vo
There are foWr meVhodU Vo York on in Vhe claUU:
a
YoW need Vo UeV Wp Vhe folloYing daVa UVrWcVWreU here. DO NOT RENAME
THEM. The VeUVU look for VheUe Upecific nameU. For Vhe dicVionar[ daVa
UVrWcVWreU, WUe Vhe proXided labelU aU Vhe oWVer ke[U and creaVe each of Vhe
defaWlV dicVionarieU in .a
: The labelU proXided Vo
: The YeighVU for
each label (oWVer ke[) and feaVWre (inner ke[). Note that the oWter dictionar[
mWst be a dictionar[, not a defaWlt dictionar[.
: The UWmU needed b[
aXeraging (Uee Vhe neZV UecVion), YiVh Vhe Uame ke[ UVrWcVWre aU YeighVU. Note
that the oWter dictionar[ mWst be a dictionar[, not a defaWlt dictionar[.
: The ÃlaUV
WpdaVedÄ XalWe needed b[ aXeraging (Uee Vhe neZV UecVion), YiVh Vhe Uame ke[
UVrWcVWre aU YeighVU. Note that the oWter dictionar[ mWst be a dictionar[, not
a defaWlt dictionar[.

GiXen an of feaVWreU (e.g. Vhe VWple of feaVWreU VhaV iU UVored in each
), reVWrn Vhe label YiVh Vhe higheUV UWm of feaVWre
YeighVU. YoWÁll YanV Vo call Vo geV Vhe maZimWm inUVead of
compWVing iV [oWrUelf. YoWÁll need Vo bWild Vhe appropriaVe inpWV daVa UVrWcVWre
for .
The meVhod:
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 8/14
ThiU meVhod Yill be called for each UVep in [oWr Vraining loop. GiXen a
and Vhe Vime in Vhe Vraining loop VhaV [oW are
cWrrenVl[ aV (onl[ needed for aXeraging), WpdaVe [oWr modelÁU YeighVU. Refer
back Vo SecVion 0 if [oW need Vo refreUh [oWr memor[ on hoY Vo WpdaVe [oWr
YeighVU. YoW Yill almoUV cerVainl[ alUo find VhiU code UnippeV from claUU
helpfWl for [oWr implemenVaVion.a
The learning rate (abbreXiaVed in Vhe meVhod declaraVion) iU Vhe amoWnV
[oW UhifV [oWr YeighVU each Vime learn iU called. ThiU Yill V[picall[ haXe Vhe
XalWe of 1.0.a

ThiU iU eUUenViall[ a baVched XerUion of claUUif[, Yhere inUVead of geVVing a
Uingle iVerable of feaVWreU, a UeqWence of iU
proXided and [oWÁll YanV Vo claUUif[ each inUVance in Vhe UeqWence. ThiU Yill
be helpfWl for Ucoring on Vhe deX and VeUV daVaUeVU.a
WeÁll Valk more aboWV
implemenVing VhiU in Vhe neZV UecVion. IV aXerageU Vhe YeighVU aV Vhe end of
Vraining.
The and meVhodU are Vhe onl[ meVhodU VhaV UhoWld modif[ Vhe
YeighVU. Onl[ UhoWld modif[ Vhe UWmU, and laUV_WpdaVed daVa UVrWcVWreU. (YoW
do noV need Vo modif[ VhoUe UVrWcVWreU Yhen iU called; iVÁU aUUWmed iV Yill
neXer be called again and VhaV no fWrVher callU Vo Yill be made.)
Like in HW 4, deVerminiUVic behaXior iU imporVanV. To ensWre determinism, at eXer[
point Yhere [oW need to iterate oXer the labels, aWse the order of .
ThiU iU moUV imporVanV Yhen creaVing Vhe dicVionar[ VhaV [oW Yill paUU Vo
in .
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 9/14
YoW do noV need Vo handle an[ edge caUeU in implemenVing VhiU model. If [oW haXe
an[ qWeUVionU aboWV edge caUeU, email Vhe help addreUU Vo aUk, bWV Ye Yill moUV
likel[ Vell [oW noV Vo Yorr[ aboWV iV. HoYeXer, noVe VhaV [oWr implemenVaVionU of
and UhoWld York YheVher or noV haU eXer been called, and
[oWr meVhod UhoWld be called from Vo geV Vhe predicVed label for
each eZample. The meVhod Yill onl[ be called once, and onl[ afVer
haU been called aV leaUV once. AfVer iU called, Yill neXer be called
again, bWV and Yill be.
TSBJOJOH ZPVS NPEFM
YoW Yill probabl[ YanV Vo implemenV [oWr meVhodU in Vhe folloYing order: once [oW
haXe and implemenVed, [oW haXe all [oW need Vo UVarV York on Vhe
fWncVion.a
ThiU fWncVion doeU Vhe folloYing:
IniViali\e Vo 1
IVeraVeU oXer Vhe daVa VimeU
In each epoch, Vhe folloYing iU done for each inUVance:
The modelÁU meVhod iU called on Vhe inUVance.
IncremenV Vhe b[ one. (The ordering of VhiU iU imporVanV Uo VhaV
aXeraging YorkU correcVl[.)
AV Vhe end of Vhe epoch, Vhe daVa iU UhWffled WUing .
HereÁU YhaV Vhe parameVerU mean:
: An inUVance of [oWr claUU
: A liUV of inUVanceU. ThiU iU Vhe Vraining daVa
for Vhe model. If [oW YanV Vo load daVa [oWrUelf for VeUVing, iV be loaded from
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 10/14
b[ calling , Yhich reVWrnU a
of objecVU, and WUe VhoUe
objecVU Vo popWlaVe a liUV YiVh objecVU WUing [oWr
feaVWre eZVracVor. NoVe VhaV must alYa[U be a liUV Vo UWpporV Vhe random
UhWffling VhaV happenU; VhiU iU differenV from all preXioWU aUUignmenVU Yhere
Ye WUed iVerableU inUVead of proXiding liUVU of daVa.
: The nWmber of VimeU Vo fWll[ loop oXer Vhe Vraining daVa.
: The learning raVe.
: WheVher [oW YanV Vo perform aXeraging aV Vhe end of Vraining. While
debWgging [oWr UolWVion, [oW UhoWld UeV aXerage Vo WnVil [oWÁre UWre
[oWr YeighVU are WpdaVing correcVl[. NoVe VhaV Uince iU afVer a in
Vhe argWmenVU liUV, iV mWUV be Upecified WUing ke[YordU, i.e.
Yhen calling Vhe fWncVion (Uee Vhe VeUVU for eZampleU). ThiU iU a good pracVice
for boolean argWmenVU becaWUe iV can eaU[ Vo miZ Vhem Wp, eUpeciall[ Yhen
Vhere are mWlViple boolean argWmenVU.
ThiU iU a Xer[ Uimple meVhod; Vhe porVion [oW need Vo implemenV iU 8 lineU of code in
Vhe UolWVion. ThiU fWncVion loopU oXer Vhe epochU (UhWffling aV Vhe end of each
one), loopU oXer Vhe daVa (calling on each daVa poinV and Vhen incremenVing
), and Vhen finall[ afVer all epochU are compleVe callU on Vhe model if
reqWeUVed. The code for VhiU fWncVion doeU noV do an[ modificaVion of Vhe YeighVU or
call iVUelf; VhaVÁU all in Vhe fWncVion; Uimilarl[, all Vhe aXeraging iU
performed in Vhe fWncVion.
IT NZ DPEF TMPX?
The VeUVU Yill Vake a Yhile. HereÁU Vhe approZimaVe Viming of
Vhe UolWVion.
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 11/14
The Vime limiVU are generoWU, bWV a good implemenVaVion Yill probabl[ rWn in leUU
Vhan half Vhe Vime limiV WnleUU [oWr compWVer iU Xer[ UloY.
3. 8FJHIU BWFSBHJOH
WiVh [oWr percepVron model and aUUociaVed Vraining fWncVion implemenVed, iVÁU Vime
Vo add aXeraging. ThiU iU Yhere VhingU geV harder. YoW ma[ find iV helpfWl Vo YriVe oWV
Vhe Vraining loop b[ hand YiVh a Umall dWmm[ daVaUeV.
The goal of aXeraging iU Vo compWVe Vhe aXerage XalWe of a YeighV oXer Vhe enVire
coWrUe of Vraining, acroUU eXer[ UVep. For eZample, if Ye Vrain on 5 daVa poinVU for 4
epochU, Ye YanV Vhe aXerage of Vhe YeighVU acroUU 1 + 5 * 4 = 21 Vime poinVU. The
eZVra 1 iU dWe Vo an addiVional Vime poinV aV Vhe beginning Yhen all YeighVU are \ero.
ThaV iU, for a Uingle UVep aV Vhe UVarV, all YeighVU are \ero, and Vhen for Vhe remaining
20 UVepU Vhe[ are UeV b[ Vhe percepVron WpdaVe rWle.
We coWld jWUV UVore a cop[ of Vhe YeighVU afVer eXer[ UVep and Vhen aXerage acroUU
Vhem, bWV VhiU YoWld be eZVremel[ inefficienV. A UlighVl[ more efficienV Vhing Vo do
YoWld be Vo keep Vhe UWm of Vhe XalWeU of each YeighV acroUU all Vime UVepU, and
Vhen diXide iV b[ Vhe VoVal nWmber of UVepU aV Vhe end. BWV if Ye add Vo VhaV UWm for
all Vhe YeighVU aV each UVep, oWr code Yill UVill be Xer[ UloY.
So inUVead, Ye opVimi\e Vhe implemenVaVion b[ onl[ adding Vo Vhe UWm eXer[ Vime a
YeighV changeU. To implemenV VhiU, Vhere are VYo ke[ daVa UVrWcVWreU VhaV [oWÁll
need Vo manage in Vhe claUU:
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 12/14
VrackU Vhe laUV Vime a YeighV YaU changed. For eZample, if
iU called YiVh a XalWe of 7 for and Vhe predicVion iU incorrecV, all
YeighVU VhaV change Yill haXe Vheir XalWe in UeV Vo 7. Since
iU a defaWlV dicVionar[ YiVh a defaWlV XalWe of \ero, if a YeighV haU
noV eXer been UeV, iVU XalWe in Yill be \ero.
VrackU Vhe UWmU of each YeighVU acroUU all Vime UVepU. IV iU la\il[
WpdaVed; VhaV iU, Ye onl[ change iV Yhen a YeighV iU WpdaVed. For eZample, if
iU called YiVh a XalWe of 7 for and Vhe predicVion iU incorrecV, Ye Yill
WpdaVe Vhe YeighVU for Vhe feaVWreU preUenV in VhaV inUVance. LeVÁU Ua[ Ye
increaUe Vhe YeighV for Ãhoora[Ä for Vhe label ÃpoUiViXeÄ from 1.0 Vo 2.0 aV UVep 7,
and iV YaU laUV WpdaVed aV UVep 3. IVÁU been 7-3=4 UVepU VhaV Vhe YeighV haU had
Vhe XalWe 2.0, Uo Ye add 4*2.0=8.0 Vo for Ãhoora[Ä YiVh Vhe label ÃpoUiViXeÄ.
We UeV Vo 7 for Ãhoora[Ä YiVh Vhe label ÃpoUiViXeÄ. Then Ye change
Vhe YeighV Vo 3.0.
Take a look aV Vhe VeUV for an eZample of YhaV Vhe
aXeraged YeighVU UhoWld look like. HereÁU hoY VhingU go aV each UVep ([oW ma[ haXe
Vo read VhiU a feY VimeU for iV Vo be clear):
All YeighVU UVarV aV XalWe \ero aV UVep \ero. The firUV label in Vhe liUV of labelU iU
ÃnegaViXeÄ, Uo Vhe firUV predicVion Yill be ÃnegaViXeÄ Yhen iU called.
iU called for one epoch YiVh YiVh a learning raVe of 1.0
iU iniViali\ed Vo 1
The inUVanceU are looped oXer:
iU called YiVh a UVep XalWe of 1. The label iU ÃpoUiViXeÄ and Vhe onl[
feaVWre iU Ãhoora[Ä. aSince Vhe predicVion iU ÃnegaViXeÄ, aVhe YeighVU for
Ãhoora[Ä for Vhe ÃpoUiViXeÄ and ÃnegaViXeÄ labelU Yill need Vo be changed b[
Vhe learning raVe.
Before Ye change Vhe YeighV, iU WpdaVed Vo add Vhe YeighV
Uince Vhe laUV WpdaVe Vo Vhe VoVal. So Vhe UWmU for ÃpoUiViXeÄ/Ähoora[Ä
and ÃnegaViXeÄ/Ähoora[Ä geV (UVepU Uince laUV WpdaVe * Vhe cWrrenV
YeighV) added Vo Vhem. The UVepU Uince laUV WpdaVe iU 1 (iVÁU UVep 1, and
all YeighVU Yere UeV Vo \ero aV UVep 0), bWV Vhe YeighV iU 0, Uo noVhing iU
added Vo Vhe UWmU.
We change afor ÃpoUiViXeÄ/Ähoora[Ä and
ÃnegaViXeÄ/Ähoora[Ä b[ Vhe learning raVe.
We noVe VhaV VhoUe YeighVU Yere laUV WpdaVed VhiU UVep (1).
11/21/22, 9:58 PM COSI 114a HW 5 2022 ² DURSbR[ PaSHU
KWWSV://SaSHU.GURSbR[.FRP/GRF/COSI-114a-HW-5-2022-VXAJH\GHELF4SHSMK3YCV 13/14
iU called YiVh UVep 2. Once again, Vhe label iU ÃpoUiViXeÄ and Vhe onl[
feaVWre iU Ãhoora[Ä (Vhe VYo pieceU of daVa are idenVical. aSince Vhe
predicVion iU ÃpoUiViXeÄ, no YeighV WpdaVe iU needed, and noVhing needU Vo
be done aV all.
NoY VhaV all daVa poinVU haXe been proceUUed, Ye need Vo WpdaVe Vhe UWmU all
Vhe Ya[ Vo Vhe end of Vraining. callU Vhe meVhod
on Vhe model YiVh Vhe final XalWe of (3). haU Vhe XalWe 3 aV VhiU
poinV, aU iV UVarVU aV 1 and iU incremenVed afVer each daVa poinV. ThiU iU correcV
becaWUe Vhere are Vhree Vime UVepU VoVal; Vhe YeighV iniViali\aVion and Vhe VYo
daVa poinVU VhaV Yere proceUUed.
JWUV like Yhen Ye WpdaVe YeighVU, Ye add (cWrrenV_UVep - laUV_WpdaVed) *
YeighV Vo Vhe UWm for each YeighV. ThiU reflecVU Vhe facV VhaV Uince Vhe laUV
WpdaVe, each YeighV haU held iVU XalWe conUVanV WnVil Vhe end of Vraining.
Finall[, Ye diXide Vhe UWm for each YeighV b[ and UeV Vhe YeighV Vo
VhaV XalWe. For eZample, if Vhe UWm iU 24 and nWmber of UVepU iU 8, Vhe final
YeighV Yill be 3.
LaUVl[, [oWÁll need Vo implemenV Vhe remaining meVhod in Vhe claUU,
. This shoWld onl[ be called once b[
[oWr training fWnction at the termination of [oWr training loop. The XalWe
VhaV [oW paUU Vo iV iU Uimpl[ Vhe VoVal nWmber of UVepU in Vhe Vraining
loop. IV iU aV VhiU poinV VhaV [oW Yill YanV Vo compWVe Vhe aXerage of each YeighV b[
diXiding Vhe UWmU of eXer[ Vracked YeighV b[ , and aUUigning VhiU neY
XalWe aU Vhe YeighV in [oWr modelÁU YeighVU daVa UVrWcVWre.a
If [oW haXenÁV alread[, donÁV forgeV Vo alUo modif[ [oWr fWncVion Uo VhaV
iU called Yhen Vhe aXerage boolean in Vhe call Vo Vrain iU Öa
OCMJHBUPSZ CMPTJOH MFNF
essay、essay代写