如何使用Python和Illiad数据集检查测试数据的性能表现?
Tensorflow是由Google提供的机器学习框架。它是一个开源框架,与Python一起使用来实现算法、深度学习等等。它被用于研究和生产目的。它具有优化技术,可以快速执行复杂的数学运算。这是因为它使用NumPy和多维数组。这些多维数组也被称为“张量”。
该框架支持使用深度神经网络。它高度可扩展,并带有许多热门数据集。它使用GPU计算并自动管理资源。它带有众多机器学习库,并且有很好的支持和文档。该框架具有运行深度神经网络模型、训练它们并创建能够预测相应数据集相关特征的应用程序的功能。
Tensor是TensorFlow中使用的数据结构。它帮助将流程图中的边缘连接起来。这个流程图被称为“数据流图”。张量不过就是一个多维数组或列表。
我们将使用Illiad数据集,其中包含来自William Cowper、Edward(Earl of Derby)和Samuel Butler的三个翻译作品的文本数据。当给出一行文本时,该模型将对转译者进行识别。使用的文本文件已进行预处理。包括删除文档头和页脚、行号和章节标题。
我们使用Google Colaboratory来运行以下代码。Google Colab或Colaboratory帮助在浏览器上运行Python代码,需要零配置并免费访问GPU(图形处理单元)。Colaboratory构建在Jupyter Notebook上。
更多Python相关文章,请阅读:Python 教程
示例
以下是代码片段 −
print("Testing the model on new data")
inputs = [
"the allies, and his armour flashed about him so that he seemed to all",
"And with loud clangor of his arms he fell.",
"Join'd to th' Ionians with their flowing robes,",
]
print("The predict method is being called")
predicted_scores = export_model.predict(inputs)
predicted_labels = tf.argmax(predicted_scores, axis=1)
for input, label in zip(inputs, predicted_labels):
print("The question is : ", input)
print("The predicted label is : ", label.numpy())
代码来自 – https://www.tensorflow.org/tutorials/load_data/text
输出
Testing the model on new data
The predict method is being called
The question is : the allies, and his armour flashed about him so that he seemed to all
The predicted label is : 2
The question is : And with loud clangor of his arms he fell.
The predicted label is : 0
The question is : Join'd to th' Ionians with their flowing robes,
The predicted label is : 1
说明
-
一旦数据已经编译并拟合了训练数据,它就会在以前未见过的数据上进行测试。
-
在测试数据上调用“predict”方法。
-
显示一些预测标签的示例,以及其相应的问题。