资源描述:
《Another Twitter sentiment analysis with Python — Part 11 (CNN + Word2Vec)》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、TheRickest RickyFollowIamadatascientist.Period.Feb23·14minreadAnotherTwittersentimentanalysiswithPython—Part11(CNN+Word2Vec)Thisisthe11thandthelastpartofmyTwittersentimentanalysisproject.Ithasbeenalongjourney,andthroughmanytrialsanderrorsalongtheway,Ihavelearnedcountlessvaluablelessons.Ihaven’t
2、decidedonmynextproject.ButIwillde nitelymaketimetostartanewproject.Youcan ndthepreviouspostsfromthebelowlinks.•Part1:Datacleaning•Part2:EDA,Datavisualisation•Part3:Zipf’sLaw,Datavisualisation•Part4:Featureextraction(countvectorizer),N-gram,confusionmatrix•Part5:Featureextraction(T dfvectorizer)
3、,machinelearningmodelcomparison,lexicalapproach•Part6:Doc2Vec•Part7:Phrasemodeling+Doc2Vec•Part8:Dimensionalityreduction(Chi2,PCA)•Part9:NeuralNetworkswithT dfvectors•Part10:NeuralNetworkswithDoc2Vec/Word2Vec/GloVe*InadditiontoshortcodeblocksIwillattach,youcan ndthelinkforthewholeJupyterNoteboo
4、kattheendofthispost.PreparationforConvolutionalNeuralNetworkInthelastpost,Ihaveaggregatedthewordvectorsofeachwordinatweet,eithersummationorcalculatingmeantogetonevectorrepresentationofeachtweet.However,inordertofeedtoaCNN,wehavetonotonlyfeedeachwordvectortothemodel,butalsoinasequencewhichmatche
5、stheoriginaltweet.Forexample,let’ssaywehaveasentenceasbelow.“Ilovecats”Andlet’sassumethatwehavea2-dimensionalvectorrepresentationofeachwordasfollows:I:[0.3,0.5]love:[1.2,0.8]cats:[0.4,1.3]Withtheabovesentence,thedimensionofthevectorwehaveforthewholesentenceis3X2(3:numberofwords,2:numberofvector
6、dimension).Butthereisonemorethingweneedtoconsider.Aneuralnetworkmodelwillexpectallthedatatohavethesamedimension,butincaseofdi erentsentences,theywillhavedi erentlengths.Thiscanbehandledwithpadding.Let’ssaywehaveoursecondsentenceasbelow.“Ilovedogstoo”withthebelowvectorrepresentationofeachword:I:
7、[0.3,0.5],love:[1.2,0.8],dogs:[0.8,1.2],too:[0.1,0.1]The rstsentencehad3X2dimensionvectors,butthesecondsentencehas4X2dimensionvector.Ourneuralnetworkwon’taccepttheseasinputs.Bypaddingtheinputs,wedecidethemaximumlengthofwordsinasen