如何使用Tensorflow和Python检查模型在Stack Overflow问题数据集上的性能?
Tensorflow 是 Google 提供的一个机器学习框架。它是一个开源框架,与 Python 结合使用,用于实现算法、深度学习应用等等。它被用于研究和生产目的。
可以使用以下代码行在 Windows 上安装“tensorflow”包:
pip install tensorflow
Tensor 是 TensorFlow 中使用的一种数据结构。它有助于在流程图中连接边。这个流程图被称为“数据流图”。Tensor 本质上是多维数组或列表。
我们使用 Google Colaboratory 来运行以下代码。Google Colab 或 Colaboratory 帮助在浏览器上运行 Python 代码,无需任何配置,并可免费访问 GPU(图形处理单元)。Collaboratory 是建立在 Jupyter Notebook 之上的。
示例
以下是代码片段:
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://tensorflowcn.cn/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'
Learn Python in-depth with real-world projects through our Python certification course. Enroll and become a certified expert to boost your career.
解释
当文本预处理代码存在于模型内部时,它有助于将模型导出到生产环境中。
这样,部署就得到了简化。
当在模型外部使用“TextVectorization”时,它有助于执行异步 CPU 处理和缓冲。
广告