Search in sources :

Example 11 with Counter

use of org.deeplearning4j.berkeley.Counter in project deeplearning4j by deeplearning4j.

the class CountCumSum method cumSumWithinPartition.

// Do cum sum within the partition
public void cumSumWithinPartition() {
    // Accumulator to get the max of the cumulative sum in each partition
    final Accumulator<Counter<Integer>> maxPerPartitionAcc = sc.accumulator(new Counter<Integer>(), new MaxPerPartitionAccumulator());
    // Partition mapping to fold within partition
    foldWithinPartitionRDD = sentenceCountRDD.mapPartitionsWithIndex(new FoldWithinPartitionFunction(maxPerPartitionAcc), true).cache();
    actionForMapPartition(foldWithinPartitionRDD);
    // Broadcast the counter (partition index : sum of count) to all workers
    broadcastedMaxPerPartitionCounter = sc.broadcast(maxPerPartitionAcc.value());
}
Also used : Counter(org.deeplearning4j.berkeley.Counter) MaxPerPartitionAccumulator(org.deeplearning4j.spark.text.accumulators.MaxPerPartitionAccumulator)

Example 12 with Counter

use of org.deeplearning4j.berkeley.Counter in project deeplearning4j by deeplearning4j.

the class UpdateWordFreqAccumulatorFunction method call.

// Function to add to word freq counter and total count of words
@Override
public Pair<List<String>, AtomicLong> call(List<String> lstOfWords) throws Exception {
    List<String> stops = stopWords.getValue();
    Counter<String> counter = new Counter<>();
    for (String w : lstOfWords) {
        if (w.isEmpty())
            continue;
        if (!stops.isEmpty()) {
            if (stops.contains(w)) {
                counter.incrementCount("STOP", 1.0);
            } else {
                counter.incrementCount(w, 1.0);
            }
        } else {
            counter.incrementCount(w, 1.0);
        }
    }
    wordFreqAcc.add(counter);
    AtomicLong lstOfWordsSize = new AtomicLong(lstOfWords.size());
    return new Pair<>(lstOfWords, lstOfWordsSize);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) Counter(org.deeplearning4j.berkeley.Counter) Pair(org.deeplearning4j.berkeley.Pair)

Aggregations

Counter (org.deeplearning4j.berkeley.Counter)12 INDArray (org.nd4j.linalg.api.ndarray.INDArray)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Pair (org.deeplearning4j.berkeley.Pair)3 ND4JIllegalStateException (org.nd4j.linalg.exception.ND4JIllegalStateException)3 ArrayList (java.util.ArrayList)2 JavaSparkContext (org.apache.spark.api.java.JavaSparkContext)2 InMemoryLookupTable (org.deeplearning4j.models.embeddings.inmemory.InMemoryLookupTable)2 RoutedTransport (org.nd4j.parameterserver.distributed.transport.RoutedTransport)2 DL4JInvalidConfigException (org.deeplearning4j.exception.DL4JInvalidConfigException)1 ExportContainer (org.deeplearning4j.spark.models.sequencevectors.export.ExportContainer)1 ExtraCounter (org.deeplearning4j.spark.models.sequencevectors.primitives.ExtraCounter)1 NetworkInformation (org.deeplearning4j.spark.models.sequencevectors.primitives.NetworkInformation)1 NetworkOrganizer (org.deeplearning4j.spark.models.sequencevectors.utils.NetworkOrganizer)1 MaxPerPartitionAccumulator (org.deeplearning4j.spark.text.accumulators.MaxPerPartitionAccumulator)1 WordFreqAccumulator (org.deeplearning4j.spark.text.accumulators.WordFreqAccumulator)1 VoidConfiguration (org.nd4j.parameterserver.distributed.conf.VoidConfiguration)1