Giskard - 機器學習模型測試框架推薦
大家好,又見面了,我是 GitHub 精選君!
背景介紹
在機器學習領域,對于模型的測試是一項關鍵任務。由于機器學習模型依賴于數(shù)據(jù),測試場景會受到特定領域問題的影響,往往是無限多的。那么從哪里開始測試?該實施哪些測試?應該覆蓋哪些問題?如何實施這些測試?在Giskard項目中,我們相信機器學習需要自己的測試框架。Giskard 是一個專注于機器學習模型的開源測試框架,涵蓋了從表格模型到語言模型(LLMs)的測試需求。
Giskard-AI/giskard 項目在 GitHub 有超過 1000 Star,用一句話介紹該項目就是:“The testing framework dedicated to ML models, from tabular to LLMs”。
項目介紹
Giskard致力于掃描AI模型以檢測偏差、性能問題和錯誤的風險。它是一個適用于機器學習模型的測試框架,可以從表格模型到語言模型進行測試。Giskard的主要功能包括:
-
? 掃描模型以發(fā)現(xiàn)漏洞:Giskard的掃描功能可以自動檢測性能偏差、數(shù)據(jù)泄漏、不穩(wěn)定性、虛假相關性、過度自信、不足自信、倫理問題等漏洞。
-
? 自動生成特定領域的測試用例:根據(jù)掃描結果,Giskard可以自動生成相關的測試用例。你可以通過定義領域特定的數(shù)據(jù)切片器和轉換器來定制測試用例,以適應你的使用場景。
-
? 借鑒開源社區(qū)的質量保證最佳實踐:Giskard的目標是成為機器學習質量保證的開源中心,你可以輕松貢獻和加載數(shù)據(jù)切片、轉換函數(shù)以及AI基礎檢測器、生成器或評估器。受到Hugging Face哲學的啟發(fā),Giskard旨在成為機器學習質量保證的開源平臺。
此外,Giskard可以與任何模型和環(huán)境配合使用,并與你喜歡的工具無縫集成。
如何使用
-
? 安裝:可以通過以下命令安裝Giskard:
pip install "giskard[server]>=2.0.0b" -U
giskard server start
-
? 掃描模型以檢測漏洞:在封裝好模型和數(shù)據(jù)集之后,你可以使用以下代碼對模型進行漏洞掃描:
import giskard
# 替換這里的模型和數(shù)據(jù)集
df = giskard.demo.titanic_df()
data_preprocessor, clf = giskard.demo.titanic_pipeline()
# Wrap your Pandas DataFrame with Giskard.Dataset, containing examples such as:
# your test set, a golden dataset, etc.
# See https://docs.giskard.ai/en/latest/guides/wrap_dataset/index.html
giskard_dataset = giskard.Dataset(
df=df, # A pandas.DataFrame that contains the raw data (before all the pre-processing steps) and the actual ground truth variable (target).
target="Survived", # Ground truth variable
name="Titanic dataset", # Optional
cat_columns=['Pclass', 'Sex', "SibSp", "Parch", "Embarked"] # Optional, but is a MUST if available. Inferred automatically if not.
)
# Wrap your model with Giskard.Model:
# you can use any tabular, text or LLM models (PyTorch, HuggingFace, LangChain, etc.),
# for classification, regression & text generation.
# See https://docs.giskard.ai/en/latest/guides/wrap_model/index.html
def prediction_function(df):
# The pre-processor can be a pipeline of one-hot encoding, imputer, scaler, etc.
preprocessed_df = data_preprocessor(df)
return clf.predict_proba(preprocessed_df)
giskard_model = giskard.Model(
model=prediction_function, # A prediction function that encapsulates all the data pre-processing steps and that could be executed with the dataset used by the scan.
model_type="classification", # Either regression, classification or text_generation.
name="Titanic model", # Optional
classification_labels=clf.classes_, # Their order MUST be identical to the prediction_function's output order
feature_names=['PassengerId', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp', 'Parch', 'Fare', 'Embarked'], # Default: all columns of your dataset
# classification_threshold=0.5, # Default: 0.5
)
# Then apply the scan
results = giskard.scan(giskard_model, giskard_dataset)
更多的安裝和使用細節(jié)可以參考項目的文檔。
以下是該項目 Star 趨勢圖(代表項目的活躍程度):

更多項目詳情請查看如下鏈接。
開源項目地址:https://github.com/Giskard-AI/giskard
開源項目作者:Giskard-AI
以下是參與項目建設的所有成員:

關注我們,一起探索有意思的開源項目。
點擊如下卡片后臺回復:加群,與技術極客們一起交流人工智能、開源項目,一起成長。
點擊 在 看 支持一下吧