Java Code Examples for org.datavec.api.split.ListStringSplit

The following examples show how to use org.datavec.api.split.ListStringSplit. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DataVec   Source File: TestTransformProcess.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInferColumns()  throws Exception {
    List<List<String>> categories = Arrays.asList(
            Arrays.asList("a","d")  ,
            Arrays.asList("b","e"),
            Arrays.asList("c","f")
    );

    RecordReader listReader = new ListStringRecordReader();
    listReader.initialize(new ListStringSplit(categories));
    List<String> inferredSingle = TransformProcess.inferCategories(listReader,0);
    assertEquals(3,inferredSingle.size());
    listReader.initialize(new ListStringSplit(categories));
    Map<Integer, List<String>> integerListMap = TransformProcess.inferCategories(listReader, new int[]{0,1});
    for(int i = 0; i < 2; i++) {
        assertEquals(3,integerListMap.get(i).size());
    }
}
 
Example 2
Source Project: deeplearning4j   Source File: TestTransformProcess.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testInferColumns()  throws Exception {
    List<List<String>> categories = Arrays.asList(
            Arrays.asList("a","d")  ,
            Arrays.asList("b","e"),
            Arrays.asList("c","f")
    );

    RecordReader listReader = new ListStringRecordReader();
    listReader.initialize(new ListStringSplit(categories));
    List<String> inferredSingle = TransformProcess.inferCategories(listReader,0);
    assertEquals(3,inferredSingle.size());
    listReader.initialize(new ListStringSplit(categories));
    Map<Integer, List<String>> integerListMap = TransformProcess.inferCategories(listReader, new int[]{0,1});
    for(int i = 0; i < 2; i++) {
        assertEquals(3,integerListMap.get(i).size());
    }
}
 
Example 3
Source Project: neo4j-ml-procedures   Source File: DL4JMLModel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
    protected Object doPredict(List<String> line) {
        try {
            ListStringSplit input = new ListStringSplit(Collections.singletonList(line));
            ListStringRecordReader rr = new ListStringRecordReader();
            rr.initialize(input);
            DataSetIterator iterator = new RecordReaderDataSetIterator(rr, 1);

            DataSet ds = iterator.next();
            INDArray prediction = model.output(ds.getFeatures());

            DataType outputType = types.get(this.output);
            switch (outputType) {
                case _float : return prediction.getDouble(0);
                case _class: {
                    int numClasses = 2;
                    double max = 0;
                    int maxIndex = -1;
                    for (int i=0;i<numClasses;i++) {
                        if (prediction.getDouble(i) > max) {maxIndex = i; max = prediction.getDouble(i);}
                    }
                    return maxIndex;
//                    return prediction.getInt(0,1); // numberOfClasses
                }
                default: throw new IllegalArgumentException("Output type not yet supported "+outputType);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
Example 4
Source Project: DataVec   Source File: ListStringInputMarshaller.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param exchange
 * @return
 */
@Override
public InputSplit getSplit(Exchange exchange) {
    List<List<String>> data = (List<List<String>>) exchange.getIn().getBody();
    InputSplit listSplit = new ListStringSplit(data);
    return listSplit;
}
 
Example 5
Source Project: DataVec   Source File: ListStringInputMarshaller.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param exchange
 * @return
 */
@Override
public InputSplit getSplit(Exchange exchange) {
    List<List<String>> data = (List<List<String>>) exchange.getIn().getBody();
    InputSplit listSplit = new ListStringSplit(data);
    return listSplit;
}
 
Example 6
Source Project: DataVec   Source File: ListStringRecordReader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Called once at initialization.
 *
 * @param split the split that defines the range of records to read
 * @throws IOException
 * @throws InterruptedException
 */
@Override
public void initialize(InputSplit split) throws IOException, InterruptedException {
    if (split instanceof ListStringSplit) {
        ListStringSplit listStringSplit = (ListStringSplit) split;
        delimitedData = listStringSplit.getData();
        dataIter = delimitedData.iterator();
    } else {
        throw new IllegalArgumentException("Illegal type of input split " + split.getClass().getName());
    }
}
 
Example 7
Source Project: deeplearning4j   Source File: ListStringRecordReader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Called once at initialization.
 *
 * @param split the split that defines the range of records to read
 * @throws IOException
 * @throws InterruptedException
 */
@Override
public void initialize(InputSplit split) throws IOException, InterruptedException {
    if (split instanceof ListStringSplit) {
        ListStringSplit listStringSplit = (ListStringSplit) split;
        delimitedData = listStringSplit.getData();
        dataIter = delimitedData.iterator();
    } else {
        throw new IllegalArgumentException("Illegal type of input split " + split.getClass().getName());
    }
}