def test_sparse_vectorss(): svss = sparse_vectorss() assert len(svss) == 0 svss.resize(5) for svs in svss: assert len(svs) == 0 svss.clear() assert len(svss) == 0 svss.extend([ sparse_vectors([ sparse_vector([pair(1, 2), pair(3, 4)]), sparse_vector([pair(5, 6), pair(7, 8)]) ]) ]) assert len(svss) == 1 assert svss[0][0][0].first == 1 assert svss[0][0][0].second == 2 assert svss[0][0][1].first == 3 assert svss[0][0][1].second == 4 assert svss[0][1][0].first == 5 assert svss[0][1][0].second == 6 assert svss[0][1][1].first == 7 assert svss[0][1][1].second == 8 deser = pickle.loads(pickle.dumps(svss, 2)) assert deser == svss
names.append(dlib.range(5, 8)) segments.append(names) names.clear() sentences.append("No names in this sentence at all") segments.append(names) names.clear() # Now before we can pass these training sentences to the dlib tools we need to # convert them into arrays of vectors as discussed above. We can use either a # sparse or dense representation depending on our needs. In this example, we # show how to do it both ways. use_sparse_vects = False if use_sparse_vects: # Make an array of arrays of dlib.sparse_vector objects. training_sequences = dlib.sparse_vectorss() for s in sentences: training_sequences.append(sentence_to_sparse_vectors(s)) else: # Make an array of arrays of dlib.vector objects. training_sequences = dlib.vectorss() for s in sentences: training_sequences.append(sentence_to_vectors(s)) # Now that we have a simple training set we can train a sequence segmenter. # However, the sequence segmentation trainer has some optional parameters we can # set. These parameters determine properties of the segmentation model we will # learn. See the dlib documentation for the sequence_segmenter object for a # full discussion of their meanings. params = dlib.segmenter_params() params.window_size = 3
segments.append(names) names.clear() sentences.append("No names in this sentence at all") segments.append(names) names.clear() # Now before we can pass these training sentences to the dlib tools we need to convert them # into arrays of vectors as discussed above. We can use either a sparse or dense # representation depending on our needs. In this example, we show how to do it both ways. use_sparse_vects = False if use_sparse_vects: # Make an array of arrays of dlib.sparse_vector objects. training_sequences = dlib.sparse_vectorss() for s in sentences: training_sequences.append(sentence_to_sparse_vectors(s)) else: # Make an array of arrays of dlib.vector objects. training_sequences = dlib.vectorss() for s in sentences: training_sequences.append(sentence_to_vectors(s)) # Now that we have a simple training set we can train a sequence segmenter. However, the # sequence segmentation trainer has some optional parameters we can set. These parameters # determine properties of the segmentation model we will learn. See the dlib documentation # for the sequence_segmenter object for a full discussion of their meanings. params = dlib.segmenter_params()