如何使用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://www.tensorflow.org/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”方法評估此資料。

  • 訓練資料相關的損失和準確率顯示在控制檯上。

更新於:2021年1月19日

97 次瀏覽

啟動你的職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.