🚀 2020年美國推特大選針對拜登立場檢測的預訓練BERT模型(KE - MLM)
本項目提供了用於立場檢測的知識增強掩碼語言模型(NAACL 2021)中KE - MLM模型的預訓練權重。該模型可用於檢測針對喬·拜登的立場,具有重要的政治分析價值。
✨ 主要特性
- 基於超500萬條關於2020年美國總統大選的英文推文進行預訓練。
- 利用立場標註數據針對喬·拜登的立場檢測進行微調。
- 以BERT - base為基礎初始化,通過正常的MLM目標進行訓練,並針對喬·拜登的立場檢測對分類層進行微調。
📦 安裝指南
文檔未提及具體安裝步驟,可參考官方倉庫獲取安裝相關信息。
💻 使用示例
基礎用法
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
import numpy as np
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
pretrained_LM_path = "kornosk/bert-election2020-twitter-stance-biden-KE-MLM"
tokenizer = AutoTokenizer.from_pretrained(pretrained_LM_path)
model = AutoModelForSequenceClassification.from_pretrained(pretrained_LM_path)
id2label = {
0: "AGAINST",
1: "FAVOR",
2: "NONE"
}
sentence = "Hello World."
inputs = tokenizer(sentence.lower(), return_tensors="pt")
outputs = model(**inputs)
predicted_probability = torch.softmax(outputs[0], dim=1)[0].tolist()
print("Sentence:", sentence)
print("Prediction:", id2label[np.argmax(predicted_probability)])
print("Against:", predicted_probability[0])
print("Favor:", predicted_probability[1])
print("Neutral:", predicted_probability[2])
sentence = "Go Go Biden!!!"
inputs = tokenizer(sentence.lower(), return_tensors="pt")
outputs = model(**inputs)
predicted_probability = torch.softmax(outputs[0], dim=1)[0].tolist()
print("Sentence:", sentence)
print("Prediction:", id2label[np.argmax(predicted_probability)])
print("Against:", predicted_probability[0])
print("Favor:", predicted_probability[1])
print("Neutral:", predicted_probability[2])
sentence = "Biden is the worst."
inputs = tokenizer(sentence.lower(), return_tensors="pt")
outputs = model(**inputs)
predicted_probability = torch.softmax(outputs[0], dim=1)[0].tolist()
print("Sentence:", sentence)
print("Prediction:", id2label[np.argmax(predicted_probability)])
print("Against:", predicted_probability[0])
print("Favor:", predicted_probability[1])
print("Neutral:", predicted_probability[2])
📚 詳細文檔
此預訓練語言模型針對喬·拜登的立場檢測任務進行了微調。更多詳細信息請參考官方倉庫。
🔧 技術細節
訓練數據
該模型在超過500萬條關於2020年美國總統大選的英文推文上進行預訓練,然後使用我們的立場標註數據針對喬·拜登的立場檢測進行微調。
訓練目標
模型以BERT - base為基礎進行初始化,使用正常的MLM目標進行訓練,並針對喬·拜登的立場檢測對分類層進行微調。
📄 許可證
本項目採用GPL - 3.0許可證。
📖 參考資料
📚 引用格式
@inproceedings{kawintiranon2021knowledge,
title={Knowledge Enhanced Masked Language Model for Stance Detection},
author={Kawintiranon, Kornraphop and Singh, Lisa},
booktitle={Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies},
year={2021},
publisher={Association for Computational Linguistics},
url={https://www.aclweb.org/anthology/2021.naacl-main.376}
}