This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
training_phrases = { | |
'when_is_open' : ' '.join([ | |
'when is the restaurant open?', | |
'when to start open?' | |
]), | |
'where_is_the_restaurant' : ' '.join([ | |
'where is the restaurant', | |
'what is the location of the restaurant?', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
optimizer = tf.train.AdamOptimizer(learning_rate) | |
with tf.name_scope("phase1"): | |
phase1_outputs = tf.matmul(hidden1, weights4) + biases4 # bypass hidden2 and hidden3 | |
phase1_reconstruction_loss = tf.reduce_mean(tf.square(phase1_outputs - X)) | |
phase1_reg_loss = regularizer(weights1) + regularizer(weights4) | |
phase1_loss = phase1_reconstruction_loss + phase1_reg_loss | |
phase1_training_op = optimizer.minimize(phase1_loss) | |
with tf.name_scope("phase2"): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# image input | |
n_inputs = 28*28 | |
# merged to one stacked AE | |
X = tf.placeholder(tf.float32, shape=[None, n_inputs]) | |
hidden1 = tf.nn.elu(tf.matmul(X, W1) + b1) | |
hidden2 = tf.nn.elu(tf.matmul(hidden1, W2) + b2) | |
hidden3 = tf.nn.elu(tf.matmul(hidden2, W3) + b3) | |
outputs = tf.matmul(hidden3, W4) + b4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first phase of AE, trained on the training data | |
hidden_output, W1, b1, W4, b4 = train_autoencoder(mnist.train.images, n_neurons=300, n_epochs=4, batch_size=150, | |
# second phase of AE, trained on the previous Autoencoder's hidden layer output | |
_, W2, b2, W3, b3 = train_autoencoder(hidden_output, n_neurons=150, n_epochs=4, batch_size=150) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def train_autoencoder(X_train, n_neurons, n_epochs, batch_size, | |
learning_rate = 0.01, l2_reg = 0.0005, seed=42, | |
hidden_activation=tf.nn.elu, | |
output_activation=tf.nn.elu): | |
graph = tf.Graph() | |
with graph.as_default(): | |
tf.set_random_seed(seed) | |
n_inputs = X_train.shape[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
X = tf.placeholder(tf.float32, shape=[None, n_inputs]) | |
weights1_init = initializer([n_inputs, n_hidden1]) | |
weights2_init = initializer([n_hidden1, n_hidden2]) | |
weights1 = tf.Variable(weights1_init, dtype=tf.float32, name="weights1") | |
weights2 = tf.Variable(weights2_init, dtype=tf.float32, name="weights2") | |
weights3 = tf.transpose(weights2, name="weights3") # tied weights | |
weights4 = tf.transpose(weights1, name="weights4") # tied weights |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports = async function (payload) { | |
const mongodb = context.services.get("mongodb-atlas"); | |
const exampledb = mongodb.db("exampledb"); | |
const examplecoll = exampledb.collection("examplecoll"); | |
const args = payload.query.text.split(" "); | |
switch (args[0]) { | |
case "stash": | |
const result = await examplecoll.insertOne({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun trySignIn() { | |
Log.d(TAG, "Signing in with tocken" + tocken) | |
val credential = GoogleAuthProvider.getCredential(token, null) | |
FirebaseAuth.getInstance().signInWithCredential(credential) | |
.addOnSuccessListener(this, { result -> | |
val user = result.user | |
Log.d(TAG, "signInWithCredential ${user.displayName} ${user.email}") | |
finish() | |
}) | |
.addOnFailureListener(this, { e -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) { | |
super.onActivityResult(requestCode, resultCode, data) | |
if (requestCode == RC_SIGN_IN) { | |
val response = IdpResponse.fromResultIntent(data) | |
if (resultCode == Activity.RESULT_OK) { | |
// handle login | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
findViewById<Button>(R.id.btn_sign_in).setOnClickListener { | |
startActivityForResult( | |
AuthUI.getInstance() | |
.createSignInIntentBuilder() | |
.setAvailableProviders(listOf(AuthUI.IdpConfig.GoogleBuilder().build())) | |
.build(), | |
RC_SIGN_IN | |
) | |
} |
NewerOlder