# of names in new sentences. model = dlib.train_sequence_segmenter(training_sequences, segments, params) # Let's print out the things the model thinks are names. The output is a set # of ranges which are predicted to contain names. If you run this example # program you will see that it gets them all correct. for i, s in enumerate(sentences): print_segment(s, model(training_sequences[i])) # Let's also try segmenting a new sentence. This will print out "Bob Bucket". # Note that we need to remember to use the same vector representation as we used # during training. test_sentence = "There once was a man from Nantucket " \ "whose name rhymed with Bob Bucket" if use_sparse_vects: print_segment(test_sentence, model(sentence_to_sparse_vectors(test_sentence))) else: print_segment(test_sentence, model(sentence_to_vectors(test_sentence))) # We can also measure the accuracy of a model relative to some labeled data. # This statement prints the precision, recall, and F1-score of the model # relative to the data in training_sequences/segments. print("Test on training data: {}".format( dlib.test_sequence_segmenter(model, training_sequences, segments))) # We can also do 5-fold cross-validation and print the resulting precision, # recall, and F1-score. print("Cross validation: {}".format( dlib.cross_validate_sequence_segmenter(training_sequences, segments, 5, params)))
model = dlib.train_sequence_segmenter(training_sequences, segments, params) # Let's print out the things the model thinks are names. The output is a set # of ranges which are predicted to contain names. If you run this example # program you will see that it gets them all correct. for i, s in enumerate(sentences): print_segment(s, model(training_sequences[i])) # Let's also try segmenting a new sentence. This will print out "Bob Bucket". # Note that we need to remember to use the same vector representation as we used # during training. test_sentence = "There once was a man from Nantucket " \ "whose name rhymed with Bob Bucket" if use_sparse_vects: print_segment(test_sentence, model(sentence_to_sparse_vectors(test_sentence))) else: print_segment(test_sentence, model(sentence_to_vectors(test_sentence))) # We can also measure the accuracy of a model relative to some labeled data. # This statement prints the precision, recall, and F1-score of the model # relative to the data in training_sequences/segments. print("Test on training data: {}".format( dlib.test_sequence_segmenter(model, training_sequences, segments))) # We can also do 5-fold cross-validation and print the resulting precision, # recall, and F1-score. print("Cross validation: {}".format( dlib.cross_validate_sequence_segmenter(training_sequences, segments, 5, params)))
params.C = 10 # Train a model. The model object is responsible for predicting the locations of names in # new sentences. model = dlib.train_sequence_segmenter(training_sequences, segments, params) # Lets print out the things the model thinks are names. The output is a set of ranges # which are predicted to contain names. If you run this example program you will see that # it gets them all correct. for i in range(len(sentences)): print_segment(sentences[i], model(training_sequences[i])) # Lets also try segmenting a new sentence. This will print out "Bob Bucket". Note that we # need to remember to use the same vector representation as we used during training. test_sentence = "There once was a man from Nantucket whose name rhymed with Bob Bucket" if use_sparse_vects: print_segment(test_sentence, model(sentence_to_sparse_vectors(test_sentence))) else: print_segment(test_sentence, model(sentence_to_vectors(test_sentence))) # We can also measure the accuracy of a model relative to some labeled data. This # statement prints the precision, recall, and F1-score of the model relative to the data in # training_sequences/segments. print "Test on training data:", dlib.test_sequence_segmenter(model, training_sequences, segments) # We can also do 5-fold cross-validation and print the resulting precision, recall, and F1-score. print "cross validation:", dlib.cross_validate_sequence_segmenter(training_sequences, segments, 5, params)
params.C = 10 # Train a model. The model object is responsible for predicting the locations of names in # new sentences. model = dlib.train_sequence_segmenter(training_sequences, segments, params) # Lets print out the things the model thinks are names. The output is a set of ranges # which are predicted to contain names. If you run this example program you will see that # it gets them all correct. for i in range(len(sentences)): print_segment(sentences[i], model(training_sequences[i])) # Lets also try segmenting a new sentence. This will print out "Bob Bucket". Note that we # need to remember to use the same vector representation as we used during training. test_sentence = "There once was a man from Nantucket whose name rhymed with Bob Bucket" if use_sparse_vects: print_segment(test_sentence, model(sentence_to_sparse_vectors(test_sentence))) else: print_segment(test_sentence, model(sentence_to_vectors(test_sentence))) # We can also measure the accuracy of a model relative to some labeled data. This # statement prints the precision, recall, and F1-score of the model relative to the data in # training_sequences/segments. print "Test on training data:", dlib.test_sequence_segmenter( model, training_sequences, segments) # We can also do 5-fold cross-validation and print the resulting precision, recall, and F1-score. print "cross validation:", dlib.cross_validate_sequence_segmenter( training_sequences, segments, 5, params)