Operaer commited on
Commit
80155c3
·
verified ·
1 Parent(s): 9fc17ac

Add model card

Browse files
Files changed (1) hide show
  1. README.md +62 -0
README.md ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ license: apache-2.0
5
+ base_model: bert-base-uncased
6
+ pipeline_tag: text-classification
7
+ tags:
8
+ - text-classification
9
+ - bert
10
+ - disaster-tweets
11
+ - kaggle
12
+ datasets:
13
+ - startificial/nlp-getting-started
14
+ metrics:
15
+ - accuracy
16
+ - f1
17
+ ---
18
+
19
+ # Disaster Tweet Detection(灾难推文检测)
20
+
21
+ 基于 `bert-base-uncased` 微调的英文推文二分类模型,判断一条推文是否**关于真实灾难**
22
+ (Kaggle 竞赛 *Real or Not? NLP with Disaster Tweets*,`nlp-getting-started`)。
23
+
24
+ ## 训练数据
25
+
26
+ - 来源:Kaggle 灾难推文数据集(7613 条训练样本)
27
+ - 标签:0 = 非灾难推文,1 = 灾难推文
28
+ - 训练:2 个 epoch,lr=2e-5,batch=16,max_len=128
29
+
30
+ ## 验证集指标
31
+
32
+ | 指标 | 数值 |
33
+ | --- | --- |
34
+ | Accuracy | **0.8451** |
35
+ | F1 (binary) | **0.8168** |
36
+ | Precision | 0.8297 |
37
+ | Recall | 0.8043 |
38
+
39
+ ## 使用方式
40
+
41
+ ```python
42
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
43
+ import torch
44
+
45
+ model_id = "Operaer/disaster-tweet-bert"
46
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
47
+ model = AutoModelForSequenceClassification.from_pretrained(model_id)
48
+ model.eval()
49
+
50
+ text = "Forest fire near La Ronge Sask. Canada"
51
+ enc = tokenizer(text, truncation=True, padding=True,
52
+ max_length=128, return_tensors="pt")
53
+ with torch.no_grad():
54
+ logits = model(**enc).logits
55
+ pred = int(torch.argmax(logits, dim=1))
56
+ print("灾难推文" if pred == 1 else "非灾难推文")
57
+ ```
58
+
59
+ ## 说明
60
+
61
+ - 本模型为《自然语言处理》课程作业产物;
62
+ - 微调代码:`train.py`;交互式 Demo:`app.py` / Gradio Space。