แนะนำ YAML

CI/CD สำหรับ Machine Learning

Ravi Bhadauria

Machine Learning Engineer

YAML คืออะไร?

  • YAML: YAML Ain't Markup Language
  • ใช้ในไฟล์คอนฟิก, การแลกเปลี่ยนข้อมูล และการจัดโครงสร้างข้อมูล
  • ภาษาจัดรูปแบบข้อมูล คล้ายกับ JSON และ XML
  • ช่วยให้ถ่ายโอนข้อมูลระหว่างภาษาหรือแอปพลิเคชันได้ในรูปแบบมาตรฐาน
  • รูปแบบเรียบง่ายและอ่านง่าย
  • นามสกุลไฟล์ที่ใช้ได้: .yaml หรือ .yml
  • ใช้เขียนคอนฟิกสำหรับเครื่องมือ CI/CD ต่าง ๆ:
    • GitHub Actions
    • Data Version Control (DVC)
CI/CD สำหรับ Machine Learning

ไวยากรณ์ YAML

  • YAML มีโครงสร้างแบบลำดับชั้น
    • การย่อหน้ามีความหมาย
  • ห้ามใช้ Tab
  • ตัวตรวจสอบ YAML (https://www.yamllint.com/)
  • คอมเมนต์เริ่มต้นด้วย #
name: Ravi
occupation: Instructor
# This is a valid comment
programming_languages: # and this one too
  python: Advanced
  go: Intermediate
  scala: Beginner
CI/CD สำหรับ Machine Learning

Scalar ใน YAML

  • ตัวเลข: จำนวนเต็มหรือทศนิยม
  • บูลีน: true หรือ false
  • Null: คีย์เวิร์ด null หรือ ~
  • สตริง: ข้อความธรรมดา หรือครอบด้วย '' หรือ ""
# Integer
42
# Floating point
3.14
# Boolean
true
# Null values
null
# String value
a: "A string in YAML"
b: 'A string in YAML'
c: A string in YAML
CI/CD สำหรับ Machine Learning

Collection ใน YAML

Sequences

  • เรียกอีกชื่อว่า list, array หรือ vector
  • เขียนได้ 2 รูปแบบ:

    • Block style

      - first
      - second
      - third
      
    • Flow style

      [first, second, third]
      

Mappings

  • เรียกอีกชื่อว่า dictionary, key-value pairs, hash หรือ object
  • คีย์ต้องไม่ซ้ำ ค่าเป็นข้อมูลประเภทใดก็ได้
  • คีย์และค่าคั่นด้วย :
key1: value1
blocklist:
  - first
  - second
flowlist: [1.2, 2, "fifty", true]
CI/CD สำหรับ Machine Learning

สรุป

  • YAML คือภาษาจัดรูปแบบข้อมูล
  • มีประโยชน์ในการเขียนคอนฟิก CI/CD
  • การย่อหน้ามีความสำคัญมาก
    • ห้ามใช้ Tab
  • Mapping, Sequence และ Scalar คือองค์ประกอบพื้นฐานของ YAML

กราฟแสดงโครงสร้างข้อมูล YAML แบบลำดับชั้น

CI/CD สำหรับ Machine Learning

รูปแบบ Editor Exercise

ภาพอธิบายหน้าตาของ Editor Exercise แสดงส่วนโฟลเดอร์ ไฟล์ และเทอร์มินัล

CI/CD สำหรับ Machine Learning

มาฝึกกันเถอะ!

CI/CD สำหรับ Machine Learning

Preparing Video For Download...