如何使用 Tensorflow 探索数据集并使用 Python 查看 stackoverflow 问题数据集中的示例文件?
keraspythonserver side programmingprogramming
Tensorflow 是 Google 提供的机器学习框架。它是一个与 Python 结合使用的开源框架,用于实现算法、深度学习应用程序等等。它用于研究和生产目的。
可以使用以下代码行在 Windows 上安装 ‘tensorflow’ 包 −
pip install tensorflow
Keras 是作为 ONEIROS(开放式神经电子智能机器人操作系统)项目研究的一部分开发的。Keras 是一个用 Python 编写的深度学习 API。它是一个高级 API,具有高效的接口,可帮助解决机器学习问题。它在 Tensorflow 框架之上运行。它旨在帮助快速进行实验。它提供了开发和封装机器学习解决方案所必需的抽象和构建块。
Keras 已存在于 Tensorflow 包中。可以使用下面的代码行访问它。
import tensorflow from tensorflow import keras
我们使用 Google Colaboratory 运行以下代码。Google Colab 或 Colaboratory 有助于在浏览器上运行 Python 代码,并且不需要任何配置,并且可以免费访问 GPU(图形处理单元)。Colaboratory 是在 Jupyter Notebook 之上构建的。以下是代码片段 −
示例
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())
代码来源 − https://www.tensorflow.org/tutorials/load_data/text
输出
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
解释
目录中的文件已列出。
StackOverflow 数据集中存在的文本数据样本已显示在控制台上。