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
const trainSave = async (model, querySnapshot) => { | |
if (!querySnapshot.docs.length) return false; | |
const xs_data = querySnapshot.docs.map(doc => fitData(doc.data().text)); | |
const ys_data = querySnapshot.docs.map( | |
doc => (doc.data().y === "positive" ? [1] : [0]) | |
); | |
const xs = tf.tensor2d(xs_data); | |
const ys = tf.tensor2d(ys_data); |
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
// TFjs and gcs are using a lot of memory, so increasing it will speed up the functions | |
exports.train = functions | |
.runWith({ memory: "2GB" }) | |
.https.onRequest(async (request, response) => { | |
const existJSON = await bucket.file("model.json").exists().then(ex => ex[0]); | |
const existBIN = await bucket.file("weights.bin").exists().then(ex => ex[0]); | |
if (!existJSON || !existBIN) { | |
const model = tf.sequential(); | |
model.add(tf.layers.dense({ units: 2, inputShape: [vocabulary.length] })); |
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
-keep class com.google.unity.** { | |
*; | |
} | |
-keep public class com.google.android.gms.ads.**{ | |
public *; | |
} | |
-keep public class com.google.ads.**{ | |
public *; | |
} | |
-keepattributes *Annotation* |
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
JSON.safeStringify = (obj, indent = 2) => { | |
let cache = []; | |
const retVal = JSON.stringify( | |
obj, | |
(key, value) => | |
typeof value === "object" && value !== null | |
? cache.includes(value) | |
? undefined // Duplicate reference found, discard key | |
: cache.push(value) && value // Store value in our collection | |
: value, |
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
temperature = 10 | |
dist = tfp.distributions.RelaxedOneHotCategorical(temperature, probs=p) | |
dist.sample() | |
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([0.31916314, 0.34642866, 0.33440822], dtype=float32)> |
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
temperature = 0.01 | |
dist = tfp.distributions.RelaxedOneHotCategorical(temperature, probs=p) | |
dist.sample() | |
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([0., 1., 0.], dtype=float32)> |
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
tf.one_hot(tf.argmax(p), depth = len(p)) | |
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([0., 1., 0.], dtype=float32)> |
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
self.normalize1 = layers.LayerNormalization(epsilon=1e-6) | |
self.normalize2 = layers.LayerNormalization(epsilon=1e-6) | |
self.channel_projection1 = keras.Sequential( | |
[ | |
layers.Dense(units=embedding_dim * 2), | |
layers.ReLU(), | |
layers.Dropout(rate=dropout_rate), | |
] | |
) |
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
import tensorflow as tf | |
from tensorflow import keras | |
from tensorflow.keras import layers | |
class gMLPLayer(layers.Layer): | |
def __init__(self, num_patches, embedding_dim, dropout_rate, *args, **kwargs): | |
super(gMLPLayer, self).__init__(*args, **kwargs) |
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 spatial_gating_unit(self, x): | |
# u and v shape: [batch_size, num_patchs, embedding_dim] | |
u, v = tf.split(x, num_or_size_splits=2, axis=2) | |
v = self.normalize2(v) |