Last active
September 27, 2015 09:48
-
-
Save honnibal/664cf54cb30c48c0c977 to your computer and use it in GitHub Desktop.
Find words that might be colors, using word vectors.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
from __future__ import print_function | |
import plac | |
import spacy.en | |
def main(vectors_loc=None): | |
nlp = spacy.en.English() | |
if vectors_loc is not None: | |
nlp.vocab.load_vectors(vectors_loc) | |
# Quickly list some colors. The .similarity() function will use the average of these word vectors. | |
colors = nlp(u'red blue yellow green turquoise sapphire emerald ruby periwinkle umber oak charcoal ebony') | |
# We want lower-case words, that aren't too rare, sorted by their similarity to the above colors | |
words = [(lex.similarity(colors), lex.orth_) for lex in nlp.vocab | |
if lex.is_lower and lex.prob >= -20] | |
words.sort(reverse=True) | |
for i, (score, word) in enumerate(words): | |
print(i, score, word) | |
if __name__ == '__main__': | |
plac.call(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Glove vectors output:
0 3.87395723519 turquoise
1 3.81783126743 yellow
2 3.74934072972 blue
3 3.74003162334 emerald
4 3.72134917579 pink
5 3.71219105108 purple
6 3.56881126256 amethyst
7 3.53722406442 sapphire
8 3.5338977891 brown
9 3.52508719696 red
10 3.49448519631 orange
11 3.46450432316 green
12 3.44438925954 garnet
13 3.40750136701 white
14 3.37292666661 violet
15 3.3686030001 aquamarine
16 3.34748098681 topaz
17 3.34234120305 ruby
18 3.3152772773 pearl
19 3.31128397829 burgundy
20 3.30942575478 black
21 3.28368459456 teal
22 3.27919208813 colored
23 3.25501919531 lilac
24 3.25401921038 grey
25 3.23096658155 silver
26 3.20777013691 gray
27 3.20412140206 reddish
28 3.19744039485 lavender
29 3.19347469396 amber
30 3.16969517955 pale
31 3.16528756293 hues
32 3.16400163358 opal
33 3.16034278217 fuchsia
34 3.15207669923 crimson
35 3.10774217816 sapphires
36 3.10093595348 beige
37 3.09839059888 peach
38 3.09668615314 onyx
39 3.0884795495 diamond
40 3.0779307923 satin
41 3.06581996239 iridescent
42 3.06472363433 greenish
43 3.05588015613 ivory
44 3.05062629551 hue
45 3.05040804143 color
46 3.04739816044 lime
47 3.03068467525 gemstone
48 3.02693619929 earrings
49 3.01975849647 aqua
50 3.01172475249 accented
51 3.00732955567 mauve
52 3.00233786367 ochre
53 2.99947677053 gold
54 2.99924936167 coloured
55 2.99406047464 faceted
56 2.98044868493 cherry
57 2.96892190548 oak
58 2.95935420273 coral
59 2.94618701376 magenta
60 2.94089170515 dark
61 2.93862445944 scarlet
62 2.92609177819 diamonds
63 2.92347453403 blue-green
64 2.91708857263 smoky
65 2.90485846061 necklace
66 2.90244943938 bluish
67 2.90196624365 olive
68 2.89681381562 jade
69 2.89296990694 shades
70 2.88725264193 pearls
71 2.88418227692 metallic
72 2.87934991203 plum
73 2.87638002505 beads
74 2.8733957592 lapis
75 2.87291067285 gemstones
76 2.87146809926 brownish
77 2.86761277939 silk
78 2.86371857348 quartz
79 2.86228403917 agate
80 2.86015993165 shade
81 2.85814995922 silvery
82 2.85621992528 mahogany
83 2.85284519015 crystal
84 2.84951707975 pinkish
85 2.84726073008 maroon
86 2.84132730527 colour
87 2.83108586479 azure
88 2.82799434488 shimmering
89 2.82199307096 yellowish
90 2.82132680799 purplish
91 2.81279489545 striped
92 2.80817585009 pastel
93 2.80712184342 pinks
94 2.80637486019 floral
95 2.80141970461 golden
96 2.79866670593 colors
97 2.79786259337 pendant
98 2.79665920514 purples
99 2.7902293279 charcoal
100 2.78933602027 pear
101 2.78233775646 translucent
102 2.78007994282 mottled
103 2.77681009425 velvet
104 2.77286006092 cobalt
105 2.7720605249 indigo
106 2.76869398825 bright
107 2.76368590644 oval
108 2.76014749584 walnut
109 2.75927573494 enamel
110 2.75764511125 tourmaline
111 2.75396672291 periwinkle
112 2.74285851648 lemon
113 2.74029274208 matte
114 2.74008222039 creamy
115 2.73949448002 tangerine
116 2.7278674572 beaded
117 2.72597122194 wood
118 2.72262044238 raspberry
119 2.71494198902 ebony
120 2.71351468159 rubies
121 2.7041493532 stone
122 2.70225336045 marble
123 2.70112397192 inlaid
124 2.6936419785 pine
125 2.69153651481 sparkling
126 2.688449127 smokey
127 2.68778297872 leather
128 2.6862100543 flower
129 2.68548111684 hued
130 2.6853321396 leaf
131 2.68287565208 chartreuse
132 2.68189727908 sterling
133 2.67146680043 reds
134 2.66722646249 dyed
135 2.66554317541 carnelian
136 2.65360795343 grayish
137 2.64848367015 crystals
138 2.64651616121 bracelet
139 2.64641917122 rhinestone
140 2.64560823732 yellows
141 2.64024332875 carat
142 2.63958006944 shimmer
143 2.63830071556 shiny
144 2.63315209683 tan
145 2.63265421481 marquise
46 2.62952121812 maple
147 2.62580441077 accents
148 2.62338247804 flecks
149 2.620271784 khaki
150 2.6186058209 glass