Giskard - 機(jī)器學(xué)習(xí)模型測(cè)試框架推薦
大家好,又見面了,我是 GitHub 精選君!
背景介紹
在機(jī)器學(xué)習(xí)領(lǐng)域,對(duì)于模型的測(cè)試是一項(xiàng)關(guān)鍵任務(wù)。由于機(jī)器學(xué)習(xí)模型依賴于數(shù)據(jù),測(cè)試場(chǎng)景會(huì)受到特定領(lǐng)域問題的影響,往往是無限多的。那么從哪里開始測(cè)試?該實(shí)施哪些測(cè)試?應(yīng)該覆蓋哪些問題?如何實(shí)施這些測(cè)試?在Giskard項(xiàng)目中,我們相信機(jī)器學(xué)習(xí)需要自己的測(cè)試框架。Giskard 是一個(gè)專注于機(jī)器學(xué)習(xí)模型的開源測(cè)試框架,涵蓋了從表格模型到語(yǔ)言模型(LLMs)的測(cè)試需求。
Giskard-AI/giskard 項(xiàng)目在 GitHub 有超過 1000 Star,用一句話介紹該項(xiàng)目就是:“The testing framework dedicated to ML models, from tabular to LLMs”。
項(xiàng)目介紹
Giskard致力于掃描AI模型以檢測(cè)偏差、性能問題和錯(cuò)誤的風(fēng)險(xiǎn)。它是一個(gè)適用于機(jī)器學(xué)習(xí)模型的測(cè)試框架,可以從表格模型到語(yǔ)言模型進(jìn)行測(cè)試。Giskard的主要功能包括:
-
? 掃描模型以發(fā)現(xiàn)漏洞:Giskard的掃描功能可以自動(dòng)檢測(cè)性能偏差、數(shù)據(jù)泄漏、不穩(wěn)定性、虛假相關(guān)性、過度自信、不足自信、倫理問題等漏洞。
-
? 自動(dòng)生成特定領(lǐng)域的測(cè)試用例:根據(jù)掃描結(jié)果,Giskard可以自動(dòng)生成相關(guān)的測(cè)試用例。你可以通過定義領(lǐng)域特定的數(shù)據(jù)切片器和轉(zhuǎn)換器來定制測(cè)試用例,以適應(yīng)你的使用場(chǎng)景。
-
? 借鑒開源社區(qū)的質(zhì)量保證最佳實(shí)踐:Giskard的目標(biāo)是成為機(jī)器學(xué)習(xí)質(zhì)量保證的開源中心,你可以輕松貢獻(xiàn)和加載數(shù)據(jù)切片、轉(zhuǎn)換函數(shù)以及AI基礎(chǔ)檢測(cè)器、生成器或評(píng)估器。受到Hugging Face哲學(xué)的啟發(fā),Giskard旨在成為機(jī)器學(xué)習(xí)質(zhì)量保證的開源平臺(tái)。
此外,Giskard可以與任何模型和環(huán)境配合使用,并與你喜歡的工具無縫集成。
如何使用
-
? 安裝:可以通過以下命令安裝Giskard:
pip install "giskard[server]>=2.0.0b" -U
giskard server start
-
? 掃描模型以檢測(cè)漏洞:在封裝好模型和數(shù)據(jù)集之后,你可以使用以下代碼對(duì)模型進(jìn)行漏洞掃描:
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)
更多的安裝和使用細(xì)節(jié)可以參考項(xiàng)目的文檔。
以下是該項(xiàng)目 Star 趨勢(shì)圖(代表項(xiàng)目的活躍程度):

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

關(guān)注我們,一起探索有意思的開源項(xiàng)目。
點(diǎn)擊如下卡片后臺(tái)回復(fù):加群,與技術(shù)極客們一起交流人工智能、開源項(xiàng)目,一起成長(zhǎng)。
點(diǎn)擊 在 看 支持一下吧