001/*
002 * Copyright (c) 2015-2020, Oracle and/or its affiliates. All rights reserved.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.tribuo.classification.sgd.crf;
018
019import com.oracle.labs.mlrg.olcut.config.Option;
020import com.oracle.labs.mlrg.olcut.config.Options;
021import org.tribuo.Trainer;
022import org.tribuo.math.optimisers.GradientOptimiserOptions;
023
024/**
025 * CLI options for training a linear chain CRF model.
026 */
027public class CRFOptions implements Options {
028
029    public GradientOptimiserOptions sgoOptions;
030
031    @Option(longName = "crf-epochs", usage = "Epochs of SGD.")
032    private int epochs = 5;
033
034    @Option(longName = "crf-logging-interval", usage = "Logging interval for loss function.")
035    private int loggingInterval = 100;
036
037    @Option(longName = "crf-seed", usage = "Sets the random seed for the CRF.")
038    private long seed = Trainer.DEFAULT_SEED;
039
040    @Option(longName = "crf-minibatch", usage = "Sets the minibatch size in the CRF trainer.")
041    private int minibatchSize = 1;
042
043    /**
044     * Returns the configured CRF trainer.
045     * @return The CRF trainer.
046     */
047    public CRFTrainer getSequenceTrainer() {
048        return new CRFTrainer(sgoOptions.getOptimiser(), epochs, loggingInterval, minibatchSize, seed);
049    }
050
051}