# 7/2進度紀錄
## 廖奕皓
進度:搞懂上禮拜的進度、找找其他AIGC Detect的相關論文
### AIGC辨識論文
1. GLTR:
將用於生成虛假文本的相同模型(GPT2)作為檢測工具,他可以訪問該模型(GPT2),分析輸入文字中每個詞(token)在語言模型的預測中屬於多常見(綠色:非常可預測、黃色:一般可預測、紅色紫色:非常難預測)
EX. 這是某個由AI生成的文字,大部分的單詞token都是綠色,非常可預測,所以判斷為AI生成的文字


論文連結:https://arxiv.org/abs/2301.11305
online demo:http://gltr.io/
github:https://github.com/HendrikStrobelt/detecting-fake-text?tab=readme-ov-file
問題:檢測受模型限制,要固定模型才能以該模型為工具去預測。
---
2. GPTDetector: A GPT-2 Based Classifier for Detecting Generated Text:
類似我們之前做的ScamDetector,利用已有的真實文本和AI生成文本去訓練二分類器,判斷文本是AI生成或不是(0, 1)。
* 分類器:可以進行二分法的模型,常用在文本分類,有BERT、RoBERTa、Logistic Regression 等。
RoBERTa-based 分類器效果最佳,對於 GPT-2 文字的辨識準確率可達 95% 以上。
問題:判斷領域可能受限,因為真實資料可能都來自論文或期刊之類的,結果受二分器模型、訓練資料選擇影響。
論文連結:https://arxiv.org/abs/2301.01509
Title:使用 RoBERTa fine-tune 以偵測 ChatGPT 輸出,並提供訓練、評估程式碼
相關github:https://github.com/l1xiangyi/chatgpt-detector-roberta?utm_source=chatgpt.com
---
3. DetectGPT(Zero-shot 基於概率曲率)
使用機率曲率(probability curvature)原理,無需訓練即可偵測 AI 文本,高準確率做到 zero‑shot,但好像不是用模型去判斷
github:https://github.com/eric-mitchell/detect-gpt?utm_source=chatgpt.com
## 簡筠方
又是chatgpt整理的:
https://hackmd.io/@IizmYTUETE2C0DpZ8K_zUw/H1ZjZyFSex
### DetectGPT
論文 : [DetectGPT: Zero-Shot Machine-Generated Text Detection
using Probability Curvature](https://arxiv.org/pdf/2301.11305v1)
github:https://github.com/eric-mitchell/detect-gpt
DetectGPT 是一種 **事後偵測(post hoc detection)** 方法,用來判斷一段文字是否由大型語言模型(LLM)生成 :
* **零樣本(zero-shot)**
* **不需訓練分類器**、**不需水印**
* **不需資料集蒐集**
* **不需存取內部 logits 或微調資料**
#### 核心概念:
>語言模型生成的文本,在模型自己的 log-likelihood 函數下,比鄰近的微擾版本更穩定。
對一段由 LLM 生成的文本,如果你對裡面的詞做些**小變動(稱為 perturbation)**,再用該模型來算 log-likelihood(簡單說就是這段文字對模型來說有多合理),你會發現原本的版本比改動後的版本更合理。
相反的,如果是一段人類寫的文本,這個穩定性特徵會比較弱。
### Post-Hoc Watermarking
論文 : [Post-Hoc Watermarking for Robust Detection in Text Generated by Large
Language Models](https://aclanthology.org/2025.coling-main.364.pdf)
github:https://github.com/AlfredWatson/RSFPH-WTGBBLM
>針對**已生成的文本**進行後處理,無需存取模型內部細節,僅透過**語言層面修改文本**來嵌入水印。
#### 生成水印
```
[LLM 輸出文本 X]
↓
[選擇嵌入位置 S(根據語法/語意特徵)]
↓
[為每個詞計算上下文 XOR 編碼 bit]
↓
[挑出所有 bit-0 的詞 → 同義詞替換為 bit-1 詞]
↓
[生成水印文本 Xw]
```
#### 檢測流程
```
[輸入文本]
↓
[選出可能嵌入位置(同樣的 anchor 特徵)]
↓
[計算每個詞對應的 bit 值]
↓
[統計整體偏向 bit-1 的比例]
↓
[應用檢定 → 是否顯著偏態 → 是否含水印]
```
## 陳孟蓉
### test_method
使用 OPT-1.3B 模型
水印演算法 KWG
- KWG.json:
{
"algorithm_name": "KGW",
"gamma": 0.5,
"delta": 2.0,
"hash_key": 15485863,
"prefix_length": 1,
"z_threshold": 4.0,
"f_scheme": "time",
"window_scheme": "left"
}
gamma : 水印 token 佔的比例
delta : 插入頻率
| 參數 | 控制內容 | 越大代表 |
| ----- | -------------- | ------------------- |
| gamma | 偏好水印 token 的程度 | 水印強度↑、可檢測性↑、自然度↓ |
| delta | 控制插入水印的間隔與集中程度 | 插水印越密集、範圍越集中、水印清晰度↑ |
:::spoiler natural_text
IBM on Tuesday announced a prepackaged and pretested cluster that is powered by Advanced Micro Devices Inc.s 64-bit Opteron processor.
IBM, of Armonk, N.Y., is combining its Opteron-based eServer 325 server—which targets scientific and technical computing users—with systems management software and storage devices to offer a bundled package that can run Linux and Windows operating systems.
The new offering, which will be available later this month or in early December, is part of IBMs eServer Cluster 1350, which also includes bundles based on the companys BladeCenter blade servers and two-processor x335 and x345 systems using Intel Corp.s 32-bit Xeon chips.
Clusters comprise multiple servers tied together to create a supercomputing environment for users. In a related move, IBM last week announced that it was teaming with Corning Inc., the U.S. Department of Energy and the National Nuclear Security
:::
:::spoiler watermarked output
Output:
Cluster comprises IBM's Opteron-based eServer 325 server and systems management software and storage devices that can run Linux and Windows operating systems (OS). In addition, it works on Linux 1.4 and Unix-like system versions x86_64 and 2.6. The eServer 325 is capable of clustering up to 35 Oracle data nodes.
With the release of this eServer 325 configuration support and support for clustering were added to the Oracle Online Install Wizard. Using the Oracle Online Loader, you can cluster up to 35 systems together to run Oracle workloads in a single operating system environment, regardless of which type of clustered system was selected in the Online Install Wizard, IBM said in an announcement.
You now select one Oracle Linux cluster and then select one Oracle Unix cluster to run the same Oracle Linux workload. The clusters are connected through the same interconnect channel. The main difference: The Oracle Linux cluster has been selected in the Oracle Online Installation Wizard, not the Oracle Unix cluster, making the cluster environment easier to configure and manage. This is the first time the choice has been made to enable clust
:::
:::spoiler unwatermarked output
Cluster comprises IBM's Opteron-based eServer 325 server and systems management software and storage devices that can run Linux and Windows operating systems. It runs cluster software that provides support for IBM's Hypervisor, BigQuery analytics engine and other enterprise applications as well as IBM mainframe technologies.
The system offers data storage density of up to 7.6TB per server, or 2TB per PC, using IBM Bluemix storage management software.
Dell EMC's new Power9-based servers use an Intel Core i9-7960X processor, dual-CPU ECC memory, support of Intel Xeon dual-core processors, HyperTransport 1.6 networking for networking and hypervisor support for virtualized server-side applications.
This story, "Dell unveils new server: Power9, Xeon server with Intel Core i7 and Xeon E7" was originally published by
NetworkWorld.
Copyright 2018 . Follow NetworkWorld elsewhere on the Internet.
Reproduction in whole or in part in any form or medium without express written permission of IDG Communications is prohibited. Copyright
:::
watermark : {'is_watermarked': True, 'score': 6.490208549618715}
unwatermark : {'is_watermarked': False, 'score': -1.1920791213585393}
natural : {'is_watermarked': False, 'score': 0.6379930845075023}
### Example
------------------------------------------
| 參數 | 值 | 說明 |
| --------------- | ---------- | -------------------------------------- |
| `vocab_size` | 10 | |
| `gamma` | 0.3 | 綠色 token 佔 30%,即 greenlist 有 3 個 token |
| `delta` | 2.0 | logits 偏移值,偏好插入 green token |
| `hash_key` | 7 | 種子值,影響隨機性 |
| `prefix_length` | 2 | 觀察前 2 個 token 決定 greenlist |
| `f_scheme` | `additive` | 使用前兩 token 的 index 總和當作種子來源 |
| `window_scheme` | `left` | 只看前面 token |
#### 前 n 個 token → f_scheme → f_x
- input_ids = [2, 4]
- f_scheme = additive
- f_x = (input_ids[-1] + input_ids[-2]) = 4 + 2 = 6
| `f_scheme` 名稱 | 算法 |
| ------------- | --------------------------------- |
| `"time"` | 把前 n 個 token 的 id 相乘,再取 hash seed |
| `"additive"` | 把前 n 個 token 的 id 相加,再取 hash seed |
| `"skip"` | 只拿第 n 個 token,直接當作 hash seed |
| `"min"` | 取前 n 個 token 的 hash 最小值來當 seed |
#### 使用 f_x 與 hash_key 決定 random seed
- **seed = (hash_key * f_x) % vocab_size**
= (7 * 6) % 10
= 42 % 10
= 2
#### 建立 vocab permutation → 取前 gamma% 作為 greenlist
- 用 seed 產生 vocab permutation
(用 seed 決定亂數順序 → 用亂數順序選前幾個 token → 這些 token 就是「本輪允許選的綠色 token」)
torch.randperm(10, generator=seed):
[3, 1, 9, 6, 5, 2, 7, 8, 0, 4]
- greenlist = 0.3 * 10 = 3
greenlist = [3, 1, 9]
#### 調整 green token 的 logits(+delta)
- 進入 KGWLogitsProcessor:
scores = [1.2, 0.3, 2.1, 1.5, 0.9, 1.0, 1.1, 0.2, 1.3, 0.7]
Greenlist = [3, 1, 9],將這三個位置的 logits 加上 delta = 2.0:
scores[3] += 2 → 1.5 + 2 = 3.5
scores[1] += 2 → 0.3 + 2 = 2.3
scores[9] += 2 → 0.7 + 2 = 2.7
使 sampling 時插入水印 token 機率上升
---------------------------------------------------
判定是否使用水印:
- z_score = (實際觀察值−期望值)除以標準差
超過 z_threshold 判定有使用水印
生成的 token 越多是在 greenlist 中代表水印越強
## 陳芊羽
給第一週進度加長條圖+codecarbon
[codecarbon](https://gitcode.com/gh_mirrors/co/codecarbon)

2. 雜記
上週是對長文章做 iterative summerization
-> multi-document?
## 游婷安
因為是要比較不同方法的AI,所以應該要使用:
1. Process-level measurement
2. Consideration of usage factor
我發現我們的serevr (186) 是使用MacOS,所以不是intel cpu& nvidia gpu -> 有些工具可能無法正常使用

| Tool | Mode | CPU Support | GPU Support | Usage Factor | macOS (186 server) | Linux w/o root (162 server) | Key Downsides |
| --------------------------------------------------------------------- | --------- | --------------- | --------------- | ----------------------- | ------------------ | ---------------------------------------- | ----------------------------------------------- |
| [**Green Algorithm**](https://calculator.green-algorithms.org/) | process | ✅ any | ✅ any | yes(⚠️manually) | ✅Good | ✅Good | no auto-logging |
| [**CodeCarbon** ](https://github.com/mlco2/codecarbon) (process mode) | both | ✅ any | ⚠️ NVIDIA only | No (only whole machine) | ⚠️cant detect gpu | ✅Good | Overestimates CPU&GPU; fallback TDP values |
| [**Eco2AI**](https://github.com/sb-ai-lab/Eco2AI) (process mode) | both | ✅ any | ⚠️ NVIDIA only | CPU only | ⚠️cant detect gpu | ✅Good | overestimates GPU factor |
| ~~**CarbonTracker**~~ | ❌machine | ⚠️ Intel only | ⚠️ NVIDIA only | No | ❌ | ❌ | Requires RAPL and root; very limited |
| [**EIT**](https://github.com/Breakend/experiment-impact-tracker) | process | ⚠️Intel only | ⚠️ NVIDIA only | yes | ❌ | ✅ | **Hard to install**, complex requirements |
| ~~**MLCO2**~~ | ❌machine | ⚠️ Not specific | Only GPU (100%) | No | ❌ | ❌ | Assumes full GPU use; no CPU or memory tracking |
| ~~**Cumulator**~~ | ❌machine | No CPU tracking | No GPU tracking | No | ❌ | ❌ | No isolation, no breakdown, just rough totals |