Upload stance analysis model - 2025-09-07 23:28:46
Browse files- README.md +139 -3
- config.json +39 -0
- model.safetensors +3 -0
- special_tokens_map.json +7 -0
- tokenizer_config.json +58 -0
- vocab.txt +0 -0
README.md
CHANGED
@@ -1,3 +1,139 @@
|
|
1 |
-
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: zh
|
3 |
+
library_name: transformers
|
4 |
+
pipeline_tag: text-classification
|
5 |
+
tags:
|
6 |
+
- bert
|
7 |
+
- chinese
|
8 |
+
- stance-analysis
|
9 |
+
- text-classification
|
10 |
+
- pytorch
|
11 |
+
- safetensors
|
12 |
+
datasets:
|
13 |
+
- custom-stance-dataset
|
14 |
+
metrics:
|
15 |
+
- accuracy
|
16 |
+
- f1
|
17 |
+
model-index:
|
18 |
+
- name: stance-ch
|
19 |
+
results:
|
20 |
+
- task:
|
21 |
+
type: text-classification
|
22 |
+
name: Stance Analysis
|
23 |
+
dataset:
|
24 |
+
type: custom
|
25 |
+
name: Chinese Stance Dataset
|
26 |
+
metrics:
|
27 |
+
- type: accuracy
|
28 |
+
value: N/A
|
29 |
+
name: Test Accuracy
|
30 |
+
- type: accuracy
|
31 |
+
value: N/A
|
32 |
+
name: Validation Accuracy
|
33 |
+
---
|
34 |
+
|
35 |
+
# Chinese BERT for Stance Analysis (立场分析)
|
36 |
+
|
37 |
+
这是一个基于BERT的中文立场分析模型,能够识别文本中表达的支持(SUPPORTIVE)或反对(OPPOSING)立场。
|
38 |
+
|
39 |
+
## 模型信息
|
40 |
+
|
41 |
+
- **模型基础**: bert-base-chinese
|
42 |
+
- **任务类型**: 二分类文本分类
|
43 |
+
- **语言**: 中文 (Chinese)
|
44 |
+
- **训练数据**: 包含6,668条立场标注数据
|
45 |
+
- **标签**: OPPOSING (反对), SUPPORTIVE (支持)
|
46 |
+
|
47 |
+
## 性能指标
|
48 |
+
|
49 |
+
| 指标 | 数值 |
|
50 |
+
|------|------|
|
51 |
+
| 验证集准确率 | N/A |
|
52 |
+
| 测试集准确率 | N/A |
|
53 |
+
| 训练轮数 | N/A |
|
54 |
+
|
55 |
+
## 使用方法
|
56 |
+
|
57 |
+
```python
|
58 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
59 |
+
import torch
|
60 |
+
|
61 |
+
# 加载模型和tokenizer
|
62 |
+
model_name = "FutureMa/stance_ch"
|
63 |
+
tokenizer = BertTokenizer.from_pretrained(model_name)
|
64 |
+
model = BertForSequenceClassification.from_pretrained(model_name)
|
65 |
+
|
66 |
+
# 示例预测
|
67 |
+
def predict_stance(text):
|
68 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
69 |
+
|
70 |
+
with torch.no_grad():
|
71 |
+
outputs = model(**inputs)
|
72 |
+
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
73 |
+
predicted_class = torch.argmax(predictions, dim=-1).item()
|
74 |
+
|
75 |
+
labels = {"0": "OPPOSING", "1": "SUPPORTIVE"}
|
76 |
+
confidence = predictions[0][predicted_class].item()
|
77 |
+
|
78 |
+
return {
|
79 |
+
"stance": labels[str(predicted_class)],
|
80 |
+
"confidence": confidence
|
81 |
+
}
|
82 |
+
|
83 |
+
# 使用示例
|
84 |
+
text = "我完全支持这个政策,它对社会发展有积极作用。"
|
85 |
+
result = predict_stance(text)
|
86 |
+
print(f"立场: {result['stance']}, 置信度: {result['confidence']:.4f}")
|
87 |
+
```
|
88 |
+
|
89 |
+
## 数据格式
|
90 |
+
|
91 |
+
训练数据采用以下格式:
|
92 |
+
```
|
93 |
+
topic: [话题内容]
|
94 |
+
answer: [回答内容]
|
95 |
+
```
|
96 |
+
|
97 |
+
模型基于回答内容判断其对话题的立场。
|
98 |
+
|
99 |
+
## 标签说明
|
100 |
+
|
101 |
+
- `OPPOSING` (0): 反对立场
|
102 |
+
- `SUPPORTIVE` (1): 支持立场
|
103 |
+
|
104 |
+
## 训练详情
|
105 |
+
|
106 |
+
- **优化器**: AdamW
|
107 |
+
- **学习率**: 2e-5
|
108 |
+
- **批次大小**: 16
|
109 |
+
- **最大序列长度**: 512
|
110 |
+
- **早停策略**: 验证集准确率连续3轮无提升
|
111 |
+
- **数据划分**: 训练集 6,268 / 验证集 200 / 测试集 200
|
112 |
+
|
113 |
+
## 注意事项
|
114 |
+
|
115 |
+
1. 模型主要针对中文文本训练
|
116 |
+
2. 最佳输入长度为512个token以内
|
117 |
+
3. 模型对政治、社会话题的立场分析效果较好
|
118 |
+
4. 建议在使用前对特定领域数据进行微调
|
119 |
+
|
120 |
+
## 许可证
|
121 |
+
|
122 |
+
本模型遵循Apache-2.0许可证。
|
123 |
+
|
124 |
+
## 引用
|
125 |
+
|
126 |
+
如果使用本模型,请引用:
|
127 |
+
```bibtex
|
128 |
+
@misc{stance_ch_2025,
|
129 |
+
title={Chinese BERT for Stance Analysis},
|
130 |
+
author={FutureMa},
|
131 |
+
year={2025},
|
132 |
+
publisher={Hugging Face},
|
133 |
+
url={https://huggingface.co/FutureMa/stance_ch}
|
134 |
+
}
|
135 |
+
```
|
136 |
+
|
137 |
+
---
|
138 |
+
|
139 |
+
*模型训练时间: 2025年09月07日*
|
config.json
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"BertForMaskedLM"
|
4 |
+
],
|
5 |
+
"attention_probs_dropout_prob": 0.1,
|
6 |
+
"classifier_dropout": null,
|
7 |
+
"directionality": "bidi",
|
8 |
+
"hidden_act": "gelu",
|
9 |
+
"hidden_dropout_prob": 0.1,
|
10 |
+
"hidden_size": 768,
|
11 |
+
"id2label": {
|
12 |
+
"0": "OPPOSING",
|
13 |
+
"1": "SUPPORTIVE"
|
14 |
+
},
|
15 |
+
"initializer_range": 0.02,
|
16 |
+
"intermediate_size": 3072,
|
17 |
+
"label2id": {
|
18 |
+
"OPPOSING": 0,
|
19 |
+
"SUPPORTIVE": 1
|
20 |
+
},
|
21 |
+
"layer_norm_eps": 1e-12,
|
22 |
+
"max_position_embeddings": 512,
|
23 |
+
"model_type": "bert",
|
24 |
+
"num_attention_heads": 12,
|
25 |
+
"num_hidden_layers": 12,
|
26 |
+
"pad_token_id": 0,
|
27 |
+
"pooler_fc_size": 768,
|
28 |
+
"pooler_num_attention_heads": 12,
|
29 |
+
"pooler_num_fc_layers": 3,
|
30 |
+
"pooler_size_per_head": 128,
|
31 |
+
"pooler_type": "first_token_transform",
|
32 |
+
"position_embedding_type": "absolute",
|
33 |
+
"problem_type": "single_label_classification",
|
34 |
+
"torch_dtype": "float32",
|
35 |
+
"transformers_version": "4.52.4",
|
36 |
+
"type_vocab_size": 2,
|
37 |
+
"use_cache": true,
|
38 |
+
"vocab_size": 21128
|
39 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3b87945a5870efc3849933dbb40cf3d1792915436469f8c4e0aa9579d9798ead
|
3 |
+
size 409100208
|
special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
tokenizer_config.json
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"added_tokens_decoder": {
|
3 |
+
"0": {
|
4 |
+
"content": "[PAD]",
|
5 |
+
"lstrip": false,
|
6 |
+
"normalized": false,
|
7 |
+
"rstrip": false,
|
8 |
+
"single_word": false,
|
9 |
+
"special": true
|
10 |
+
},
|
11 |
+
"100": {
|
12 |
+
"content": "[UNK]",
|
13 |
+
"lstrip": false,
|
14 |
+
"normalized": false,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": false,
|
17 |
+
"special": true
|
18 |
+
},
|
19 |
+
"101": {
|
20 |
+
"content": "[CLS]",
|
21 |
+
"lstrip": false,
|
22 |
+
"normalized": false,
|
23 |
+
"rstrip": false,
|
24 |
+
"single_word": false,
|
25 |
+
"special": true
|
26 |
+
},
|
27 |
+
"102": {
|
28 |
+
"content": "[SEP]",
|
29 |
+
"lstrip": false,
|
30 |
+
"normalized": false,
|
31 |
+
"rstrip": false,
|
32 |
+
"single_word": false,
|
33 |
+
"special": true
|
34 |
+
},
|
35 |
+
"103": {
|
36 |
+
"content": "[MASK]",
|
37 |
+
"lstrip": false,
|
38 |
+
"normalized": false,
|
39 |
+
"rstrip": false,
|
40 |
+
"single_word": false,
|
41 |
+
"special": true
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"clean_up_tokenization_spaces": true,
|
45 |
+
"cls_token": "[CLS]",
|
46 |
+
"do_basic_tokenize": true,
|
47 |
+
"do_lower_case": false,
|
48 |
+
"extra_special_tokens": {},
|
49 |
+
"mask_token": "[MASK]",
|
50 |
+
"model_max_length": 512,
|
51 |
+
"never_split": null,
|
52 |
+
"pad_token": "[PAD]",
|
53 |
+
"sep_token": "[SEP]",
|
54 |
+
"strip_accents": null,
|
55 |
+
"tokenize_chinese_chars": true,
|
56 |
+
"tokenizer_class": "BertTokenizer",
|
57 |
+
"unk_token": "[UNK]"
|
58 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|