模型概述
模型特點
模型能力
使用案例
🚀 大五人格預測模型
本項目利用遷移學習和BERT BASE UNCASED模型,根據輸入文本準確預測個人的大五人格特質。該方法有效解決了人格預測中標記數據有限的問題,為了解個人性格提供了有價值的見解。
🚀 快速開始
要通過託管推理API使用該模型,請參考以下代碼片段:
from transformers import BertTokenizer, BertForSequenceClassification
def personality_detection(text):
tokenizer = BertTokenizer.from_pretrained("Minej/bert-base-personality")
model = BertForSequenceClassification.from_pretrained("Minej/bert-base-personality")
inputs = tokenizer(text, truncation=True, padding=True, return_tensors="pt")
outputs = model(**inputs)
predictions = outputs.logits.squeeze().detach().numpy()
label_names = ['Extroversion', 'Neuroticism', 'Agreeableness', 'Conscientiousness', 'Openness']
result = {label_names[i]: predictions[i] for i in range(len(label_names))}
return result
結果格式
personality_detection
函數返回一個字典,其中包含基於給定輸入文本預測的人格特質。
該字典包含以下人格特質及其對應的預測值:
- 外向性(Extroversion):一個介於 0 到 1 之間的值,表示預測的外向性特質。
- 神經質(Neuroticism):一個介於 0 到 1 之間的值,表示預測的神經質特質。
- 宜人性(Agreeableness):一個介於 0 到 1 之間的值,表示預測的宜人性特質。
- 盡責性(Conscientiousness):一個介於 0 到 1 之間的值,表示預測的盡責性特質。
- 開放性(Openness):一個介於 0 到 1 之間的值,表示預測的開放性特質。
text_input = "I am feeling excited about the upcoming event."
personality_prediction = personality_detection(text_input)
print(personality_prediction)
輸出示例:
{
"Extroversion": 0.535,
"Neuroticism": 0.576,
"Agreeableness": 0.399,
"Conscientiousness": 0.253,
"Openness": 0.563
}
注意:示例輸出中的值僅為佔位符,可能不反映實際預測結果。你可以修改示例代碼和結果格式,以匹配你的特定用例和所需的輸出格式。
✨ 主要特性
- 遷移學習:利用預訓練的 BERT BASE UNCASED 模型,通過遷移學習解決標記數據有限的問題,提高人格特質預測的準確性。
- 精準預測:基於輸入文本,準確預測個人的大五人格特質。
- 易於使用:提供簡單的 API 接口,方便用戶進行人格特質預測。
📦 安裝指南
確保你已安裝所需的依賴項(transformers
和 torch
)。你可以使用以下命令進行安裝:
pip install transformers torch
💻 使用示例
基礎用法
from transformers import BertTokenizer, BertForSequenceClassification
def personality_detection(text):
tokenizer = BertTokenizer.from_pretrained("Minej/bert-base-personality")
model = BertForSequenceClassification.from_pretrained("Minej/bert-base-personality")
inputs = tokenizer(text, truncation=True, padding=True, return_tensors="pt")
outputs = model(**inputs)
predictions = outputs.logits.squeeze().detach().numpy()
label_names = ['Extroversion', 'Neuroticism', 'Agreeableness', 'Conscientiousness', 'Openness']
result = {label_names[i]: predictions[i] for i in range(len(label_names))}
return result
text_input = "I am feeling excited about the upcoming event."
personality_prediction = personality_detection(text_input)
print(personality_prediction)
高級用法
如果你想下載模型文件並使用它們,而不是使用託管推理 API,可以參考以下代碼:
from transformers import BertForSequenceClassification, BertTokenizer
import torch
# Initialization of the model values
model = BertForSequenceClassification.from_pretrained(".", num_labels=5)
tokenizer = BertTokenizer.from_pretrained('.', do_lower_case=True)
model.config.label2id = {
"Extroversion": 0,
"Neuroticism": 1,
"Agreeableness": 2,
"Conscientiousness": 3,
"Openness": 4,
}
model.config.id2label = {
"0": "Extroversion",
"1": "Neuroticism",
"2": "Agreeableness",
"3": "Conscientiousness",
"4": "Openness",
}
def personality_detection(model_input: str) -> dict:
'''
Performs personality prediction on the given input text
Args:
model_input (str): The text conversation
Returns:
dict: A dictionary where keys are speaker labels and values are their personality predictions
'''
if len(model_input) == 0:
ret = {
"Extroversion": float(0),
"Neuroticism": float(0),
"Agreeableness": float(0),
"Conscientiousness": float(0),
"Openness": float(0),
}
return ret
else:
dict_custom = {}
preprocess_part1 = model_input[:len(model_input)]
dict1 = tokenizer.encode_plus(preprocess_part1, max_length=1024, padding=True, truncation=True)
dict_custom['input_ids'] = [dict1['input_ids'], dict1['input_ids']]
dict_custom['token_type_ids'] = [dict1['token_type_ids'], dict1['token_type_ids']]
dict_custom['attention_mask'] = [dict1['attention_mask'], dict1['attention_mask']]
outs = model(torch.tensor(dict_custom['input_ids']), token_type_ids=None, attention_mask=torch.tensor(dict_custom['attention_mask']))
b_logit_pred = outs[0]
pred_label = torch.sigmoid(b_logit_pred)
ret = {
"Extroversion": float(pred_label[0][0]),
"Neuroticism": float(pred_label[0][1]),
"Agreeableness": float(pred_label[0][2]),
"Conscientiousness": float(pred_label[0][3]),
"Openness": float(pred_label[0][4]),
}
return ret
text_input = "I am feeling excited about the upcoming event."
personality_prediction = personality_detection(text_input)
請確保你已將必要的模型文件(config.json
、pytorch_model.bin
、special_tokens_map.json
、tokenizer_config.json
、vocab.txt
)下載並放置在當前目錄(由 "." 表示)中。如有需要,請相應調整路徑和文件名。
📚 詳細文檔
模型描述
在機器學習中,當標記數據有限時,訓練準確的模型可能具有挑戰性。遷移學習通過利用來自相似任務或領域的預先標記數據提供瞭解決方案。通過將從一個任務中學到的知識遷移到另一個任務,我們可以克服數據稀缺問題並訓練更有效的模型。
在本項目中,我們使用 BERT BASE UNCASED 模型進行遷移學習,以預測大五人格特質。該模型在一個精心策劃的人格特質數據集上進行了微調,學習輸入文本和人格特徵之間的模式。通過應用遷移學習,我們提高了人格特質預測的準確性。
通過利用遷移學習和微調 BERT BASE UNCASED,我們可以根據個人的輸入文本準確預測其大五人格特質。這種方法解決了人格預測中標記數據有限的挑戰,為了解個人的性格提供了見解。
本項目展示了遷移學習在機器學習中的強大力量,並突出了 BERT BASE UNCASED 在預測大五人格特質方面的有效性。
屬性 | 詳情 |
---|---|
模型類型 | BERT BASE UNCASED |
語言 (NLP) | 英語 |
許可證 | MIT |
微調基礎模型 | https://huggingface.co/bert-base-uncased |
用途
直接使用
人格預測模型可供對根據輸入文本瞭解自己人格特質感興趣的個人直接使用。用戶可以輸入文本並獲得大五人格特質的預測結果。
下游使用
該模型不適合用於下游使用或針對特定任務進行微調。它被設計為一個獨立的人格預測模型。
超出適用範圍的使用
該模型不適用於人格預測以外的用途。不應將其用於在就業、教育或法律事務等領域對個人做出關鍵決策或判斷。
偏差、風險和侷限性
人格預測模型與任何機器學習模型一樣,存在一定的侷限性和潛在偏差,需要加以考慮:
- 上下文有限:模型僅基於輸入文本進行預測,可能無法全面捕捉個人的人格特徵。需要考慮到人格特質受文本表達之外的各種因素影響。
- 泛化能力:模型根據從特定數據集中學習到的模式預測人格特質。當應用於來自訓練數據中未充分代表的不同人口統計或文化背景的個人時,其性能可能會有所不同。
- 倫理考量:人格預測模型應負責任地使用,要理解人格特質並不能決定一個人的價值或能力。應避免根據預測的人格特質對個人做出不公平的判斷或歧視。
- 隱私問題:模型依賴用戶提供的輸入文本,其中可能包含敏感或個人信息。用戶在分享個人細節時應謹慎,並確保數據的安全性。
- 誤判:模型的預測結果可能並不總是與個人的實際人格特質完全一致。模型可能會產生誤報(預測出不存在的特質)或漏報(遺漏存在的特質)。
建議
為了減輕與人格預測模型相關的風險和侷限性,建議採取以下措施:
- 提高意識和教育:用戶應瞭解模型的侷限性和潛在偏差。促進對人格特質複雜性的理解,認識到單一模型或文本分析無法完全捕捉人格特質。
- 避免刻板印象和歧視:用戶在僅根據預測的人格特質做出判斷或決策時應謹慎。不應使用人格預測結果來歧視個人或延續刻板印象。
- 結合上下文解讀:在適當的上下文中解讀模型的預測結果,並考慮個人輸入文本之外的其他信息。
- 數據隱私和安全:確保用戶數據得到安全處理,並遵守隱私法規。用戶應瞭解自己提供的信息,並在分享個人細節時謹慎行事。
- 促進道德使用:鼓勵負責任地使用人格預測模型,反對濫用或有害應用。
需要注意的是,上述建議是一般性指導方針,應根據具體用例和倫理考量制定更具體的建議。
🔧 技術細節
本項目使用遷移學習技術,基於 BERT BASE UNCASED 模型進行微調。具體步驟如下:
- 數據準備:收集並整理人格特質數據集,用於模型的微調。
- 模型選擇:選擇 BERT BASE UNCASED 作為基礎模型,因為它在自然語言處理任務中表現出色。
- 微調模型:在人格特質數據集上對 BERT BASE UNCASED 模型進行微調,學習輸入文本和人格特徵之間的模式。
- 評估和優化:使用評估指標對微調後的模型進行評估,並根據評估結果進行優化。
通過以上步驟,我們提高了人格特質預測的準確性,解決了標記數據有限的問題。
📄 許可證
本項目採用 MIT 許可證。有關詳細信息,請參閱 LICENSE 文件。
📖 引用
@article{DBLP:journals/corr/abs-1810-04805,
author = {Jacob Devlin and
Ming{-}Wei Chang and
Kenton Lee and
Kristina Toutanova},
title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
Understanding},
journal = {CoRR},
volume = {abs/1810.04805},
year = {2018},
url = {http://arxiv.org/abs/1810.04805},
archivePrefix = {arXiv},
eprint = {1810.04805},
timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
bibsource = {dblp computer science bibliography, https://dblp.org}
}








