Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GPT-OSS-Safeguard 實驗工具

此目錄彙整作者探索 GPT-OSS-Safeguard 時使用的部分工具。它是 DNGros/gptossexp-workspace 的部分鏡像,嘗試移除較多雜項,只保留較通用的內容。不過目前仍相當實驗性,如果作者之後繼續修改主要實驗 repo,本目錄可能落後。

Hackathon 貢獻

Hackathon 筆記整理於以下文章。

Dev Notes 24: Small Evaluation of GPT-OSS-Safeguard Preferences; Also Prompting Experiments

主要工作是探索 Safeguard model 與 base model 在「沒有政策」時的偏好差異,做法是請模型評分一小組爭議觀點有多「好」。結果摘要如下。

  • 在 102 則爭議觀點的小型實驗資料中,以 1 至 5 分評分時,GPT-OSS-Safeguard-20B 對各種觀點的評價與 base model 有可測量的差異,約 44% 文字得到不同評分。
  • GPT-OSS-Safeguard model 似乎更常把爭議觀點集中評為猶豫不決的中間值 3。Safeguard model 有 72% 評分為 3,base model 則為 55%。
  • 作者先前曾嘗試重現 OpenAI 回報的 ToxicChat 資料集結果。HF 的 Yacine 在活動中分享如何依 Hugging Face Space 的做法,以 Harmony format 提示模型。但作者在活動後以簡單 prompt 測試 ToxicChat 時,不同 prompt format 並未造成太大差異。這可能是好消息,因為直接將政策放進 system role 的簡單方法,可能不會比 Harmony style 差很多。仍有許多問題值得探索,也歡迎其他人分享重現論文結果,或比較 prompt format、HF Inference 與本機 inference 的經驗。作者不確定本機與 Groq 是否真的回傳相同輸出。

資料比較圖

此路徑的內容

此路徑包含 Hackathon 結果的程式碼,以及可作為政策測試起點的 framework。

安裝

使用 miniconda、uv 或其他工具管理環境。例如以下指令。

# Activate the environment you are using (or make a new one)
conda create -n gptosoexp python=3.12
conda activate gptossexp
# Install this dir
pip install -e .

政策測試 framework

此處提供用來反覆調整政策的基本 framework。它很初步,主要概念是加入含有 policy 與 parse function 的 module。

# toy_example_policy.py

POLICY = """\
Output exactly `1` if the user message is toxic, and `0` if it is not
"""

def parse(response: ModelResponse) -> ClassificationResult:
    text = response.response.strip()
    binary_label = (text == "1")
    return ClassificationResult(
        binary_label=binary_label,
        fine_grain_label="1" if binary_label else "0",
        float_label=1.0 if binary_label else 0.0,
        metadata={},
        model_response=response,
        parsed_successfully=(text == "1" or text == "0")
    )

其他範例請參閱政策目錄

接著可使用 classify method。

from gpt_oss_utils_dactile.classify import classify, ClassificationResult
import toy_example_policy
from gpt_oss_utils_dactile.model_predict import ModelResponse, Model, InferenceBackend

response: ClassificationResult = classify(
    text="I hate puppies",
    policy=toy_example_policy, # Just pass in your policy module
    model = Model.GPT_OSS_20B,
    backend = InferenceBackend.API_INJECT_HARMONY,
    #         ^ This is the version that follows the HF space style.
    #           See the post for explaining some of this nuance.
    #           If you instead use InferenceBackend.API it will instead
    #           just pass things into the `system` prompt rather
    #           than the `developer` channel.
    use_cache: bool = True,
    #                 ^ cache this for rerun later
)
print(response.binary_label)

Hackathon 實驗程式碼

進入點是上游的 gpt_oss_utils_dactile/hackathon/hello_controversial.py

# Runs all 102 examples with both models and prints some analysis outputs
python -m gpt_oss_utils_dactile.hackathon.hello_controversial

再次提醒,這些內容仍很實驗性。合成資料位於上游 controversial-micro.jsonl

聯絡

歡迎發起 discussion 並標記 @DNGros。

上述百分比與觀察是來源作者的小型實驗結果,繁中維護者未重新執行。請勿將這些數值視為一般模型表現或正式安全保證。