Skip to content

Instantly share code, notes, and snippets.

View dmmiller612's full-sized avatar

Derek Miller dmmiller612

  • DeepCure
  • Boston, Massachusetts
View GitHub Profile
@dmmiller612
dmmiller612 / sparktorch_example.py
Last active July 26, 2022 20:06
SparkTorch Example
from sparktorch import SparkTorch, serialize_torch_obj
from pyspark.sql import SparkSession
from pyspark.ml.feature import VectorAssembler
from pyspark.sql.functions import rand
from pyspark.ml.pipeline import Pipeline
import torch
import torch.nn as nn
spark = SparkSession.builder.appName("examples").master('local[*]').getOrCreate()
@dmmiller612
dmmiller612 / sparkflow_example.py
Last active July 26, 2022 20:07
SparkFlow example
from sparkflow.graph_utils import build_graph
from sparkflow.tensorflow_async import SparkAsyncDL
import tensorflow as tf
from pyspark.ml.feature import VectorAssembler, OneHotEncoder
from pyspark.ml.pipeline import Pipeline
#simple tensorflow network
def small_model():
x = tf.placeholder(tf.float32, shape=[None, 784], name='x')
y = tf.placeholder(tf.float32, shape=[None, 10], name='y')
@dmmiller612
dmmiller612 / tensorflow_json.py
Created December 11, 2017 15:58
Tensorflow Graph and weights to json and back for training
import tensorflow as tf
import numpy as np
from google.protobuf import json_format
import json
np.random.seed(12345)
def tensorflow_get_weights():
"""
@dmmiller612
dmmiller612 / serialize_tensorflow.py
Created December 11, 2017 15:42
Tensorflow Serialize and Deserialize GraphDef and set weights.
import tensorflow as tf
import numpy as np
from google.protobuf import json_format
np.random.seed(12345)
def tensorflow_get_weights():
"""
@author https://github.com/maxim5
@dmmiller612
dmmiller612 / KerasAttention.py
Last active June 19, 2021 08:32
Keras Sequence to Sequence LSTM with Attention Mechanism
from keras.layers.core import Permute
from keras.layers import Dense, Activation, RepeatVector, merge,Flatten, TimeDistributed, Input
from keras.layers import Embedding, LSTM
from keras.models import Model
hidden = 225
features = get_features()
outputs = get_outputs()
@dmmiller612
dmmiller612 / KerasSequenceToSeqenceExample.py
Last active June 6, 2017 19:01
Keras Sequence to Sequence Simple example
from __future__ import print_function
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.layers import LSTM, Masking
from keras.optimizers import RMSprop
import numpy as np
"""
This gist shows you have to do a simple seq-to-seq with keras with words instead of chars.
It is roughly based on this example https://github.com/fchollet/keras/blob/master/examples/lstm_text_generation.py
@dmmiller612
dmmiller612 / ExampleUsage.java
Last active March 16, 2023 10:12
Spark DL4J Dataframe/Dataset usage
import org.apache.spark.ml.feature.*;
class ExampleUsage {
public void example(){
List<Row> dubs = Lists.newArrayList(
RowFactory.create(1000.0, 1000.0, 1.0),
RowFactory.create(90.0, 90.0, 0.0)
);
DataFrame df = sqlContext.createDataFrame(dubs, createStruct());
@dmmiller612
dmmiller612 / RealCodedGeneticAlgorithm.java
Last active August 21, 2016 13:49
excerpt from one of my machine learning libraries of a real coded genetic algorithm.
import com.derek.ml.math.ErrorFunctions;
import com.derek.ml.math.Statistics;
import com.derek.ml.model.Chromosome;
import com.derek.ml.model.LabeledPoint;
import com.derek.ml.model.Pair;
import java.util.*;
import java.util.stream.Collectors;
@dmmiller612
dmmiller612 / SparkCDGist.java
Last active June 21, 2016 14:30
Java Spark Gist for Linear Regression after a group by and conversion from JavaPairRdd<Something, Iterable<Something>> to Map<Something, LinearRegressionModel.
package cdapp.services;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.ml.Pipeline;