如何使用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://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 處理和緩衝。
廣告