File size: 4,941 Bytes
c488630 23035b6 2766a1a ddf0bda 23035b6 c488630 fb56143 c488630 fb56143 c488630 fb56143 c488630 828a039 30ab1ca c488630 9b8a934 c488630 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
---
license: gemma
datasets:
- jslin09/Fraud_Case_Verdicts
language:
- zh
base_model:
- google/gemma-2-2b
pipeline_tag: text-generation
text-generation:
parameters:
max_length: 400
max_new_tokens: 400
do_sample: true
temperature: 0.75
top_k: 50
top_p: 0.9
tags:
- legal
widget:
- text: 王大明意圖為自己不法所有,基於竊盜之犯意,
example_title: 生成竊盜罪之犯罪事實
- text: 騙人布意圖為自己不法所有,基於詐欺取財之犯意,
example_title: 生成詐欺罪之犯罪事實
- text: 梅友乾明知其無資力支付酒店消費,亦無付款意願,竟意圖為自己不法之所有,
example_title: 生成吃霸王餐之詐欺犯罪事實
- text: 闕很大明知金融帳戶之存摺、提款卡及密碼係供自己使用之重要理財工具,
example_title: 生成賣帳戶幫助詐欺犯罪事實
- text: 通訊王明知近來盛行以虛設、租賃、借用或買賣行動電話人頭門號之方式,供詐騙集團作為詐欺他人交付財物等不法用途,
example_title: 生成賣電話SIM卡之幫助詐欺犯罪事實
- text: 趙甲王基於行使偽造特種文書及詐欺取財之犯意,
example_title: 偽造特種文書(契約、車牌等)詐財
library_name: transformers
---
# 判決書「犯罪事實」欄草稿自動生成
本模型是以司法院公開之「詐欺」案件判決書做成之資料集,基於 [Google Gemma2:2b](https://huggingface.co/google/gemma-2-2b) 模型進行微調訓練,可以自動生成詐欺及竊盜案件之犯罪事實段落之草稿。資料集之資料範圍從100年1月1日至110年12月31日,所蒐集到的原始資料共有 74823 篇(判決以及裁定),我們只取判決書的「犯罪事實」欄位內容,並把這原始的資料分成三份,用於訓練的資料集有59858篇,約佔原始資料的80%,剩下的20%,則是各分配10%給驗證集(7482篇),10%給測試集(7483篇)。在本網頁進行測試時,請在模型載入完畢並生成第一小句後,持續按下Compute按鈕,就能持續生成文字。或是輸入自己想要測試的資料到文字框中進行測試。或是可以到[這裡](https://huggingface.co/spaces/jslin09/legal_document_drafting)有更完整的使用體驗。
# 比較
以下是本模型與經過微調後的BLOOM 560m、Llama 3.2-1b以 [ROUGE-L](https://en.wikipedia.org/wiki/ROUGE_(metric)) 做評估後的散點圖。

# 使用範例
如果要在自己的程式中調用本模型,可以參考下列的 Python 程式碼,藉由呼叫 API 的方式來生成刑事判決書「犯罪事實」欄的內容。
<details>
<summary> 點擊後展開 </summary>
<pre>
<code>
import requests, json
from time import sleep
from tqdm.auto import tqdm, trange
API_URL = "https://api-inference.huggingface.co/models/jslin09/gemma2-2b-fraud"
API_TOKEN = 'XXXXXXXXXXXXXXX' # 調用模型的 API token
headers = {"Authorization": f"Bearer {API_TOKEN}"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return json.loads(response.content.decode("utf-8"))
prompt = "森上梅前明知其無資力支付酒店消費,亦無付款意願,竟意圖為自己不法之所有,"
query_dict = {
"inputs": prompt,
}
text_len = 300
t = trange(text_len, desc= '生成例稿', leave=True)
for i in t:
response = query(query_dict)
try:
response_text = response[0]['generated_text']
query_dict["inputs"] = response_text
t.set_description(f"{i}: {response[0]['generated_text']}")
t.refresh()
except KeyError:
sleep(30) # 如果伺服器太忙無回應,等30秒後再試。
pass
print(response[0]['generated_text'])
</code>
</pre>
</details>
或是,你要使用 transformers 套件來實作你的程式,將本模型下載至你本地端的電腦中執行,可以參考下列程式碼:
<details>
<summary> 點擊後展開 </summary>
<pre>
<code>
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("jslin09/gemma2-2b-fraud")
model = AutoModelForCausalLM.from_pretrained("jslin09/gemma2-2b-fraud")
</code>
</pre>
</details>
如果是要使用 [Ollama](https://ollama.com/) 作為本地端驅動模型的工具,可以使用 Ollama 下載放在 Ollama 網站的[已量化(Q4_0)版本](https://ollama.com/jslin/gemma2-2b-fraud) 直接使用。
# 致謝
微調本模型所需要的算力,是由[評律網](https://www.pingluweb.com.tw/)提供 NVIDIA H100。特此致謝。
# 引文訊息
```
@article{lin2025assisting,
title={Assisting Drafting of Chinese Legal Documents Using Fine-Tuned Pre-trained Large Language Models},
author={Lin, Chun-Hsien and Cheng, Pu-Jen},
journal={The Review of Socionetwork Strategies},
pages={1--28},
year={2025},
publisher={Springer}
}
``` |