Skip to content

Instantly share code, notes, and snippets.

View cerisara's full-sized avatar

Christophe Cerisara cerisara

  • LORIA - CNRS
  • Nancy, France
View GitHub Profile
@cerisara
cerisara / DA reco
Created March 8, 2016 13:47
Dialogue act recognition Keras model
import numpy as np
from keras.preprocessing import sequence
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten, TimeDistributedDense
from keras.layers.recurrent import LSTM
from keras.layers.embeddings import Embedding
from keras.utils import np_utils
from keras.preprocessing.text import Tokenizer
from keras.models import Graph
complete_sentences = [["*-START-*"] for a in range(1000)]
sents = np.zeros((nb_samples, timesteps+1, len(vocab)))
for x in range(nb_samples):
sents[i,0,word2index["*-START-*"]] = 1. # init the sequences
for t in range(timesteps):
preds = self.model.predict(sents[:,0:t+1], verbose=0)
# get the maximum predictions for this timestep for each sample
next_word_indices = np.argmax(preds[:,t], axis=1)
import numpy as np
import matplotlib.pyplot as plt
from keras.models import Sequential
from keras.layers.core import Dense, Activation
from keras.optimizers import SGD
from sklearn.metrics import mean_squared_error
tau=2*np.pi
@cerisara
cerisara / lstm_keras.py
Last active June 15, 2018 17:43
LSTM training multiclass with Keras
# X_train contains word indices (single int between 0 and max_words)
# Y_train0 contains class indices (single int between 0 and nb_classes)
X_train = sequence.pad_sequences(X_train, maxlen=maxlen, padding='post')
X_test = sequence.pad_sequences(X_test, maxlen=maxlen, padding='post')
Y_train = np.zeros((batchSize,globvars.nb_classes))#,dtype=np.float32)
for t in range(batchSize):
Y_train[t][Y_train0[t]]=1
Y_test = np.zeros((len(Y_test0),globvars.nb_classes))#,dtype=np.float32)
@cerisara
cerisara / IterativeReduceFlatMap.java
Last active September 4, 2015 07:48
Alternative flattening/deflattening of parameters in DL4J / Spark
/**
* Iterative reduce with
* flat map using map partitions
*
* @author Adam Gibson
modified by Christophe Cerisara
*/
public class IterativeReduceFlatMap implements FlatMapFunction<Iterator<DataSet>, INDArray> {