Skip to content

Instantly share code, notes, and snippets.

MultiDataSetIterator iterator = new RecordReaderMultiDataSetIterator.Builder(batchSize)
.addReader("csvInput", featuresReader)
.addReader("csvLabels", labelsReader)
.addInput("csvInput") //Input: all columns from input reader
.addOutput("csvLabels", 0, 3) //Output 1: columns 0 to 3 inclusive
.addOutputOneHot("csvLabels", 4, numClasses) //Output 2: column 4 -> convert to one-hot for classification
.build();
@tastyminerals
tastyminerals / TestMultiIter
Created January 29, 2018 16:13
Testing DL4J multiiter
// init DL4J seq readers
val seqWordsReader = new CSVSequenceRecordReader()
seqWordsReader.initialize(new FileSplit(new File(wordsFileSavePath)))
val seqFeatsReader = new CSVSequenceRecordReader()
seqFeatsReader.initialize(new FileSplit(new File(featsFileSavePath)))
val seqLabelsReader = new CSVSequenceRecordReader()
seqLabelsReader.initialize(new FileSplit(new File(labelsFileSavePath)))
@tastyminerals
tastyminerals / test
Created January 30, 2018 13:32
MultiDataSetIterator
// init DL4J seq readers
val seqWordsReader = new CSVSequenceRecordReader()
seqWordsReader.initialize(new FileSplit(new File(wordsFileSavePath)))
val seqFeatsReader = new CSVSequenceRecordReader()
seqFeatsReader.initialize(new FileSplit(new File(featsFileSavePath)))
val seqLabelsReader = new CSVSequenceRecordReader()
seqLabelsReader.initialize(new FileSplit(new File(labelsFileSavePath)))
@tastyminerals
tastyminerals / demo
Created January 30, 2018 13:50
demoNet
class NetworkInit(vocabSize: Int) {
private val embeddingWidth = DatasetTools.getTomlConfTable("romain").getLong("inputsize").toInt
private val hiddenSize = DatasetTools.getTomlConfTable("romain").getLong("hiddensize").toInt
private val numberOfFeats = DatasetTools.getTomlConfTable("romain").getLong("feats").toInt
private val numberOfClasses = DatasetTools.getTomlConfTable("romain").getLong("classes").toInt
val config: ComputationGraphConfiguration = new NeuralNetConfiguration.Builder()
.learningRate(DatasetTools.getTomlConfTable("romain").getDouble("minlr"))
.graphBuilder()
.addInputs("wordIndeces")
class NetworkInit(vocabSize: Int) {
private val embeddingWidth = 100
private val hiddenSize = 200
private val numberOfFeats = 9
private val numberOfClasses = 1
val config: ComputationGraphConfiguration = new NeuralNetConfiguration.Builder()
.learningRate(DatasetTools.getTomlConfTable("romain").getDouble("minlr"))
.graphBuilder()
.addInputs("wordIndeces")
@tastyminerals
tastyminerals / change.d
Created November 25, 2019 11:13
change-making problem in D (naive implementation)
#!/usr/bin/rdmd
import std.algorithm : cartesianProduct;
import std.array;
import std.container.rbtree : redBlackTree;
import std.stdio;
int minimum_coins(int target, in int[] denominations)
{
auto origSet = redBlackTree(target);
@tastyminerals
tastyminerals / benchmarks.md
Last active January 2, 2021 12:36
Julia vs Numpy
Description NumPy (MKL) (sec.) Julia (sec.)
Dot (scalar) product of two 300000 arrays (float64), (1000 loops) 0.03528142820068751 0.027905 (x1/1.3)
Element-wise sum of two 100x100 matrices (int), (1000 loops) 0.0037877704002312385 0.0061 (x1.6)
Element-wise multiplication of two 100x100 matrices (float64), (1000 loops) 0.004193491550176986 0.032161 (x7.7)
L2 norm of 500x600 matrix (float64), (1000 loops) 0.023907507749936486 0.096 (x4)
Matrix product of 500x600 and 600x500 matrices (float64) 0.0018566828504845035 0.01988 (x10.7)
Sort of 500x600 matrix (float64) **0.0103262
@tastyminerals
tastyminerals / julia_bench.jl
Last active March 29, 2020 20:06
Julia benchmarks
using BenchmarkTools
using Random
using LinearAlgebra
BenchmarkTools.DEFAULT_PARAMETERS.evals = 20
# define arrays and matrices
rows, cols = 500, 600
reduceRows, reduceCols = Int(rows / 5), Int(cols / 6)
@tastyminerals
tastyminerals / numpy_bench.py
Created March 29, 2020 20:01
Numpy benchmarks
import argparse
from collections import defaultdict as dd
from time import perf_counter as timer
import numpy as np
def functions(nruns=1):
rows, cols = 500, 600
reduceRows, reduceCols = rows / 5, cols / 6