Fix small bug in code of mark-adverbs tutorial

This commit is contained in:
Pokey Rule 2016-10-26 15:23:36 +01:00 committed by GitHub
parent 271a120d30
commit 603a3f40c5

View File

@ -78,7 +78,7 @@ p A simple work-around is to average the vectors of several words, and use that
+code. +code.
>>> say_verbs = ['pleaded', 'confessed', 'remonstrated', 'begged', 'bragged', 'confided', 'requested'] >>> say_verbs = ['pleaded', 'confessed', 'remonstrated', 'begged', 'bragged', 'confided', 'requested']
>>> say_vector = sum(nlp.vocab[verb].vector for verb in say_verbs) / len(say_verbs) >>> say_vector = sum(nlp.vocab[verb].vector for verb in say_verbs) / len(say_verbs)
>>> words.sort(key=lambda w: cosine(w.vector * say_vector)) >>> words.sort(key=lambda w: cosine(w.vector, say_vector))
>>> words.reverse() >>> words.reverse()
>>> print('1-20', ', '.join(w.orth_ for w in words[0:20])) >>> print('1-20', ', '.join(w.orth_ for w in words[0:20]))
1-20 bragged, remonstrated, enquired, demurred, sighed, mused, intimated, retorted, entreated, motioned, ranted, confided, countersued, gestured, implored, interceded, muttered, marvelled, bickered, despaired 1-20 bragged, remonstrated, enquired, demurred, sighed, mused, intimated, retorted, entreated, motioned, ranted, confided, countersued, gestured, implored, interceded, muttered, marvelled, bickered, despaired