def generate_test_vectorss(): vss = vectorss() vss.append(generate_test_vectors()) vss.append(generate_test_vectors()) vss.append(generate_test_vectors()) assert len(vss) == 3 return vss
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 params.use_high_order_features = True params.use_BIO_model = True # This is the common SVM C parameter. Larger values encourage the trainer to # attempt to fit the data exactly but might overfit. In general, you determine # this parameter by cross-validation.
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 params.use_high_order_features = True params.use_BIO_model = True # This is the common SVM C parameter. Larger values encourage the trainer to attempt to # fit the data exactly but might overfit. In general, you determine this parameter by
def test_vectorss_extend(): vss = vectorss() vss.extend([generate_test_vectors(), generate_test_vectors()]) assert len(vss) == 2
def test_vectorss_resize(): vss = vectorss() vss.resize(100) assert len(vss) == 100 for i in range(100): assert len(vss[i]) == 0