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.sequence; 018 019import com.oracle.labs.mlrg.olcut.config.Configurable; 020import com.oracle.labs.mlrg.olcut.provenance.Provenancable; 021import com.oracle.labs.mlrg.olcut.provenance.Provenance; 022import org.tribuo.Output; 023import org.tribuo.provenance.TrainerProvenance; 024 025import java.util.Collections; 026import java.util.Map; 027 028/** 029 * An interface for things that can train sequence prediction models. 030 */ 031public interface SequenceTrainer<T extends Output<T>> extends Configurable, Provenancable<TrainerProvenance> { 032 033 /** 034 * Trains a sequence prediction model using the examples in the given data set. 035 * @param examples the data set containing the examples. 036 * @return a prediction model that can be used to predict values for new examples. 037 */ 038 default public SequenceModel<T> train(SequenceDataset<T> examples) { 039 return train(examples, Collections.emptyMap()); 040 } 041 042 /** 043 * Trains a sequence prediction model using the examples in the given data set. 044 * @param examples the data set containing the examples. 045 * @param runProvenance Training run specific provenance (e.g., fold number). 046 * @return a predictive model that can be used to generate predictions for new examples. 047 */ 048 public SequenceModel<T> train(SequenceDataset<T> examples, Map<String, Provenance> runProvenance); 049 050 /** 051 * Returns the number of times the train method has been invoked. 052 * @return The number of times train has been invoked. 053 */ 054 public int getInvocationCount(); 055}