Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีใช้ TensorFlow ดาวน์โหลดและสำรวจชุดข้อมูล Iliad ด้วย Python


TensorFlow เฟรมเวิร์ก ML จาก Google Open Source ใช้กับ Python อัลกอริทึม Deep Learning งานวิจัยและ Production

ติดตั้ง tensorflow บน Windows:

pip install tensorflow

Tensor โครงสร้างข้อมูลใน TensorFlow (Data Flow Graph) เป็นอาร์เรย์หลายมิติ/ลิสต์ มี 3 แอตทริบิวต์: Rank, Type, Shape

ใช้ชุดข้อมูล Iliad (ข้อความแปล 3 ชิ้น) โมเดลระบุผู้แปลจากบรรทัดเดี่ยว ข้อมูล Preprocessed แล้ว ใช้ Google Colab รันโค้ด (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()))

Credit: TensorFlow Tutorials

ผลลัพธ์

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 ใช้โหลด Example จากไฟล์ข้อความ

  • tf.text ใช้ Preprocess ข้อมูล

  • ขั้นแรก ดาวน์โหลดและสำรวจ Dataset