YAML 入門

Machine Learning 的 CI/CD

Ravi Bhadauria

Machine Learning Engineer

什麼是 YAML?

  • YAML:YAML Ain't Markup Language(遞迴縮寫)
  • 用於設定檔、資料交換與結構化資料表達
  • 類似 JSON、XML 的資料格式語言
  • 提供標準格式,方便在語言或應用間傳遞資料
  • 格式簡潔清楚
  • 合法副檔名:.yaml.yml
  • 常用於撰寫各式 CI/CD 工具的設定:
    • GitHub Actions
    • Data Version Control (DVC)
Machine Learning 的 CI/CD

YAML 語法

name: Ravi
occupation: Instructor
# This is a valid comment
programming_languages: # and this one too
  python: Advanced
  go: Intermediate
  scala: Beginner
Machine Learning 的 CI/CD

YAML 標量(Scalars)

  • 數字:整數或浮點數
  • 布林:truefalse
  • 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
Machine Learning 的 CI/CD

YAML 集合(Collections)

序列(Sequences)

  • 亦稱清單、陣列或向量
  • 有兩種寫法:

    • 區塊風格

      - first
      - second
      - third
      
    • 流水風格

      [first, second, third]
      

對映(Mappings)

  • 亦稱字典、鍵值對、雜湊或物件
  • 鍵需唯一,值可為任意有效資料
  • 鍵與值以 : 分隔
key1: value1
blocklist:
  - first
  - second
flowlist: [1.2, 2, "fifty", true]
Machine Learning 的 CI/CD

重點整理

  • YAML 是資料格式語言
  • 很適合撰寫 CI/CD 設定
  • 縮排非常重要
    • 不允許使用 Tab
  • 對映、序列與標量是 YAML 的基礎組件

YAML 資料結構的階層式圖示。

Machine Learning 的 CI/CD

編輯器練習版面

帶標註的編輯器練習版面配置圖,顯示資料夾、檔案與終端機區域。

Machine Learning 的 CI/CD

一起來練習吧!

Machine Learning 的 CI/CD

Preparing Video For Download...