Skip to content

Instantly share code, notes, and snippets.

View stefanondisponibile's full-sized avatar
👾
I'm game!

Stefano stefanondisponibile

👾
I'm game!
View GitHub Profile
@stefanondisponibile
stefanondisponibile / tf2_TextVectorizationLayer_standardize.py
Last active January 20, 2020 16:28
TensorFlow TextVectorizationLayer.
# No standardization.
vectorize_layer = TextVectorization(output_mode="int", max_tokens=5, standardize=None)
# Lowercase text and strip punctuation. [DEFAULT]
vectorize_layer = TextVectorization(output_mode="int", max_tokens=5, standardize="lower_and_strip_punctuation")
# Apply a custom standardization function.
def replace_foo_with_bar(input_data):
return tf.strings.regex_replace(input_data, "foo", "bar")
vectorize_layer = TextVectorization(output_mode="int", max_tokens=5, standardize=replace_foo_with_bar)
@stefanondisponibile
stefanondisponibile / build.sh
Created October 29, 2019 20:14
Build TensorFlow Serving with Sentencepiece custom ops.
#!/bin/bash
CWD=$(pwd)
GPROTOBUF_URL=https://github.com/protocolbuffers/protobuf/releases/download/v3.7.0/protobuf-cpp-3.7.0.tar.gz
compile_gprotobuf () {
sudo apt-get install autoconf automake libtool curl make g++ unzip &&
wget $GPROTOBUF_URL &&
fname=protobuf-cpp-3.7.0.tar.gz &&
tar xvzf $fname && rm $fname &&
@stefanondisponibile
stefanondisponibile / zscore_drop_outliers.py
Created February 19, 2019 16:57
Drops outliers from a dataframe with zscore
import pandas as pd
from scipy import stats
# df = .....
df = df[(np.abs(stats.zscore(df[feature_cols])) < 3).all(axis=1)]