
- 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 with Illiad dataset to check how well the test data performs 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. It has optimization techniques that help in performing complicated mathematical operations quickly. This is because it uses NumPy and multi-dimensional arrays. These multi-dimensional arrays are also known as ‘tensors’.
The framework supports working with a deep neural network. It is highly scalable, and comes with many popular datasets. It uses GPU computation and automates the management of resources. It comes with a multitude of machine learning libraries and is well-supported and documented. The framework has the ability to run deep neural network models, train them, and create applications that predict relevant characteristics of the respective datasets.
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("Testing the model on new data") inputs = [ "the allies, and his armour flashed about him so that he seemed to all", "And with loud clangor of his arms he fell.", "Join'd to th' Ionians with their flowing robes,", ] print("The predict method is being called") predicted_scores = export_model.predict(inputs) predicted_labels = tf.argmax(predicted_scores, axis=1) for input, label in zip(inputs, predicted_labels): print("The question is : ", input) print("The predicted label is : ", label.numpy())
Code credit − https://www.tensorflow.org/tutorials/load_data/text
Output
Testing the model on new data The predict method is being called The question is : the allies, and his armour flashed about him so that he seemed to all The predicted label is : 2 The question is : And with loud clangor of his arms he fell. The predicted label is : 0 The question is : Join'd to th' Ionians with their flowing robes, The predicted label is : 1
Explanation
Once the data has been compiled, and fit the training data, it is tested on never-before seen data.
The ‘predict’ method is called on the test data.
Some samples of the predicted label are displayed along with its corresponding question.
- Related Articles
- How can Tensorflow be used to check how well the model performs on stackoverflow question dataset using Python?
- How can Tensorflow be used to load the Illiad dataset using Python?
- How can Tensorflow be used to train the Illiad dataset using Python?
- How can Tensorflow be used to split the Illiad dataset into training and test data in Python?
- How can Tensorflow be used to download and explore the Illiad dataset using Python?
- How can Tensorflow be used to create a dataset of raw strings from the Illiad dataset using Python?
- How can Tensorflow be used to build vocabulary from tokenized words for Illiad dataset using Python?
- How can Tensorflow be used to convert the tokenized words from Illiad dataset into integers using Python?
- How can Tensorflow be used to vectorise the text data associated with stackoverflow question dataset using Python?
- How can Tensorflow be used to prepare the dataset with stackoverflow questions using Python?
- How can Tensorflow be used with Estimators to inspect the titanic dataset using Python?
- How can Tensorflow be used to visualize the flower dataset using Python?
- How can Tensorflow be used to iterate through the dataset and display sample data using Python?
- How can Tensorflow be used to evaluate both the models on test data using Python?
- How can Tensorflow be used to configure the stackoverflow question dataset using Python?
