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

Function sentence_to_vectors

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

Source from the content-addressed store, hash-verified

41# as a string and converts it into an array of words and then associates a
42# feature vector with each word.
43def sentence_to_vectors(sentence):
44 # Create an empty array of vectors
45 vects = dlib.vectors()
46 for word in sentence.split():
47 # Our vectors are very simple 1-dimensional vectors. The value of the
48 # single feature is 1 if the first letter of the word is capitalized and
49 # 0 otherwise.
50 if word[0].isupper():
51 vects.append(dlib.vector([1]))
52 else:
53 vects.append(dlib.vector([0]))
54 return vects
55
56
57# Dlib also supports the use of a sparse vector representation. This is more

Callers 1

Calls 3

splitMethod · 0.45
appendMethod · 0.45
vectorMethod · 0.45

Tested by

no test coverage detected