Skip to content

Instantly share code, notes, and snippets.


J.J. Allaire jjallaire

View GitHub Profile
jjallaire / multiplicative_lstm.R
Created Oct 26, 2018
Custom Multiplicative LSTM Layer for R Keras
View multiplicative_lstm.R
layer_multiplicative_lstm <-function(
object, units, activation = "tanh", recurrent_activation = "hard_sigmoid", use_bias = TRUE,
return_sequences = FALSE, return_state = FALSE, go_backwards = FALSE, stateful = FALSE, unroll = FALSE,
kernel_initializer = "glorot_uniform", recurrent_initializer = "orthogonal", bias_initializer = "zeros",
unit_forget_bias = TRUE, kernel_regularizer = NULL, recurrent_regularizer = NULL, bias_regularizer = NULL,
from keras.models import Model
from keras import layers
from keras import Input
text_vocabulary_size = 10000
question_vocabulary_size = 10000
answer_vocabulary_size = 500
text_input = Input(shape=(None,), dtype='int32', name='text')
embedded_text = layers.Embedding(
'''Train MNIST with tfrecords yielded from a TF Dataset
In order to run this example you should first run ''
which will download MNIST data and serialize it into 3 tfrecords files
(train.tfrecords, validation.tfrecords, and test.tfrecords).
This example demonstrates the use of TF Datasets wrapped by a generator
function. The example currently only works with a fork of keras that accepts
`workers=0` as an argument to fit_generator, etc. Passing `workers=0` results
in the generator function being run on the main thread (without this various
jjallaire / reveal.Rmd
Created Mar 24, 2016
reveal.js with custom css
View reveal.Rmd
title: "Untitled"
css: styles.css
## R Markdown
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF,
jjallaire / reveal-dygraph.Rmd
Created Jan 20, 2016
dygraphs with reveal.js
View reveal-dygraph.Rmd
title: "Untitled"
output: revealjs::revealjs_presentation
## R Markdown
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
View gist:008622dabd5730cf74cf
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
CharacterVector asUTF8(CharacterVector x) {
const void *vmax = vmaxget();
CharacterVector xUTF8(x.length());
for (int i = 0; i<x.length(); i++) {
const char* utf8 = Rf_translateCharUTF8(x[i]);
xUTF8[i] = Rf_mkCharCE(utf8, CE_UTF8);
View gist:bfc84ce7dd566a0a7231
#include <Rcpp.h>
using namespace Rcpp;
void finalizeInt(int* ptr) {
// do nothing
typedef XPtr<int,PreserveStorage,finalizeInt> XPtrInt;
// [[Rcpp::export]]
jjallaire / gist:ded5279b9c552ece9917
Created Feb 4, 2015
boost function and boost bind
View gist:ded5279b9c552ece9917
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::depends(BH)]]
#include <boost/bind.hpp>
#include <boost/function.hpp>
typedef boost::function<int(int,int)> Combiner;
int add(int x, int y) {
jjallaire / uniform.cpp
Created Dec 28, 2014
Rcpp modules with sourceCpp
View uniform.cpp
#include <Rcpp.h>
using namespace Rcpp;
using namespace Rcpp;
class Uniform {
Uniform(double min_, double max_) : min(min_), max(max_) {}
NumericVector draw(int n) const {
RNGScope scope;
return runif( n, min, max );
jjallaire / dygraphs.Rmd
Created Oct 28, 2014
htmlwidgets and runtime: shiny
View dygraphs.Rmd
title: "Dygraphs in R Markdown"
output: html_document
runtime: shiny
hw <- HoltWinters(ldeaths)