如何使用Tensorflow使用Python查看矢量化数据的样本?
Tensorflow是Google提供的一种机器学习框架。它是一个开放源代码框架,可与Python结合使用,以实现算法,深度学习应用程序等等。它用于研究和生产目的。
可以使用下面的代码行在Windows上安装'tensorflow'软件包-
pip install tensorflow
Tensor是TensorFlow中使用的数据结构。它有助于连接流程图中的边缘。该流程图称为“数据流程图”。张量不过是多维数组或列表。
我们将使用Illiad的数据集,其中包含来自WilliamCowper,Edward(德比伯爵)和SamuelButler的三本翻译作品的文本数据。当给出单行文本时,训练模型以识别翻译器。使用的文本文件已经过预处理。这包括删除文档的页眉和页脚,行号和章节标题。
我们正在使用Google合作实验室来运行以下代码。GoogleColab或Colaboratory可以帮助通过浏览器运行Python代码,并且需要零配置和对GPU(图形处理单元)的免费访问。合作已建立在JupyterNotebook的基础上。
示例
print("Look at sample data after processing it") example_text, example_label = next(iter(all_labeled_data)) print("句子是: ", example_text.numpy()) vectorized_text, example_label = preprocess_text(example_text, example_label) print("向量化的句子是: ", vectorized_text.numpy()) print("Run the pre-process function on the data") all_encoded_data = all_labeled_data.map(preprocess_text)
代码信用-https://www.tensorflow.org/tutorials/load_data/text
输出结果
Look at sample data after processing it 句子是: b'But I have now both tasted food, and given' 向量化的句子是: [ 20 21 58 49 107 3497 909 2 4 540] Run the pre-process function on the data
解释
数据矢量化后,所有令牌都将转换为整数。
它们被转换为整数,以便模型可以解释输入给它的输入。