如何使用 Python 和 TensorFlow 查看矢量化数据的样本?
TensorFlow 是 Google 提供的一个机器学习框架。它是一个开源框架,与 Python 结合使用,可以实现算法、深度学习应用程序等等。它用于研究和生产目的。
可以使用以下代码行在 Windows 上安装“tensorflow”包:
pip install tensorflow
张量 (Tensor) 是 TensorFlow 中使用的一种数据结构。它有助于连接数据流图中的边。这个数据流图被称为“数据流图”。张量只不过是多维数组或列表。
我们将使用伊利亚特的数据集,其中包含威廉·考珀、爱德华(德比伯爵)和塞缪尔·巴特勒三位翻译作品的文本数据。该模型在给定单行文本时,被训练以识别翻译者。所使用的文本文件已进行预处理。这包括删除文档页眉和页脚、行号和章节标题。
我们正在使用 Google Colaboratory 来运行以下代码。Google Colab 或 Colaboratory 帮助在浏览器上运行 Python 代码,无需任何配置,并可免费访问 GPU(图形处理单元)。Colaboratory 建立在 Jupyter Notebook 之上。
示例
print("Look at sample data after processing it")
example_text, example_label = next(iter(all_labeled_data))
print("The sentence is : ", example_text.numpy())
vectorized_text, example_label = preprocess_text(example_text, example_label)
print("The vectorized sentence is : ", vectorized_text.numpy())
print("Run the pre-process function on the data")
all_encoded_data = all_labeled_data.map(preprocess_text)代码来源 − https://tensorflowcn.cn/tutorials/load_data/text
输出
Look at sample data after processing it The sentence is : b'But I have now both tasted food, and given' The vectorized sentence is : [ 20 21 58 49 107 3497 909 2 4 540] Run the pre-process function on the data
解释
数据向量化后,所有标记都将转换为整数。
将它们转换为整数,以便模型可以解释输入。
广告
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP