MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / tokens_to_vector

Function tokens_to_vector

nlp_class/sentiment.py:94–101  ·  view source on GitHub ↗
(tokens, label)

Source from the content-addressed store, hash-verified

92
93# now let's create our input matrices
94def tokens_to_vector(tokens, label):
95 x = np.zeros(len(word_index_map) + 1) # last element is for the label
96 for t in tokens:
97 i = word_index_map[t]
98 x[i] += 1
99 x = x / x.sum() # normalize it before setting label
100 x[-1] = label
101 return x
102
103N = len(positive_tokenized) + len(negative_tokenized)
104# (N x D+1 matrix - keeping them together for now so we can shuffle more easily later

Callers 1

sentiment.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected