org.datavec.api.util.ClassPathResource Java Examples
The following examples show how to use
org.datavec.api.util.ClassPathResource.
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: NeuralStyleTransfer.java From dl4j-tutorials with MIT License | 5 votes |
private INDArray createCombinationImage() throws IOException { INDArray content = LOADER.asMatrix(new ClassPathResource(CONTENT_FILE).getFile()); IMAGE_PRE_PROCESSOR.transform(content); INDArray combination = createCombineImageWithRandomPixels(); combination.muli(NOISE_RATION).addi(content.muli(1 - NOISE_RATION)); return combination; }
Example #2
Source File: DataPreview.java From StockPrediction with MIT License | 5 votes |
public static void main (String[] args) throws IOException { SparkSession spark = SparkSession.builder().master("local").appName("DataProcess").getOrCreate(); String filename = "prices-split-adjusted.csv"; String symbol = "GOOG"; // load data from csv file Dataset<Row> data = spark.read().format("csv").option("header", true) .load(new ClassPathResource(filename).getFile().getAbsolutePath()) //.filter(functions.col("symbol").equalTo(symbol)) //.drop("date").drop("symbol") .withColumn("openPrice", functions.col("open").cast("double")).drop("open") .withColumn("closePrice", functions.col("close").cast("double")).drop("close") .withColumn("lowPrice", functions.col("low").cast("double")).drop("low") .withColumn("highPrice", functions.col("high").cast("double")).drop("high") .withColumn("volumeTmp", functions.col("volume").cast("double")).drop("volume") .toDF("date", "symbol", "open", "close", "low", "high", "volume"); data.show(); Dataset<Row> symbols = data.select("date", "symbol").groupBy("symbol").agg(functions.count("date").as("count")); System.out.println("Number of Symbols: " + symbols.count()); symbols.show(); VectorAssembler assembler = new VectorAssembler() .setInputCols(new String[] {"open", "low", "high", "volume", "close"}) .setOutputCol("features"); data = assembler.transform(data).drop("open", "low", "high", "volume", "close"); data = new MinMaxScaler().setMin(0).setMax(1) .setInputCol("features").setOutputCol("normalizedFeatures") .fit(data).transform(data) .drop("features").toDF("features"); }
Example #3
Source File: ClassifyBySimilarity.java From Java-for-Data-Science with MIT License | 4 votes |
public static void main(String[] args) throws Exception { ClassPathResource srcFile = new ClassPathResource("/raw_sentences.txt"); File file = srcFile.getFile(); SentenceIterator iter = new BasicLineIterator(file); TokenizerFactory tFact = new DefaultTokenizerFactory(); tFact.setTokenPreProcessor(new CommonPreprocessor()); LabelsSource labelFormat = new LabelsSource("LINE_"); ParagraphVectors vec = new ParagraphVectors.Builder() .minWordFrequency(1) .iterations(5) .epochs(1) .layerSize(100) .learningRate(0.025) .labelsSource(labelFormat) .windowSize(5) .iterate(iter) .trainWordVectors(false) .tokenizerFactory(tFact) .sampling(0) .build(); vec.fit(); double similar1 = vec.similarity("LINE_9835", "LINE_12492"); out.println("Comparing lines 9836 & 12493 ('This is my house .'/'This is my world .') Similarity = " + similar1); double similar2 = vec.similarity("LINE_3720", "LINE_16392"); out.println("Comparing lines 3721 & 16393 ('This is my way .'/'This is my work .') Similarity = " + similar2); double similar3 = vec.similarity("LINE_6347", "LINE_3720"); out.println("Comparing lines 6348 & 3721 ('This is my case .'/'This is my way .') Similarity = " + similar3); double dissimilar1 = vec.similarity("LINE_3720", "LINE_9852"); out.println("Comparing lines 3721 & 9853 ('This is my way .'/'We now have one .') Similarity = " + dissimilar1); double dissimilar2 = vec.similarity("LINE_3720", "LINE_3719"); out.println("Comparing lines 3721 & 3720 ('This is my way .'/'At first he says no .') Similarity = " + dissimilar2); }
Example #4
Source File: ParagraphVectorsClassifierExample.java From Java-for-Data-Science with MIT License | 4 votes |
public static void main(String[] args) throws Exception { ClassPathResource resource = new ClassPathResource("paravec/labeled"); iter = new FileLabelAwareIterator.Builder() .addSourceFolder(resource.getFile()) .build(); tFact = new DefaultTokenizerFactory(); tFact.setTokenPreProcessor(new CommonPreprocessor()); pVect = new ParagraphVectors.Builder() .learningRate(0.025) .minLearningRate(0.001) .batchSize(1000) .epochs(20) .iterate(iter) .trainWordVectors(true) .tokenizerFactory(tFact) .build(); pVect.fit(); ClassPathResource unlabeledText = new ClassPathResource("paravec/unlabeled"); FileLabelAwareIterator unlabeledIter = new FileLabelAwareIterator.Builder() .addSourceFolder(unlabeledText.getFile()) .build(); MeansBuilder mBuilder = new MeansBuilder( (InMemoryLookupTable<VocabWord>) pVect.getLookupTable(), tFact); LabelSeeker lSeeker = new LabelSeeker(iter.getLabelsSource().getLabels(), (InMemoryLookupTable<VocabWord>) pVect.getLookupTable()); while (unlabeledIter.hasNextDocument()) { LabelledDocument doc = unlabeledIter.nextDocument(); INDArray docCentroid = mBuilder.documentAsVector(doc); List<Pair<String, Double>> scores = lSeeker.getScores(docCentroid); out.println("Document '" + doc.getLabel() + "' falls into the following categories: "); for (Pair<String, Double> score : scores) { out.println(" " + score.getFirst() + ": " + score.getSecond()); } } }
Example #5
Source File: NeuralStyleTransfer.java From dl4j-tutorials with MIT License | 4 votes |
private INDArray loadImage(String contentFile) throws IOException { INDArray content = LOADER.asMatrix(new ClassPathResource(contentFile).getFile()); IMAGE_PRE_PROCESSOR.transform(content); return content; }