seman cs with dense vectors
play

Seman&cs with Dense Vectors Dorota Glowacka - PowerPoint PPT Presentation

Seman&cs with Dense Vectors Dorota Glowacka dorota.glowacka@ed.ac.uk Previous lectures: - how to represent a word as a sparse vector with


  1. Seman&cs ¡with ¡Dense ¡Vectors ¡ Dorota ¡Glowacka ¡ dorota.glowacka@ed.ac.uk ¡

  2. Previous ¡lectures: ¡ ¡-­‑ ¡how ¡to ¡represent ¡a ¡word ¡as ¡a ¡sparse ¡vector ¡ with ¡dimensions ¡corresponding ¡to ¡the ¡words ¡in ¡ the ¡vocabulary ¡ ¡ ¡ ¡-­‑ ¡the ¡values ¡in ¡the ¡vector ¡were ¡a ¡func&on ¡of ¡ the ¡ count ¡ of ¡ the ¡ word ¡ co-­‑occurring ¡ with ¡ each ¡ neighbouring ¡word ¡ ¡ -­‑ ¡ each ¡ word ¡ is ¡ thus ¡ represented ¡ with ¡ a ¡ vector ¡that ¡is ¡ long ¡(with ¡vocabularies ¡of ¡20,000 ¡ to ¡ 50,000) ¡ and ¡ sparse ¡ (with ¡ most ¡ elements ¡ of ¡ the ¡vector ¡for ¡each ¡word ¡equal ¡to ¡zero) ¡ ¡ ¡

  3. Today’s ¡Lecture ¡ • How ¡to ¡represent ¡a ¡word ¡with ¡vectors ¡that ¡are ¡ short ¡(with ¡length ¡of ¡50 ¡– ¡1,000) ¡and ¡ dense ¡(most ¡ values ¡are ¡non-­‑zero) ¡ • Why ¡short ¡vectors? ¡ ¡-­‑ ¡easier ¡to ¡include ¡as ¡features ¡in ¡machine ¡ learning ¡systems ¡ ¡-­‑ ¡because ¡they ¡contain ¡fewer ¡parameters, ¡they ¡ generalize ¡beRer ¡and ¡are ¡less ¡prone ¡to ¡overfiTng ¡ ¡-­‑ ¡sparse ¡vectors ¡are ¡beRer ¡at ¡capturing ¡ synonymy ¡ ¡

  4. Singular ¡Value ¡Decomposi&on ¡(SVD) ¡ • SVD ¡is ¡a ¡method ¡for ¡finding ¡ the ¡most ¡important ¡ dimensions ¡ of ¡a ¡dataset ¡ • It ¡can ¡be ¡applied ¡to ¡any ¡rectangular ¡matrix ¡ • SVD ¡ belongs ¡ to ¡ a ¡ family ¡ of ¡ methods ¡ that ¡ can ¡ approximate ¡ an ¡ N-­‑ dimensional ¡ dataset ¡ using ¡ fewer ¡ dimensions , ¡ such ¡ as ¡ Principle ¡ Component ¡ Analysis ¡(PCA) ¡ or ¡ Factor ¡Analysis ¡ • First ¡applied ¡in ¡ Latent ¡Seman>c ¡Analysis ¡(LSA) ¡ to ¡ tasks ¡ genera&ng ¡ embeddings ¡ from ¡ term-­‑ document ¡matrices ¡

  5. Singular ¡Value ¡Decomposi&on ¡(SVD) ¡ • Dimensionality ¡reduc&on ¡methods ¡first ¡ rotate ¡the ¡ axes ¡ of ¡the ¡original ¡dataset ¡into ¡a ¡ new ¡space . ¡ • The ¡new ¡space ¡is ¡chosen ¡so ¡that ¡the ¡ highest ¡order ¡ dimension ¡ captures ¡ the ¡ most ¡ variance ¡ in ¡ the ¡ original ¡dataset, ¡the ¡next ¡dimension ¡captures ¡the ¡ next ¡most ¡variance, ¡and ¡so ¡on. ¡ • While ¡ some ¡ informa&on ¡ about ¡ the ¡ rela&onship ¡ between ¡the ¡original ¡points ¡is ¡necessarily ¡lost ¡in ¡ the ¡ new ¡ transforma&on, ¡ the ¡ remaining ¡ dimensions ¡preserve ¡as ¡much ¡as ¡possible ¡of ¡the ¡ original ¡seTng. ¡

  6. Latent ¡Seman&c ¡Analysis ¡(LSA) ¡ • LSA ¡is ¡a ¡par&cular ¡applica&on ¡of ¡SVD ¡to ¡a ¡| V | ¡ × ¡c ¡term-­‑ document ¡matrix ¡ X ¡represen&ng ¡| V | ¡words ¡and ¡their ¡ co-­‑occurrence ¡with ¡ c ¡ documents. ¡ • SVD ¡ factorizes ¡ matrix ¡ X ¡ into ¡ the ¡ product ¡ of ¡ three ¡ matrices: ¡ 1. | V | × ¡ m ¡ matrix ¡ W , ¡ where ¡ each ¡ row ¡ w ¡ represents ¡ a ¡ word ¡and ¡each ¡column ¡represents ¡ m ¡dimensions ¡in ¡a ¡ latent ¡space. ¡ ¡ m ¡column ¡vectors ¡are ¡orthogonal ¡to ¡each ¡other ¡and ¡are ¡ ordered ¡by ¡the ¡amount ¡of ¡variance ¡in ¡the ¡original ¡dataset ¡ m ¡= ¡rank ¡of ¡ X ¡ (number ¡of ¡linearly ¡independent ¡rows) ¡ ¡

  7. Latent ¡Seman&c ¡Analysis ¡(LSA) ¡ 2. ¡ Σ ¡is ¡a ¡diagonal ¡ m ¡× ¡m ¡ matrix ¡with ¡ singular ¡values ¡along ¡ the ¡ diagonal, ¡ expressing ¡ the ¡ importance ¡ of ¡ each ¡ dimension. ¡ 3. ¡The ¡ m ¡× ¡c ¡ matrix ¡ C , ¡where ¡each ¡row ¡represents ¡one ¡of ¡ the ¡ latent ¡ dimensions ¡ and ¡ the ¡ m ¡ row ¡ vectors ¡ are ¡ orthogonal ¡to ¡each ¡other. ¡ • By ¡using ¡only ¡the ¡first ¡ k ¡dimensions ¡of ¡ W, ¡Σ ¡ and ¡ C , ¡the ¡ product ¡ of ¡ these ¡ 3 ¡ matrices ¡ becomes ¡ a ¡ least-­‑squares ¡ approxima&on ¡to ¡the ¡original ¡ X . ¡ • Since ¡ the ¡ first ¡ dimensions ¡ encode ¡ the ¡ most ¡ variance, ¡ SVD ¡ models ¡ the ¡ most ¡ important ¡ informa&on ¡ in ¡ the ¡ original ¡ X ¡

  8. ! $ ! $ # & # & ! $ ! $ … 0 0 σ 1 0 # & # & # & # & # & # & … 0 0 # σ 2 & # & 0 # & # & # & # & … 0 X W C = 0 0 σ 3 # & # & # & # & ! # & # & # ! ! ! " & # & # & # & # & # & σ m … 0 0 0 # & # & # & # & " % " % # & # & " % " % m × m m × c V × m V × c

  9. Taking ¡only ¡the ¡top ¡ k ¡≤ ¡m ¡ dimensions ¡a]er ¡SVD ¡is ¡applied ¡to ¡the ¡co-­‑occurrence ¡matrix ¡ X : ¡ ¡ ! $ ! $ # & # & ! $ … 0 0 σ 1 # & 0 # & # & # & # & … 0 0 σ 2 # & 0 # & # & # & ! $ … 0 X W k C = # & 0 0 σ 3 # & # & " % # & ! # & # ! ! ! " & # & k × c # & # & σ k # & … 0 0 0 # & # & " % # & # & " % # & " % k × k V × k V × c

  10. SVD ¡and ¡LSA ¡ • Using ¡only ¡the ¡top ¡ k ¡dimensions ¡leads ¡to ¡a ¡ reduced ¡ W ¡matrix, ¡with ¡one ¡ k -­‑dimensioned ¡ row ¡per ¡word ¡ • This ¡row ¡acts ¡as ¡a ¡ dense ¡ k-­‑ dimensional ¡vector ¡ (embedding) ¡represen&ng ¡that ¡word ¡ • LSA ¡embeddings ¡generally ¡set ¡k ¡= ¡300 ¡ • LSA ¡applies ¡a ¡par&cular ¡weigh&ng ¡for ¡each ¡co-­‑ occurrence ¡cell ¡that ¡mul&plies ¡two ¡weights: ¡ local ¡and ¡ global ¡

  11. LSA ¡term ¡weigh&ng ¡ • The ¡ local ¡ weight ¡of ¡each ¡ term ¡ i ¡in ¡ document ¡ j ¡ is ¡ its ¡log ¡frequency: ¡ ( ) + 1 log f i , j • The ¡ global ¡ weight ¡of ¡term ¡i ¡is ¡a ¡version ¡of ¡its ¡ entropy : ¡ ( ) log p i , j ( ) 1 + ∑ j p i , j log D where ¡ D ¡is ¡the ¡number ¡of ¡documents. ¡

  12. SVD ¡and ¡word-­‑context ¡ • In ¡LSA, ¡SVD ¡is ¡applied ¡to ¡the ¡term-­‑document ¡ matrix. ¡ • An ¡ alterna&ve ¡ is ¡ to ¡ apply ¡ SVD ¡ to ¡ the ¡ word-­‑ word ¡ or ¡ word-­‑context ¡ matrix ¡ – ¡ the ¡ context ¡ dimensions ¡are ¡words ¡(rather ¡than ¡documents ¡ as ¡in ¡LSA) ¡ • Relies ¡on ¡PPMI-­‑weighted ¡word-­‑word ¡matrix ¡ • Only ¡top ¡dimensions ¡are ¡used ¡– ¡ truncated ¡SVD ¡

  13. Skip-­‑gram ¡and ¡CBOW ¡ • Methods ¡ for ¡ genera&ng ¡ dense ¡ embeddings ¡ inspired ¡by ¡neural ¡network ¡models ¡ • Neural ¡ network ¡ language ¡ models ¡ are ¡ given ¡ a ¡ word ¡and ¡predict ¡a ¡context ¡– ¡this ¡process ¡can ¡be ¡ used ¡to ¡learn ¡word ¡embeddings. ¡ • The ¡intui&on ¡is ¡that ¡words ¡with ¡similar ¡meanings ¡ tend ¡to ¡occur ¡near ¡each ¡other ¡in ¡text. ¡ • The ¡process ¡for ¡learning ¡these ¡embeddings ¡has ¡a ¡ strong ¡ rela&onship ¡ with ¡ SVD ¡ factoriza&on ¡ and ¡ dot-­‑product ¡similarity ¡metrics. ¡

  14. Skip-­‑gram ¡Model ¡ • Learns ¡two ¡separate ¡embeddings ¡for ¡each ¡word ¡ w : ¡ word ¡embedding ¡v ¡and ¡ context ¡embedding ¡c . ¡ • Embeddings ¡ encoded ¡ in ¡ two ¡ matrices: ¡ word ¡ matrix ¡W ¡and ¡ context ¡matrix ¡C . ¡ • Each ¡ row ¡ i ¡ of ¡ word ¡ matrix ¡ W ¡ is ¡ 1 ¡ x ¡ d ¡ vector ¡ embedding ¡ v i ¡ for ¡word ¡ i ¡ vocabulary ¡ V . ¡ • Each ¡column ¡ i ¡of ¡the ¡context ¡matrix ¡ C ¡is ¡a ¡ d ¡x ¡1 ¡ vector ¡embedding ¡ c i ¡for ¡word ¡ i ¡in ¡vocabulary ¡ V . ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend