Package: bigquery-ml-utils
BigQuery ML UtilsBigQuery ML(aka.
BQML) lets you create and execute machine learning models inBigQueryusing standard SQL queries. The BigQuery ML Utils library is an integrated suite
of machine learning tools for building and using BigQuery ML models.InstallationInstall this library in avirtualenvusing pip.virtualenvis a tool to
create isolated Python environments. The basic problem it addresses is one of
dependencies and versions, and indirectly permissions.Withvirtualenv, it's possible to
install this library without needing system install permissions, and without
clashing with the installed system
dependencies.Mac/Linuxpip install virtualenv
    virtualenv <your-env>
    source <your-env>/bin/activate
    <your-env>/bin/pip install bigquery-ml-utilsWindowspip install virtualenv
    virtualenv <your-env>
    <your-env>\Scripts\activate
    <your-env>\Scripts\pip.exe install bigquery-ml-utilsOverviewInferenceTransform PredictorThe Transform Predictor feeds input data into the BQML model trained with
TRANSFORM. It performs both preprocessing and postprocessing on the input and
output. The first argument is aSavedModelwhich represents theTRANSFORM clausefor feature preprocessing. The second argument is aSavedModelorXGBoost Boosterwhich represents
the model logic.XGBoost PredictorThe XGBoost Predictor feeds input data into the BQML XGBoost model. It performs
both preprocessing and postprocessing on the input and output. The first
argument is aXGBoost Boosterwhich
represents the model logic. The following arguments are model assets.Tensorflow OpsBQML Tensorflow Custom Ops provides SQL functions (Date functions,Datetime functions,Time functionsandTimestamp functions)
that are not available in TensorFlow. The implementation and function behavior
align with theBigQuery. This is part of an
effort to bridge the gap between the SQL community and the Tensorflow community.
The following example returns the same result asTIMESTAMP_ADD(timestamp_expression, INTERVAL int64_expression date_part)>>> timestamp = tf.constant(['2008-12-25 15:30:00+00', '2023-11-11 14:30:00+00'], dtype=tf.string)
>>> interval = tf.constant([200, 300], dtype=tf.int64)
>>> result = timestamp_ops.timestamp_add(timestamp, interval, 'MINUTE')
tf.Tensor([b'2008-12-25 18:50:00.0 +0000' b'2023-11-11 19:30:00.0 +0000'], shape=(2,), dtype=string)Note:/usr/share/zoneinfois needed for parsing time zone which might not be
available in your OS. You will need to installtzdatato generate it. For
example, add the following code in your Dockerfile.RUN apt-get update && DEBIAN_FRONTEND="noninteractive" \
    TZ="America/Los_Angeles" apt-get install -y tzdataModel GeneratorText Embedding Model GeneratorThe Text Embedding Model Generator automatically loads a text embedding model
from Tensorflow hub and integrates a signature such that the resulting model can
be immediately integrated within BQML. Currently, the NNLM and BERT embedding
models can be selected.NNLM Text Embedding ModelTheNNLMmodel
has a model size of <150MB and is recommended for phrases, news, tweets,
reviews, etc. NNLM does not carry any default signatures because it is designed
to be utilized as a Keras layer; however, the Text Embedding Model Generator
takes care of this.SWIVEL Text Embedding ModelTheSWIVELmodel
has a model size of <150MB and is recommended for phrases, news, tweets,
reviews, etc. SWIVEL does not require pre-processing because the embedding model
already satisfies BQML imported model requirements. However, in order to align
signatures for NNLM, SWIVEL, and BERT, the Text Embedding Model Generator
establishes the same input label for SWIVEL.BERT Text Embedding ModelThe BERT model has a model size of ~200MB and is recommended for phrases, news,
tweets, reviews, paragraphs, etc. TheBERTmodel does not carry any default signatures
because it is designed to be utilized as a Keras layer. The Text Embedding Model
Generator takes care of this and also integrates atext preprocessing layerfor BERT.