MCPcopy Create free account
hub / github.com/davisking/dlib / sentence_to_sparse_vectors

Function sentence_to_sparse_vectors

python_examples/sequence_segmenter.py:66–80  ·  view source on GitHub ↗
(sentence)

Source from the content-addressed store, hash-verified

64# pairs into your sparse vectors in any order you want and don't need to worry
65# about them being in sorted order.
66def sentence_to_sparse_vectors(sentence):
67 vects = dlib.sparse_vectors()
68 has_cap = dlib.sparse_vector()
69 no_cap = dlib.sparse_vector()
70 # make has_cap equivalent to dlib.vector([1])
71 has_cap.append(dlib.pair(0, 1))
72
73 # Since we didn't add anything to no_cap it is equivalent to
74 # dlib.vector([0])
75 for word in sentence.split():
76 if word[0].isupper():
77 vects.append(has_cap)
78 else:
79 vects.append(no_cap)
80 return vects
81
82
83def print_segment(sentence, names):

Callers 1

Calls 2

appendMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected