

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can the preprocessed data be shuffled using Tensorflow and Python?
<p>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.</p><p>The ‘tensorflow’ package can be installed on Windows using the below line of code −</p><pre class="prettyprint notranslate">pip install tensorflow</pre><p>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.</p><p>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.</p><p>We are using the 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.</p><h2>Example</h2><p>Following is the code snippet −</p><pre class="prettyprint notranslate">print("Combine the labelled dataset and reshuffle it") BUFFER_SIZE = 50000 BATCH_SIZE = 64 VALIDATION_SIZE = 5000 all_labeled_data = labeled_data_sets[0] for labeled_dataset in labeled_data_sets[1:]: all_labeled_data = all_labeled_data.concatenate(labeled_dataset) all_labeled_data = all_labeled_data.shuffle( BUFFER_SIZE, reshuffle_each_iteration=False) print("Displaying a few samples of input data") for text, label in all_labeled_data.take(8): print("The sentence is : ", text.numpy()) print("The label is :", label.numpy())</pre><p>Code credit − <a href="https://www.tensorflow.org/tutorials/load_data/text" rel="nofollow" target="_blank">https://www.tensorflow.org/tutorials/load_data/text</a></p><h2>Output</h2><pre class="result notranslate">Combine the labelled dataset and reshuffle it Displaying a few samples of input data The sentence is : b'But I have now both tasted food, and given' The label is : 0 The sentence is : b'All these shall now be thine: but if the Gods' The label is : 1 The sentence is : b'Their spiry summits waved. There, unperceived' The label is : 0 The sentence is : b'"I pray you, would you show your love, dear friends,' The label is : 1 The sentence is : b'Entering beneath the clavicle the point' The label is : 0 The sentence is : b'But grief, his father lost, awaits him now,' The label is : 1 The sentence is : b'in the fore-arm where the sinews of the elbow are united, whereon he' The label is : 2 The sentence is : b'For, as I think, I have already chased' The label is : 0</pre><h2>Explanation</h2><ul class="list"><li><p>After preprocessing the data, a few samples from the dataset are displayed on the console.</p></li><li><p>The data is not grouped, which means every entry in the ‘all_labeled_data’ maps to one data point.</p></li></ul>
- Related Questions & Answers
- How can Tensorflow be used to visualize the data using Python?
- How can Tensorflow be used to standardize the data using Python?
- How can Tensorflow and pre-trained model be used to visualize the data using Python?
- How can Tensorflow be used to fit the data to the model using Python?
- How can Tensorflow and Tensorflow text be used to tokenize string data?
- How can Tensorflow be used to iterate through the dataset and display sample data using Python?
- How can Tensorflow be used to compile and fit the model using Python?
- How can Tensorflow be used to evaluate both the models on test data using Python?
- How can Tensorflow be used to view a sample of the vectorised data using Python?
- How can Tensorflow and pre-trained model be used for evaluation and prediction of data using Python?
- 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 decode the predictions using Python?
- How can Tensorflow be used to check the predicrion using Python?
- How can Tensorflow be used to check the predictions using Python?
Advertisements