
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How can Tensorflow be used to export the built model using Python?
Tensorflow is a machine learning framework that is provided by Google. It is an open-source framework used in conjunction with Python to implement algorithms, deep learning applications, and much more. It is used in research and for production purposes.
The ‘tensorflow’ package can be installed on Windows using the below line of code −
pip install tensorflow
Tensor is a data structure used in TensorFlow. It helps connect edges in a flow diagram. This flow diagram is known as the ‘Data flow graph’. Tensors are nothing but a multidimensional array or a list.
We will be using the Illiad’s dataset, which contains text data of three translation works from William Cowper, Edward (Earl of Derby) and Samuel Butler. The model is trained to identify the translator when a single line of text is given. The text files used have been preprocessing. This includes removing the document header and footer, line numbers and chapter titles.
We are using Google Colaboratory to run the below code. Google Colab or Colaboratory helps run Python code over the browser and requires zero configuration and free access to GPUs (Graphical Processing Units). Colaboratory has been built on top of Jupyter Notebook.
Example
Following is the code snippet −
print("The customized pre-processing step") preprocess_layer = TextVectorization( max_tokens=vocab_size, standardize=tf_text.case_fold_utf8, split=tokenizer.tokenize, output_mode='int', output_sequence_length=MAX_SEQUENCE_LENGTH) preprocess_layer.set_vocabulary(vocab) print("The model is being exported") export_model = tf.keras.Sequential( [preprocess_layer, model, layers.Activation('sigmoid')])
Code credit − https://www.tensorflow.org/tutorials/load_data/text
Output
The customized pre-processing step The model is being exported
Explanation
If we want our model to take raw strings as input, we eed to create a ‘textVectorization’ layer which performs the same function as that of preprocessing.
The vocabulary has already been trained, which means we can use the ‘set_vocabulary’ method to train the new vocabulary.
- Related Articles
- How can Tensorflow be used to export the model built using Python?
- How can Tensorflow be used to export the model so that it can be used later?
- How can Tensorflow be used to compile the model using Python?
- How can Tensorflow be used to train the model using Python?
- How can Tensorflow be used to compile the exported model using Python?
- How can Tensorflow and pre-trained model be used to compile the model using Python?
- How can Tensorflow be used with Estimator to compile the model using Python?
- How can Tensorflow be used with Estimators to evaluate the model using Python?
- How can Tensorflow be used to compile and fit the model using Python?
- How can Tensorflow be used to evaluate a CNN model using Python?
- How can Tensorflow be used to create a sequential model using Python?
- How can Tensorflow be used to fit the data to the model using Python?
- How can Tensorflow be used to compare the linear model and the Convolutional model using Python?
- How can Tensorflow and pre-trained model be used to continue training the model using Python?
- How can a sequential model be built on Auto MPG using TensorFlow?
