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.interop.tensorflow.sequence;
018
019import com.oracle.labs.mlrg.olcut.config.Configurable;
020import com.oracle.labs.mlrg.olcut.provenance.ConfiguredObjectProvenance;
021import com.oracle.labs.mlrg.olcut.provenance.Provenancable;
022import org.tribuo.ImmutableFeatureMap;
023import org.tribuo.Output;
024import org.tribuo.sequence.SequenceExample;
025import org.tensorflow.Tensor;
026
027import java.io.Serializable;
028import java.util.List;
029import java.util.Map;
030
031/**
032 * Converts a sequence example into a feed dict suitable for Tensorflow.
033 */
034public interface SequenceExampleTransformer<T extends Output<T>> extends Configurable, Provenancable<ConfiguredObjectProvenance>, Serializable {
035
036    /**
037     * Encodes an example as a feed dict.
038     *
039     * @param example the input example
040     * @param featureMap feature domain
041     * @return a map from graph placeholder names to their fed-in values.
042     */
043    Map<String, Tensor<?>> encode(SequenceExample<T> example, ImmutableFeatureMap featureMap);
044
045    /**
046     * Encodes a batch of examples as a feed dict.
047     *
048     * @param batch a batch of examples.
049     * @param featureMap feature domain
050     * @return a map from graph placeholder names to their fed-in values.
051     */
052    Map<String, Tensor<?>> encode(List<SequenceExample<T>> batch, ImmutableFeatureMap featureMap);
053
054}