Пример #1
0
def test(model, testset, outfile):
    sys.stderr.write("Testing.\n")
    testing_tagfile = tempfile.NamedTemporaryFile(delete=False)
    testing_features = tempfile.NamedTemporaryFile(delete=False)
    # tag the testing file with placeholder tags
    crf_formatter.text_to_tagged(testset, testing_tagfile.name)
    # generate features for the tagged file
    features.generate(testing_tagfile.name, testing_features.name)

    # Generate predicted tags using the trained model
    sys.stderr.write("Predicting tags.\n")

    # Call CRFSuite using the command line to tag the testing_features
    # using your trained CRF model.
    cmd = ["crfsuite", "tag", "-m", model, testing_features.name]
    predictions, _ = Popen(cmd, stdout=PIPE).communicate()

    # pair the testing characters with their predicted tags
    # convert the tagged file back to lines of text
    crf_formatter.predictions_to_text(testing_tagfile.name,
                                      predictions.split('\n'),
                                      outfile=outfile)

    # clear the temp files
    os.unlink(testing_tagfile.name)
    os.unlink(testing_features.name)
Пример #2
0
def test(model, testset, outfile):
	sys.stderr.write("Testing.\n")
	testing_tagfile = tempfile.NamedTemporaryFile(delete=False)
	testing_features = tempfile.NamedTemporaryFile(delete=False)
	# tag the testing file with placeholder tags
	crf_formatter.text_to_tagged(testset, testing_tagfile.name)
	# generate features for the tagged file
	features.generate(testing_tagfile.name, testing_features.name)
	
	# Generate predicted tags using the trained model
	sys.stderr.write("Predicting tags.\n")

	# Call CRFSuite using the command line to tag the testing_features
	# using your trained CRF model.
	
	cmd = None ### YOUR CODE HERE: define the command.
	predictions, _ = Popen(cmd, stdout=PIPE).communicate()
	
	# pair the testing characters with their predicted tags
	# convert the tagged file back to lines of text
	crf_formatter.predictions_to_text(testing_tagfile.name, predictions.split('\n'), outfile=outfile)
	
	# clear the temp files
	os.unlink(testing_tagfile.name)
	os.unlink(testing_features.name)
Пример #3
0
def train(model, trainset):
	sys.stderr.write("Training.\n")
	training_tagfile = tempfile.NamedTemporaryFile(delete=False)
	training_features = tempfile.NamedTemporaryFile(delete=False)
	# tag the segmented training set
	crf_formatter.text_to_tagged(trainset, training_tagfile.name)
	# generate features for the tagged set
	features.generate(training_tagfile.name, training_features.name)

	# Call CRFSuite using the command line to train a CRF model.
	cmd = ["crfsuite",  "learn", "-m", model, training_features.name]
	call(cmd)

	# clear the temp files
	os.unlink(training_tagfile.name)
	os.unlink(training_features.name)
Пример #4
0
def train(model, trainset):
    sys.stderr.write("Training.\n")
    training_tagfile = tempfile.NamedTemporaryFile(delete=False)
    training_features = tempfile.NamedTemporaryFile(delete=False)
    # tag the segmented training set
    crf_formatter.text_to_tagged(trainset, training_tagfile.name)
    # generate features for the tagged set
    features.generate(training_tagfile.name, training_features.name)

    # Call CRFSuite using the command line to train a CRF model.
    cmd = ["crfsuite", "learn", "-m", model, training_features.name]
    call(cmd)

    # clear the temp files
    os.unlink(training_tagfile.name)
    os.unlink(training_features.name)