How can Tensorflow be used to explore the dataset and see a sample file from the stackoverflow question dataset 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

Keras was developed as a part of the research for the project ONEIROS (Open-ended Neuro-Electronic Intelligent Robot Operating System). Keras is a deep learning API, which is written in Python. It is a high-level API that has a productive interface that helps solve machine learning problems. It runs on top of the Tensorflow framework. It was built to help experiment in a quick manner. It provides essential abstractions and building blocks that are essential in developing and encapsulating machine learning solutions.

Keras is already present within the Tensorflow package. It can be accessed using the below line of code.

import tensorflow
from tensorflow import keras

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. Following is the code snippet −

Example

print("The files in the directory are listed out")
list(dataset_dir.iterdir())
print("The stackoverflow questions are present in the 'train/' directory")
train_dir = dataset_dir/'train'
list(train_dir.iterdir())
sample_file = train_dir/'python/1755.txt'
print("A sample file is displayed")
with open(sample_file) as f:
   print(f.read())

Code credit − https://www.tensorflow.org/tutorials/load_data/text

Output

The files in the directory are listed out
The stackoverflow questions are present in the 'train/' directory
A sample file is displayed
why does this blank program print true x=true.def stupid():. x=false.stupid().print x

Explanation

  • The files in the directory are listed.

  • A sample of the text data present in the StackOverflow dataset is displayed on the console.

Updated on: 18-Jan-2021

76 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements