Calculate the sum vector of multiple words.
Arguments
- data
A
wordvec
(data.table) orembed
(matrix), seedata_wordvec_load
.- x
Can be:
NULL
: use the sum of all word vectors indata
a single word:
"China"
a list of words:
c("king", "queen")
cc(" king , queen ; man | woman")
an R formula (
~ xxx
) specifying words that positively and negatively contribute to the similarity (for word analogy):~ boy - he + she
~ king - man + woman
~ Beijing - China + Japan
- verbose
Print information to the console? Defaults to
TRUE
.
Download
Download pre-trained word vectors data (.RData
):
https://psychbruce.github.io/WordVector_RData.pdf
Examples
sum_wordvec(normalize(demodata), ~ king - man + woman)
#> dim1 dim2 dim3 dim4 dim5
#> -0.0055029992 -0.0670502053 -0.0451917763 0.0387523404 -0.0028627068
#> dim6 dim7 dim8 dim9 dim10
#> -0.0311541918 0.0722744639 -0.0547962213 -0.0020958381 0.1267937027
#> dim11 dim12 dim13 dim14 dim15
#> -0.1177978229 -0.1116193754 -0.0432157999 0.0087648568 -0.0212594939
#> dim16 dim17 dim18 dim19 dim20
#> -0.0361886454 -0.0145757764 -0.0391255380 0.0236719225 0.0679695260
#> dim21 dim22 dim23 dim24 dim25
#> 0.0825006128 0.0179503178 -0.0102744498 0.0096805959 0.0097418516
#> dim26 dim27 dim28 dim29 dim30
#> -0.0583066547 -0.1043284916 0.0066451406 0.0774529645 -0.0630043398
#> dim31 dim32 dim33 dim34 dim35
#> 0.0176932143 -0.0357660002 -0.0127675640 0.0952755743 -0.1004202304
#> dim36 dim37 dim38 dim39 dim40
#> -0.0307725420 0.0191817489 0.0342936599 -0.0381161430 -0.0036010425
#> dim41 dim42 dim43 dim44 dim45
#> -0.0222736867 -0.0654523468 0.0581761410 0.0386649344 0.0625108822
#> dim46 dim47 dim48 dim49 dim50
#> 0.0144455335 -0.0298451219 0.0179820393 -0.0070950816 0.0410382461
#> dim51 dim52 dim53 dim54 dim55
#> 0.0193902936 0.0009054039 -0.0824461123 0.0896711960 -0.1071550823
#> dim56 dim57 dim58 dim59 dim60
#> 0.0090518215 -0.0452947722 -0.0242425101 0.0499748883 0.0017788248
#> dim61 dim62 dim63 dim64 dim65
#> 0.0896162255 0.0778694536 0.0043599153 0.0777055479 0.0090822422
#> dim66 dim67 dim68 dim69 dim70
#> -0.0272763870 0.0142941177 0.0595841030 -0.0188500428 0.0720441406
#> dim71 dim72 dim73 dim74 dim75
#> 0.0662750676 0.0333189751 -0.0275026411 0.0473774977 0.0302065682
#> dim76 dim77 dim78 dim79 dim80
#> 0.0363555415 -0.0305552844 0.0234168307 0.1017575023 0.0411732703
#> dim81 dim82 dim83 dim84 dim85
#> 0.0094623327 0.0278133126 -0.0067087575 0.0304040180 -0.0629132792
#> dim86 dim87 dim88 dim89 dim90
#> 0.0630248067 -0.0340541402 0.0388550926 0.0546983130 0.0218934638
#> dim91 dim92 dim93 dim94 dim95
#> 0.0433205797 -0.1001378189 -0.0860689768 -0.0450885649 0.0072867091
#> dim96 dim97 dim98 dim99 dim100
#> 0.0317569448 0.0645638429 -0.0160440819 0.0639956819 -0.0188932674
#> dim101 dim102 dim103 dim104 dim105
#> 0.0053826412 -0.0191800667 -0.0261438897 -0.1247332173 -0.1010494892
#> dim106 dim107 dim108 dim109 dim110
#> 0.0587875995 -0.1849463247 -0.0674423763 0.0657176846 -0.0205700926
#> dim111 dim112 dim113 dim114 dim115
#> 0.0666514408 0.0815598320 0.0569012270 -0.0101953971 0.0484093475
#> dim116 dim117 dim118 dim119 dim120
#> -0.1185521372 0.0030313936 -0.0933326263 0.0544090501 0.0927743854
#> dim121 dim122 dim123 dim124 dim125
#> 0.0572259111 0.0394707134 -0.0271925329 -0.0265718034 0.0412028096
#> dim126 dim127 dim128 dim129 dim130
#> 0.0438836936 0.0418592306 0.0034390046 0.0029262269 0.0134619940
#> dim131 dim132 dim133 dim134 dim135
#> 0.0060545735 0.0513732397 0.0327279879 0.1054238844 0.0668562286
#> dim136 dim137 dim138 dim139 dim140
#> 0.0769686804 -0.0227940919 -0.0422079731 0.0703340490 -0.0155774872
#> dim141 dim142 dim143 dim144 dim145
#> 0.0372660027 -0.1356710009 0.0350093190 0.0236513594 0.0484942080
#> dim146 dim147 dim148 dim149 dim150
#> -0.0400414708 0.0188626798 0.0274173715 -0.0486294492 0.0038126260
#> dim151 dim152 dim153 dim154 dim155
#> 0.0133522101 0.0559058596 0.0022117502 -0.0837040985 -0.0849908637
#> dim156 dim157 dim158 dim159 dim160
#> -0.0533659570 -0.0608346184 0.0319297479 0.0282798544 0.0078445029
#> dim161 dim162 dim163 dim164 dim165
#> -0.0496067834 -0.0011413436 0.1585030627 -0.0257539005 -0.0556869160
#> dim166 dim167 dim168 dim169 dim170
#> -0.0376501897 0.0119025195 -0.0722575073 -0.0134277815 0.0713891951
#> dim171 dim172 dim173 dim174 dim175
#> -0.1004959954 0.0377733481 0.1079291741 0.0487607486 0.0176890786
#> dim176 dim177 dim178 dim179 dim180
#> -0.0642323537 0.0939240962 0.0323515907 0.0062917470 0.0628913182
#> dim181 dim182 dim183 dim184 dim185
#> -0.1168540632 0.0042852646 -0.1256198725 -0.0767676420 0.0159300785
#> dim186 dim187 dim188 dim189 dim190
#> 0.0294246554 0.0809427655 0.0357663118 -0.0218166578 0.0638628914
#> dim191 dim192 dim193 dim194 dim195
#> 0.0283086395 -0.0002039863 -0.0330815284 0.0067946163 0.0198031884
#> dim196 dim197 dim198 dim199 dim200
#> 0.0572634491 0.0025753907 -0.0179017809 0.0275942861 -0.0879453025
#> dim201 dim202 dim203 dim204 dim205
#> -0.0565598458 0.0206358787 0.0228473515 -0.0461282294 -0.0145729556
#> dim206 dim207 dim208 dim209 dim210
#> -0.0143933569 0.0095678299 0.0631869552 0.0659021305 0.0042216349
#> dim211 dim212 dim213 dim214 dim215
#> 0.0293649478 0.1033812547 -0.0516775577 -0.1253424596 0.0270994610
#> dim216 dim217 dim218 dim219 dim220
#> 0.0385621533 -0.0036571112 -0.0278117809 0.0295294855 0.0024058853
#> dim221 dim222 dim223 dim224 dim225
#> -0.0144733111 0.0180931805 0.0579378103 -0.0116669835 0.0087559466
#> dim226 dim227 dim228 dim229 dim230
#> -0.0283575865 -0.0278965844 -0.0272467575 0.0342410954 0.0878225024
#> dim231 dim232 dim233 dim234 dim235
#> -0.0741101358 -0.0684089597 -0.1740935244 -0.0044601583 0.0376029740
#> dim236 dim237 dim238 dim239 dim240
#> 0.0221138776 0.0207988624 -0.0113099903 -0.0275133395 -0.0000199454
#> dim241 dim242 dim243 dim244 dim245
#> 0.0563714279 -0.1243700668 0.0584321684 0.0294712221 0.0939427080
#> dim246 dim247 dim248 dim249 dim250
#> -0.0011363452 -0.0734356129 0.0425710531 0.0715560074 -0.0782001568
#> dim251 dim252 dim253 dim254 dim255
#> 0.0274794287 0.0326764105 0.0565690520 -0.0124150119 0.0545865281
#> dim256 dim257 dim258 dim259 dim260
#> 0.0131866584 -0.1333997208 -0.0673208573 -0.0237475804 -0.0439831482
#> dim261 dim262 dim263 dim264 dim265
#> 0.0048958304 0.0900008028 -0.0692655794 0.0177480897 -0.0185615675
#> dim266 dim267 dim268 dim269 dim270
#> -0.0438003657 0.0037071559 0.0152207093 0.0955843067 0.1068395259
#> dim271 dim272 dim273 dim274 dim275
#> 0.0044241142 0.1174178922 -0.0404572738 0.0672502162 -0.0424039690
#> dim276 dim277 dim278 dim279 dim280
#> -0.1056443456 -0.0766069551 0.0035567801 -0.0748190562 0.0503630702
#> dim281 dim282 dim283 dim284 dim285
#> 0.0909204843 -0.0668049051 0.0951348101 -0.0171847044 0.0625944510
#> dim286 dim287 dim288 dim289 dim290
#> -0.0035357800 -0.0205028927 -0.0161002229 -0.0182009416 0.0601725192
#> dim291 dim292 dim293 dim294 dim295
#> -0.0265177060 -0.0849906153 -0.0761131339 -0.1206830347 0.0004351351
#> dim296 dim297 dim298 dim299 dim300
#> 0.0062921084 -0.0137075363 0.0623639418 0.0806824072 0.0592501645
#> attr(,"formula")
#> [1] "king - man + woman"
#> attr(,"x.words")
#> [1] "king" "woman" "man"