如何使用Python和TensorFlow创建基于伊利亚特数据集的原始字符串数据集?
TensorFlow是Google提供的机器学习框架。它是一个开源框架,与Python结合使用,可以实现算法、深度学习应用程序等等。它用于研究和生产目的。
可以使用以下代码行在Windows上安装“tensorflow”包:
pip install tensorflow
张量是TensorFlow中使用的数据结构。它有助于连接数据流图中的边。这个数据流图被称为“数据流图”。张量只不过是多维数组或列表。
我们将使用伊利亚特数据集,其中包含威廉·考珀、爱德华(德比伯爵)和塞缪尔·巴特勒三位翻译作品的文本数据。该模型在给出一行文本时被训练来识别翻译者。所使用的文本文件已经过预处理。这包括删除文档页眉和页脚、行号和章节标题。
我们使用Google Colaboratory运行以下代码。Google Colab或Colaboratory帮助在浏览器上运行Python代码,无需任何配置,并且可以免费访问GPU(图形处理单元)。Colaboratory构建在Jupyter Notebook之上。
示例
以下是代码片段:
print("Creating a test dataset that consists of raw strings")
test_ds = all_labeled_data.take(VALIDATION_SIZE).batch(BATCH_SIZE)
test_ds = configure_dataset(test_ds)
loss, accuracy = export_model.evaluate(test_ds)
print("The loss is : ", loss)
print("The accuracy is: {:2.2%}".format(accuracy))代码来源:https://tensorflowcn.cn/tutorials/load_data/text
输出
Creating a test dataset that consists of raw strings 79/79 [==============================] - 7s 10ms/step - loss: 0.5230 - accuracy: 0.7909 The loss is : 0.5458346605300903 The accuracy is: 78.16%
解释
构建一个测试数据集,其中数据被分组到一定的批次大小。
使用“evaluate”方法评估此数据。
训练数据相关的损失和准确率显示在控制台上。
广告
数据结构
网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP