如何使用Python使用Tensorflow检查模型在stackoverflow的问题数据集上的表现?
Tensorflow是由Google提供的机器学习框架。它是一个开源框架,可配合Python来实现算法、深度学习应用等。它用于研究和生产目的。
可以使用以下代码在Windows上安装“tensorflow”包:
pip install tensorflow
张量是TensorFlow中使用的数据结构。它有助于连接流程图中的边缘。这个流程图称为“数据流图”。张量只是一个多维数组或列表。
我们将使用Google Colaboratory来运行下面的代码。Google Colab或Colaboratory可以在浏览器上运行Python代码,不需要任何配置,并且可以免费访问GPU(图形处理单元)。Collaboratory是基于Jupyter Notebook构建的。
更多Python相关文章,请阅读:Python 教程
示例
以下是代码片段:
print("Testing the model with new data")
inputs = [
"how do I extract keys from a dict into a list?",
"debug public static void main(string[] args) {...}",
]
print("Predicting the scores ")
predicted_scores = export_model.predict(inputs)
print("Predicting the labels")
predicted_labels = get_string_labels(predicted_scores)
for input, label in zip(inputs, predicted_labels):
print("Question is: ", input)
print("The predicted label is : ", label.numpy())
代码来源-https://www.tensorflow.org/tutorials/load_data/text
输出
Testing the model with new data
Predicting the scores
Predicting the labels
Question is: how do I extract keys from a dict into a list?
The predicted label is : b'python'
Question is: debug public static void main(string[] args) {...}
The predicted label is : b'java'
解释
- 当文本预处理代码存在于模型中时,它有助于将模型导出到生产环境。
- 这样,部署就简化了。
- 当“TextVectorization”在模型外使用时,它有助于执行异步CPU处理和缓冲。