org.datavec.api.records.reader.impl.collection.ListStringRecordReader Java Examples

The following examples show how to use org.datavec.api.records.reader.impl.collection.ListStringRecordReader. 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 File: TestTransformProcess.java    From DataVec with 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 File: TestTransformProcess.java    From deeplearning4j with 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 File: DL4JMLModel.java    From neo4j-ml-procedures with 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 File: ListStringInputFormat.java    From DataVec with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a reader from an input split
 *
 * @param split the split to read
 * @return the reader from the given input split
 */
@Override
public RecordReader createReader(InputSplit split) throws IOException, InterruptedException {
    RecordReader reader = new ListStringRecordReader();
    reader.initialize(split);
    return reader;
}
 
Example #5
Source File: ListStringInputFormat.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a reader from an input split
 *
 * @param split the split to read
 * @return the reader from the given input split
 */
@Override
public RecordReader createReader(InputSplit split) throws IOException, InterruptedException {
    RecordReader reader = new ListStringRecordReader();
    reader.initialize(split);
    return reader;
}
 
Example #6
Source File: ListStringInputFormat.java    From DataVec with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a reader from an input split
 *
 * @param split the split to read
 * @param conf
 * @return the reader from the given input split
 */
@Override
public RecordReader createReader(InputSplit split, Configuration conf) throws IOException, InterruptedException {
    RecordReader reader = new ListStringRecordReader();
    reader.initialize(conf, split);
    return reader;
}
 
Example #7
Source File: ListStringInputFormat.java    From deeplearning4j with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a reader from an input split
 *
 * @param split the split to read
 * @param conf
 * @return the reader from the given input split
 */
@Override
public RecordReader createReader(InputSplit split, Configuration conf) throws IOException, InterruptedException {
    RecordReader reader = new ListStringRecordReader();
    reader.initialize(conf, split);
    return reader;
}