Create readme
Browse files
README.md
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: zh
|
3 |
+
datasets:
|
4 |
+
- Legal Document Dataset
|
5 |
+
|
6 |
+
---
|
7 |
+
# bert-base-chinese for QA
|
8 |
+
|
9 |
+
This is the [bert-base-chinese](https://huggingface.co/bert-base-chinese) model, fine-tuned using the Legal Document Dataset. It's been trained on question-answer pairs for the task of Question Answering.
|
10 |
+
|
11 |
+
## Usage
|
12 |
+
|
13 |
+
### In Transformers
|
14 |
+
```python
|
15 |
+
from transformers import BertTokenizerFast, BertForQuestionAnswering, pipeline
|
16 |
+
model_name = "NchuNLP/Legal-Document-Question-Answering"
|
17 |
+
tokenizer = BertTokenizerFast.from_pretrained(model_name)
|
18 |
+
model = BertForQuestionAnswering.from_pretrained(model_name)
|
19 |
+
|
20 |
+
# a) Get predictions
|
21 |
+
nlp = pipeline('question-answering', model=model, tokenizer=tokenizer)
|
22 |
+
QA_input = {
|
23 |
+
'question': '被告人做了甚麼偽造或冒用的行為?',
|
24 |
+
'context': '犯罪事實一、汪睿楨因細故與其高中老師陳渝麓而生糾紛,竟基於偽造文書之犯意,於民國110年4月16下午4時39分及同年月26日晚間6時13分許,在桃園市○鎮區○○路○○0段000巷00弄00號住處,以電子設備連結網際網路,以陳渝麓名義向教育部部長電子信箱寄送信件,投訴有關學生疑似遭受性侵害等情事,致使教育部誤認上開信件為陳渝麓所發送,足以生損害教育部於信箱管理之正確性。二、案經陳渝麓訴由桃園市政府警察局桃園分局報告偵辦。'
|
25 |
+
}
|
26 |
+
res = nlp(QA_input)
|
27 |
+
# b) Load model & tokenizer
|
28 |
+
model = AutoModelForQuestionAnswering.from_pretrained(model)
|
29 |
+
tokenizer = AutoTokenizer.from_pretrained(tokenizer)
|
30 |
+
# c) Load API
|
31 |
+
|
32 |
+
import requests
|
33 |
+
|
34 |
+
API_URL = "https://api-inference.huggingface.co/models/NchuNLP/Legal-Document-Question-Answering"
|
35 |
+
headers = {"Authorization": "Bearer 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"}
|
36 |
+
|
37 |
+
def query(payload):
|
38 |
+
response = requests.post(API_URL, headers=headers, json=payload)
|
39 |
+
return response.json()
|
40 |
+
|
41 |
+
output = query({
|
42 |
+
"inputs": {
|
43 |
+
"question: "中興大學在哪里?",
|
44 |
+
"context": "國立中興大學(簡稱興大、NCHU),是位於臺中的一所高等教育機構。中興大學以農業科學、農業經濟學、獸醫、生命科學、轉譯醫學、生醫工程、生物科技、綠色科技等研究領域見長 。近年中興大學與臺中榮民總醫院、彰化師範大學、中國醫藥大學等機構合作,聚焦於癌症醫學、免疫醫學及醫學工程三項領域,將實驗室成果逐步應用到臨床上,未來「衛生福利部南投醫院中興院區」將改為「國立中興大學醫學院附設醫院」。興大也與臺中市政府合作,簽訂合作意向書,共同推動數位文化、智慧城市等面相帶動區域發展。"
|
45 |
+
},
|
46 |
+
})
|
47 |
+
|
48 |
+
print(output)
|
49 |
+
```
|
50 |
+
|
51 |
+
## Authors
|
52 |
+
**Kei Yu Heish:** [email protected]
|
53 |
+
|
54 |
+
**Yao-Chung Fan:** [email protected]
|
55 |
+
|
56 |
+
## About us
|
57 |
+
|
58 |
+
[中興大學自然語言處理實驗室](https://nlpnchu.org/)研究方向圍繞於深度學習技術在文字資料探勘 (Text Mining) 與自然語言處理 (Natural Language Processing) 方面之研究,目前實驗室成員的研究主題著重於機器閱讀理解 (Machine Reading Comprehension) 以及自然語言生成 (Natural Language Generation) 兩面向。
|
59 |
+
|
60 |
+
## More Information
|
61 |
+
|
62 |
+
<p>For more info about Nchu NLP Lab, visit our <strong><a href="https://demo.nlpnchu.org/">Lab Online Demo</a></strong> repo and <strong><a href="https://github.com/NCHU-NLP-Lab">GitHub</a></strong>.
|