All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.deeplearning4j.models.embeddings.learning.impl.elements.BatchSequences Maven / Gradle / Ivy

/*******************************************************************************
 * Copyright (c) 2015-2019 Skymind, Inc.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Apache License, Version 2.0 which is available at
 * https://www.apache.org/licenses/LICENSE-2.0.
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 ******************************************************************************/

package org.deeplearning4j.models.embeddings.learning.impl.elements;

import lombok.extern.slf4j.Slf4j;
import org.deeplearning4j.models.sequencevectors.sequence.SequenceElement;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

@Slf4j
public class BatchSequences {

    private int batches;

    List> buffer = new ArrayList<>();

    public BatchSequences(int batches) {
        this.batches = batches;
    }

    public void put(T word, T lastWord, long randomValue, double alpha) {
        BatchItem newItem = new BatchItem<>(word, lastWord, randomValue, alpha);
        buffer.add(newItem);
    }

    public void put(T word, int[] windowWords, boolean[] wordStatuses, long randomValue, double alpha) {
        BatchItem newItem = new BatchItem<>(word, windowWords, wordStatuses, randomValue, alpha);
        buffer.add(newItem);
    }

    public void put(T word, int[] windowWords, boolean[] wordStatuses, long randomValue, double alpha, int numLabels) {
        BatchItem newItem = new BatchItem<>(word, windowWords, wordStatuses, randomValue, alpha, numLabels);
        buffer.add(newItem);
    }

    public List> get(int chunkNo) {
        List> retVal = new ArrayList<>();

        for (int i = 0 + chunkNo * batches; (i < batches + chunkNo * batches) && (i < buffer.size()); ++i) {
            BatchItem value = buffer.get(i);
            retVal.add(value);
        }
        return retVal;
    }

    public int size() {
        return buffer.size();
    }

    public void clear() {
        buffer.clear();
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy