TheWeeeed commited on
Commit
fd8d742
·
verified ·
1 Parent(s): 5ed0bf6

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +87 -0
README.md ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ license: apache-2.0 # 或者您選擇的其他許可證,例如 mit, cc-by-4.0
2
+ language:
3
+ - zh # 中文
4
+ tags:
5
+ - extractive-qa
6
+ - bert
7
+ - chinese
8
+ pipeline_tag: question-answering
9
+ widget:
10
+ - question: "模型卡片的作者是誰?"
11
+ context: "這張模型卡片是由一個大型語言模型協助創建的。"
12
+ candidate_labels: ["大型語言模型", "Hugging Face", "用戶"] # 如果是多選模型
13
+ # - text: "這是一段示例文本,用於測試模型。" # 如果是文本生成或其他類型
14
+ # answers: # 如果是問答模型,可以提供一個示例答案
15
+ # - "一個大型語言模型"
16
+ ---
17
+
18
+ # 模型名稱:[您的模型名稱,例如:中文抽取式問答模型 - 段落選擇器]
19
+
20
+ 這是一個為中文抽取式問答任務微調的 [基礎模型架構,例如:BERT] 模型。
21
+ 它是[您的兩階段問答系統的描述,例如:一個兩階段問答系統的第一階段/第二階段],用於[模型的功能,例如:從候選段落中選擇最相關的段落/從給定段落中提取答案]。
22
+
23
+ ## 模型描述
24
+
25
+ * **模型類型**: [例如:bert-base-chinese 微調後的 `AutoModelForMultipleChoice` 或 `AutoModelForQuestionAnswering`]
26
+ * **語言**: 中文 (簡體/繁體,請指明)
27
+ * **訓練數據**: [簡要描述您用於訓練的數據集,例如:基於 [某數據集名稱] 修改/生成的自定義數據集,包含問題、候選段落和相關段落標籤/答案標註]
28
+ * **開發者**: [您的名字或組織名,例如:TheWeeeed (YuTsyh)]
29
+ * **相關項目/GitHub倉庫**: [鏈接到您的 GitHub 倉庫,例如:https://github.com/YuTsyh/Chinese-Extractive-Question-Answering-QA-.git]
30
+ * **相關模型 (如果適用)**:
31
+ * [例如:對於答案抽取模型,可以鏈接到段落選擇模型:TheWeeeed/chinese-paragraph-selector]
32
+ * [例如:對於段落選擇模型,可以鏈接到答案抽取模型:TheWeeeed/chinese-extractive-qa]
33
+
34
+ ## 用途
35
+
36
+ ### 直接使用
37
+
38
+ 您可以直接使用這個模型進行[多項選擇/問題回答]。
39
+
40
+ ```python
41
+ from transformers import AutoTokenizer, AutoModelForMultipleChoice # 或者 AutoModelForQuestionAnswering
42
+
43
+ tokenizer = AutoTokenizer.from_pretrained("TheWeeeed/[您的模型倉庫名]")
44
+ model = AutoModelForMultipleChoice.from_pretrained("TheWeeeed/[您的模型倉庫名]") # 或者 AutoModelForQuestionAnswering
45
+
46
+ # --- 如果是段落選擇模型 (AutoModelForMultipleChoice) ---
47
+ question = "問題文本"
48
+ candidate_paragraphs = ["段落文本1", "段落文本2", "段落文本3", "段落文本4"]
49
+
50
+ inputs = []
51
+ for paragraph_text in candidate_paragraphs:
52
+ inputs.append(tokenizer(question, paragraph_text, return_tensors="pt", truncation=True, padding="max_length", max_length=512))
53
+
54
+ # 準備模型的輸入格式
55
+ input_ids = torch.stack([inp['input_ids'].squeeze(0) for inp in inputs]).unsqueeze(0)
56
+ attention_mask = torch.stack([inp['attention_mask'].squeeze(0) for inp in inputs]).unsqueeze(0)
57
+ # token_type_ids = ... (如果您的模型使用它)
58
+
59
+ # device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
60
+ # model.to(device)
61
+ # input_ids = input_ids.to(device)
62
+ # attention_mask = attention_mask.to(device)
63
+
64
+ with torch.no_grad():
65
+ outputs = model(input_ids=input_ids, attention_mask=attention_mask) # 可能還需要 token_type_ids
66
+
67
+ predicted_index = torch.argmax(outputs.logits, dim=1).item()
68
+ print(f"選擇的段落索引: {predicted_index}, 內容: {candidate_paragraphs[predicted_index][:100]}...")
69
+
70
+ # --- 如果是答案抽取模型 (AutoModelForQuestionAnswering) ---
71
+ # question = "問題文本"
72
+ # context = "從段落選擇模型選出的相關段落文本"
73
+
74
+ # inputs = tokenizer(question, context, return_tensors="pt", truncation=True, padding="max_length", max_length=384)
75
+ # # inputs = {k: v.to(device) for k,v in inputs.items()} # 如果使用GPU
76
+
77
+ # with torch.no_grad():
78
+ # outputs = model(**inputs)
79
+
80
+ # start_logits = outputs.start_logits
81
+ # end_logits = outputs.end_logits
82
+ # # (接下來需要 utils_qa.py 中的後處理邏輯來提取答案文本)
83
+ # # all_tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"].squeeze().tolist())
84
+ # # answer_tokens = all_tokens[torch.argmax(start_logits):torch.argmax(end_logits)+1]
85
+ # # answer = tokenizer.decode(tokenizer.convert_tokens_to_ids(answer_tokens))
86
+ # # print(f"答案: {answer}")
87
+ # # 更完整的答案提取請參考 inference_pipeline.py 中使用 postprocess_qa_predictions 的部分