如何使用Python和TensorFlow下載並探索伊利亞特資料集?
TensorFlow是由Google提供的機器學習框架。它是一個開源框架,與Python結合使用以實現演算法、深度學習應用程式等等。它用於研究和生產目的。
可以使用以下程式碼行在Windows上安裝“tensorflow”包:
pip install tensorflow
張量是TensorFlow中使用的資料結構。它有助於連線資料流圖中的邊。這個資料流圖被稱為“資料流圖”。張量只不過是多維陣列或列表。
它們可以使用三個主要屬性來標識:
**秩** - 它表示張量的維度。可以理解為張量的階數或已定義張量的維度數。
**型別** - 它表示與張量元素關聯的資料型別。它可以是一維、二維或n維張量。
**形狀** - 它是行數和列數的總和。
我們將使用伊利亞特資料集,其中包含威廉·考珀、愛德華(德比伯爵)和塞繆爾·巴特勒的三部譯文的文字資料。該模型經過訓練,可以根據給定的單行文字識別翻譯者。使用的文字檔案已經過預處理。這包括刪除文件頁首和頁尾、行號和章節標題。
我們使用Google Colaboratory執行以下程式碼。Google Colab或Colaboratory有助於透過瀏覽器執行Python程式碼,無需任何配置,並可免費訪問GPU(圖形處理單元)。協作工具構建在Jupyter Notebook之上。以下是程式碼片段:
示例
print("Loading the Illiad dataset")
DIRECTORY_URL = 'https://storage.googleapis.com/download.tensorflow.org/data/illiad/'
FILE_NAMES = ['cowper.txt', 'derby.txt', 'butler.txt']
print("Iterating through the name of the files")
for name in FILE_NAMES:
text_dir = utils.get_file(name, origin=DIRECTORY_URL + name)
parent_dir = pathlib.Path(text_dir).parent
print("The list of files in the directory")
print(list(parent_dir.iterdir()))程式碼來源 - https://www.tensorflow.org/tutorials/load_data/text
輸出
Loading the Illiad dataset
Iterating through the name of the files
Downloading data from
https://storage.googleapis.com/download.tensorflow.org/data/illiad/cowper.txt
819200/815980 [==============================] - 0s 0us/step
Downloading data from
https://storage.googleapis.com/download.tensorflow.org/data/illiad/derby.txt
811008/809730 [==============================] - 0s 0us/step
Downloading data from
https://storage.googleapis.com/download.tensorflow.org/data/illiad/butler.txt
811008/807992 [==============================] - 0s 0us/step
The list of files in the directory
[PosixPath('/root/.keras/datasets/derby.txt'), PosixPath('/root/.keras/datasets/cowper.txt'),
PosixPath('/root/.keras/datasets/butler.txt')]
[ ]解釋
“tf.data.TextLineDataset”用於從文字檔案載入示例。
“tf.text”用於預處理資料。
首先,下載並探索資料集。
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP