Update README.md
Browse files
README.md
CHANGED
|
@@ -11,11 +11,83 @@ widget:
|
|
| 11 |
- text: "Is this review positive or negative? Review: Best cast iron skillet you will ever buy."
|
| 12 |
example_title: "Sentiment analysis"
|
| 13 |
---
|
| 14 |
-
# Model Card for
|
| 15 |
|
| 16 |
<!-- Provide a quick summary of what the model is/does. -->
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
## Model Details
|
| 21 |
|
|
@@ -83,10 +155,10 @@ Use the code below to get started with the model.
|
|
| 83 |
|
| 84 |
## Training Details
|
| 85 |
|
| 86 |
-
###
|
| 87 |
|
| 88 |
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 89 |
-
[法律要件資料集](https://huggingface.co/datasets/jslin09/LegalElements)
|
| 90 |
|
| 91 |
[More Information Needed]
|
| 92 |
|
|
|
|
| 11 |
- text: "Is this review positive or negative? Review: Best cast iron skillet you will ever buy."
|
| 12 |
example_title: "Sentiment analysis"
|
| 13 |
---
|
| 14 |
+
# Model Card for Gemma2-2b-ner
|
| 15 |
|
| 16 |
<!-- Provide a quick summary of what the model is/does. -->
|
| 17 |
|
| 18 |
+
本模型基於 [Gemma2:2b](https://huggingface.co/google/gemma-2-2b) 進行微調,目的是讓其依據台灣刑法學中常用的「刑法三階理論」,針對大型語言模型生成的詐欺罪「犯罪事實」段落,依照詐欺罪法條所規定的構成要件進行標註。具備生成詐欺罪「犯罪事實」的模型,可以參考以 BLOOM 560M 為基礎的[BLOOM 560M Fraud](https://huggingface.co/jslin09/bloom-560m-finetuned-fraud)微調模型,或是以 Gemma2 為基礎的[Gemma2:2b Fraud](https://huggingface.co/jslin09/gemma2-2b-fraud)微調模型。
|
| 19 |
+
目前可以識別出來的標註標籤有以下七種具名實體,無法識別出來的構成要件要素具名實體,則會傳回 None。
|
| 20 |
+
|
| 21 |
+
<pre>
|
| 22 |
+
<code>
|
| 23 |
+
from colorama import Fore, Back, Style
|
| 24 |
+
|
| 25 |
+
elements = {'LEO_SOC': ('犯罪主體', 'Subject of Crime'),
|
| 26 |
+
'LEO_VIC': ('客體', 'Victim'),
|
| 27 |
+
'LEO_ACT': ('不法行為', 'Behavior'),
|
| 28 |
+
'LEO_SLE': ('主觀要件', 'Subjective Legal Element of the Offense'),
|
| 29 |
+
'LEO_CAU': ('因果關係', 'Causation'),
|
| 30 |
+
'LEO_ROH': ('危害結果', 'Result of Hazard'),
|
| 31 |
+
'LEO_ATP': ('未遂', 'Attempted')
|
| 32 |
+
}
|
| 33 |
+
tag_color = {'LEO_SOC': Fore.BLACK + Back.RED,
|
| 34 |
+
'LEO_VIC': Fore.BLACK + Back.YELLOW,
|
| 35 |
+
'LEO_ACT': Fore.BLACK + Back.GREEN,
|
| 36 |
+
'LEO_SLE': Fore.BLACK + Back.MAGENTA,
|
| 37 |
+
'LEO_CAU': Fore.BLACK + Back.CYAN,
|
| 38 |
+
'LEO_ROH': Fore.BLACK + Back.BLUE,
|
| 39 |
+
'LEO_ATP': Fore.WHITE + Back.BLACK,
|
| 40 |
+
}
|
| 41 |
+
</code>
|
| 42 |
+
</pre>
|
| 43 |
+
|
| 44 |
+
為了要將本模型標註出來的結果以更明顯的方式識別,可以參考以下的程式碼,將本大型語言模型生成的標註結果以及所標註的標籤,同時送入以下的函數,就可以將結果以 colorama 的方式著色標註。
|
| 45 |
+
|
| 46 |
+
<pre>
|
| 47 |
+
<code>
|
| 48 |
+
from colorama import Fore, Back, Style
|
| 49 |
+
|
| 50 |
+
def tag_in_color(response_content, tag):
|
| 51 |
+
'''
|
| 52 |
+
說明:
|
| 53 |
+
將標註結果依照標籤進行標色。
|
| 54 |
+
Parameters:
|
| 55 |
+
response_content (str): 已經標註完畢並有標籤的內容。
|
| 56 |
+
tag (str): 標籤名稱,英文,沒有括號。
|
| 57 |
+
Return:
|
| 58 |
+
result (str): 去除標籤並含有 colorama 標色符號的字串。
|
| 59 |
+
'''
|
| 60 |
+
response_head = response_content.split("標註結果:\n")[0]
|
| 61 |
+
response_body = response_content.split("標註結果:\n")[1]
|
| 62 |
+
start_index = 0
|
| 63 |
+
# 使用正規表示式找出所有構成要件要素文字的起始位置
|
| 64 |
+
# 加入 re.escape() 是為了避免處理到有逸脱字元的字串會報錯而中斷程式執行
|
| 65 |
+
findall_open_tags = [m.start() for m in re.finditer(re.escape(f"[{tag}]"), response_body)]
|
| 66 |
+
findall_close_tags = [m.start() for m in re.finditer(re.escape(f"[/{tag}]"), response_body)]
|
| 67 |
+
try:
|
| 68 |
+
parts = [response_body[start_index:findall_open_tags[0]]] # 第一個標籤之前的句子
|
| 69 |
+
except IndexError:
|
| 70 |
+
parts = []
|
| 71 |
+
# 找出每個標籤所在位置,取出標籤文字並加以著色。
|
| 72 |
+
for j, idx in enumerate(findall_open_tags):
|
| 73 |
+
tag_text = response_body[idx + len(tag) + 2:findall_close_tags[j]]
|
| 74 |
+
parts.append(f"{tag_color[tag]}" + tag_text + Style.RESET_ALL) # 標籤內文字著色
|
| 75 |
+
closed_tag = findall_close_tags[j] + len(tag) + 3
|
| 76 |
+
try:
|
| 77 |
+
next_open_tag = findall_open_tags[j+1]
|
| 78 |
+
parts.append(response_body[closed_tag: next_open_tag]) # 結束標籤之後到下一個標籤前的文字
|
| 79 |
+
except IndexError:
|
| 80 |
+
parts.append(response_body[findall_close_tags[-1] + len(tag) + 3 :]) # 加入最後一句
|
| 81 |
+
result = ''
|
| 82 |
+
for _, part in enumerate(parts):
|
| 83 |
+
result = result + part
|
| 84 |
+
if result == '':
|
| 85 |
+
color_result = f"{tag_color[tag]}{tag}" + Fore.RESET + Back.RESET + " " +Fore.YELLOW + Back.RED + "*** 無標註結果 ***" + Fore.RESET + Back.RESET
|
| 86 |
+
else:
|
| 87 |
+
color_result = Fore.RED + Back.YELLOW + "標註著色結果:\n" + Fore.RESET + Back.RESET + result
|
| 88 |
+
return color_result
|
| 89 |
+
</code>
|
| 90 |
+
</pre>
|
| 91 |
|
| 92 |
## Model Details
|
| 93 |
|
|
|
|
| 155 |
|
| 156 |
## Training Details
|
| 157 |
|
| 158 |
+
### 訓練資料
|
| 159 |
|
| 160 |
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 161 |
+
本模型是以強化學習的方式微調 Gemma2:2b 並經過多回合人工對齊生成資料反覆迭代訓練而成,訓練所需要的資料集是[法律要件資料集](https://huggingface.co/datasets/jslin09/LegalElements)。使用者可以下載後自己持續迭代後修正及擴充資料集內容。
|
| 162 |
|
| 163 |
[More Information Needed]
|
| 164 |
|