Skip to content

Instantly share code, notes, and snippets.

View malzzz's full-sized avatar

Mallory M. malzzz

  • Bivalent Capital
  • /dev/null
View GitHub Profile
@malzzz
malzzz / gist:37784f06bb57b725c6ab
Created February 28, 2016 23:35
This should work
from tensorflow.models.embedding.word2vec_optimized import FLAGS, Options, Word2Vec
FLAGS1 = FLAGS
FLAGS2 = FLAGS
class MyOptions(Options):
def __init__(self):
super(MyOptions, self).__init__()
self.train_data = FLAGS1.train_data = "new_train_data"
import org.deeplearning4j.nn.api.OptimizationAlgorithm
import org.deeplearning4j.nn.conf._
import org.deeplearning4j.nn.conf.graph.MergeVertex
import org.deeplearning4j.nn.conf.layers._
import org.deeplearning4j.nn.weights.WeightInit
import org.nd4j.linalg.lossfunctions.LossFunctions
/**
* GoogLeNet: https://arxiv.org/abs/1409.4842
*/
@malzzz
malzzz / NArray.scala
Created September 28, 2016 20:24
Refactoring stuff, saving this for later
trait NArray[I, A] { self =>
def dims: List[Idx[I]]
def coords: data.Vector[A]
def resetCoords(v: data.Vector[A]): NArray[I, A] =
if (coords.dim == v.dim) {
new NArray[I, A] {
val dims = self.dims
val coords = v
@malzzz
malzzz / convolution.scala
Last active October 2, 2016 04:16
Functional 2d convolution, less broken; i.e., works (I think). Probably slow af.
def conv2[A: ClassTag](input: Vector[A], kernel: Vector[A], padding: Int, stride: Int)(implicit ev: Numeric[A]) = {
// Static sizes
val inputHW = sqrt(input.length).toInt
val kernelHW = sqrt(kernel.length).toInt
val rowSizeAfterPad = inputHW + kernelHW - 1
val rowSizeStrided = rowSizeAfterPad + stride
val opsPerPass = rowSizeAfterPad / kernelHW
val passSize = kernelHW * rowSizeStrided
val inputSizePaddedStrided = (rowSizeStrided * inputHW) + (rowSizeStrided * 2)
@malzzz
malzzz / gist:15639fc36d069490b7709be2f3a4d522
Last active March 27, 2023 16:21 — forked from Frozenfire92/gist:3627e38dc47ca581d6d024c14c1cf4a9
Install Scala 2.12.3 and SBT using apt-get on Ubuntu 16.04
## Java
sudo apt-get update
sudo apt-get install default-jdk
## Scala
sudo apt-get remove scala-library scala
sudo wget https://downloads.lightbend.com/scala/2.12.3/scala-2.12.3.deb
sudo dpkg -i scala-2.12.3.deb
sudo apt-get update
sudo apt-get install scala
0xE0Bfce34f6e43b54D7C68dEc29675A92c60ECb6E
0xb7BfB0d9c2c93a22FE911f871B0D9e4160FDCafE
@malzzz
malzzz / Future-retry.scala
Created October 31, 2017 14:20 — forked from viktorklang/Future-retry.scala
Asynchronous retry for Future in Scala
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext
import scala.concurrent.Future
import akka.pattern.after
import akka.actor.Scheduler
/**
* Given an operation that produces a T, returns a Future containing the result of T, unless an exception is thrown,
* in which case the operation will be retried after _delay_ time, if there are more possible retries, which is configured through
* the _retries_ parameter. If the operation does not succeed and there is no retries left, the resulting Future will contain the last failure.
@malzzz
malzzz / CallbackExecutionContext.scala
Created October 31, 2017 14:22 — forked from viktorklang/CallbackExecutionContext.scala
Creates an ExecutionContext inside an Actor that will execute the runnables inside the Actor receive block, so that the risk of closing over Actor internals is less problematic.
//Warning: Uses Akka internal APIs (not binary compatible),
//can be written not to depend on that but implemented like this for brevity.
package akka.util
trait CallbackExecutionContext { this: akka.actor.Actor ⇒
// Defines our signal for callback execution
case object Execute
// ``SerializedSuspendableExecutionContext`` is Akka-internal
private[this] final val ssec: SerializedSuspendableExecutionContext = {