disaster-tweet-bert / README.md
Operaer's picture
Add model card
80155c3 verified
|
Raw History Blame Contribute Delete
1.59 kB
metadata
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

使用方式

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。