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