Bert Sentiment Analisis Indo
模型简介
该模型经过微调,专门用于印尼语文本的情感分析任务,能够准确识别文本中的情感倾向。
模型特点
高准确率
在评估数据集上取得了0.91的准确率,正面情感分类的F1分数达到0.93。
印尼语优化
专门针对印尼语文本进行微调,能够更好地理解印尼语的语言特点。
高效推理
基于BERT架构,能够在合理时间内完成文本分类任务。
模型能力
印尼语文本情感分析
二元情感分类(正面/负面)
自然语言处理
使用案例
社交媒体分析
评论情感分析
分析社交媒体上用户评论的情感倾向
准确识别正面和负面评论
客户反馈分析
产品评价分类
自动分类电商平台上的产品评价
帮助企业快速了解客户满意度
🚀 基于BERT的印尼语情感分析模型
本仓库包含一个经过微调的BERT模型,用于进行情感分析。该模型经过训练,可将文本分为两种情感类别:0(负面)和1(正面)。以下是该模型的性能和训练细节总结。
🚀 快速开始
安装依赖
确保你已经安装了必要的库:
pip install transformers torch
加载模型
你可以使用transformers
库加载经过微调的BERT模型:
from transformers import BertForSequenceClassification, BertTokenizer
## 加载经过微调的模型和分词器
model = BertForSequenceClassification.from_pretrained("path_to_model")
tokenizer = BertTokenizer.from_pretrained("path_to_tokenizer")
预处理和预测
对你的输入文本进行预处理并进行预测:
# prompt: use this model to predict a sentence with output sentiment negatif or positif
from transformers import BertTokenizer, BertForSequenceClassification
import torch
# 加载保存的模型和分词器
model_path = 'bibrani/bert-sentiment-analisis-indo'
tokenizer = BertTokenizer.from_pretrained(model_path)
model = BertForSequenceClassification.from_pretrained(model_path)
# 设置设备
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
print(device)
def predict_sentiment(text):
"""预测给定文本的情感。
参数:
text (str): 输入文本。
返回:
str: "Negative sentiment" 或 "Positive sentiment"。
"""
# 对输入文本进行分词
inputs = tokenizer(text, padding="max_length", truncation=True, max_length=512, return_tensors="pt")
# 将输入移动到设备上
input_ids = inputs.input_ids.to(device)
attention_mask = inputs.attention_mask.to(device)
# 进行推理
with torch.no_grad():
outputs = model(input_ids, attention_mask=attention_mask)
logits = outputs.logits
# 获取预测的类别
predicted_class = torch.argmax(logits, dim=1).item()
if predicted_class == 0:
return "Negative sentiment", inputs
else:
return "Positive sentiment", inputs
# 示例用法
text_to_predict = "jadi cerita nya saya sedang ingin makan spaghetti dengan meatball yang kalau menurut ekspektasi saya adalah bakso yang terbuat dari cingcang yang biasa digunakan di menu pasta , setelah sampai , ternyata bakso yang digunakan adalah bakso olahan yang biasa dipakai di tukang bakso , bahkan bentuk nya tidak bulat"
sentiment = predict_sentiment(text_to_predict)
print(f"Text: {text_to_predict}")
print(f"Sentiment: {sentiment}")
✨ 主要特性
该模型能够对印尼语文本进行情感分析,将其分类为积极或消极情感,在评估数据集上取得了较好的性能。
📦 安装指南
确保你已经安装了必要的库:
pip install transformers torch
💻 使用示例
基础用法
from transformers import BertForSequenceClassification, BertTokenizer
## 加载经过微调的模型和分词器
model = BertForSequenceClassification.from_pretrained("path_to_model")
tokenizer = BertTokenizer.from_pretrained("path_to_tokenizer")
高级用法
# prompt: use this model to predict a sentence with output sentiment negatif or positif
from transformers import BertTokenizer, BertForSequenceClassification
import torch
# 加载保存的模型和分词器
model_path = 'bibrani/bert-sentiment-analisis-indo'
tokenizer = BertTokenizer.from_pretrained(model_path)
model = BertForSequenceClassification.from_pretrained(model_path)
# 设置设备
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model.to(device)
print(device)
def predict_sentiment(text):
"""预测给定文本的情感。
参数:
text (str): 输入文本。
返回:
str: "Negative sentiment" 或 "Positive sentiment"。
"""
# 对输入文本进行分词
inputs = tokenizer(text, padding="max_length", truncation=True, max_length=512, return_tensors="pt")
# 将输入移动到设备上
input_ids = inputs.input_ids.to(device)
attention_mask = inputs.attention_mask.to(device)
# 进行推理
with torch.no_grad():
outputs = model(input_ids, attention_mask=attention_mask)
logits = outputs.logits
# 获取预测的类别
predicted_class = torch.argmax(logits, dim=1).item()
if predicted_class == 0:
return "Negative sentiment", inputs
else:
return "Positive sentiment", inputs
# 示例用法
text_to_predict = "jadi cerita nya saya sedang ingin makan spaghetti dengan meatball yang kalau menurut ekspektasi saya adalah bakso yang terbuat dari cingcang yang biasa digunakan di menu pasta , setelah sampai , ternyata bakso yang digunakan adalah bakso olahan yang biasa dipakai di tukang bakso , bahkan bentuk nya tidak bulat"
sentiment = predict_sentiment(text_to_predict)
print(f"Text: {text_to_predict}")
print(f"Sentiment: {sentiment}")
📚 详细文档
模型性能总结
该模型在评估数据集上取得了以下性能指标:
类别 | 精确率 | 召回率 | F1分数 | 样本数 |
---|---|---|---|---|
0 | 0.88 | 0.84 | 0.86 | 799 |
1 | 0.92 | 0.94 | 0.93 | 1467 |
准确率:0.91
宏平均 | 加权平均 |
---|---|
精确率 = 0.90 召回率 = 0.89 F1分数 = 0.90 | 精确率 = 0.90 召回率 = 0.91 F1分数 = 0.90 |
训练详情
属性 | 详情 |
---|---|
模型架构 | BERT(来自Transformer的双向编码器表示) |
任务 | 情感分析(二分类) |
训练轮数 | 5 |
硬件 | NVIDIA A100 GPU |
结果解释
类别0:表示负面情感。 类别1:表示正面情感。
该模型在两个类别上都表现出色,对于正面情感(类别1)的精确率和召回率略高。
🔧 技术细节
该模型基于BERT架构,通过在特定的印尼语情感分析数据集上进行5轮训练得到。使用NVIDIA A100 GPU进行加速训练,最终在评估数据集上取得了较好的性能。
📄 许可证
本项目采用MIT许可证。
Distilbert Base Uncased Finetuned Sst 2 English
Apache-2.0
基于DistilBERT-base-uncased在SST-2情感分析数据集上微调的文本分类模型,准确率91.3%
文本分类 英语
D
distilbert
5.2M
746
Xlm Roberta Base Language Detection
MIT
基于XLM-RoBERTa的多语言检测模型,支持20种语言的文本分类
文本分类
Transformers 支持多种语言

X
papluca
2.7M
333
Roberta Hate Speech Dynabench R4 Target
该模型通过动态生成数据集来改进在线仇恨检测,专注于从最差案例中学习以提高检测效果。
文本分类
Transformers 英语

R
facebook
2.0M
80
Bert Base Multilingual Uncased Sentiment
MIT
基于bert-base-multilingual-uncased微调的多语言情感分析模型,支持6种语言的商品评论情感分析
文本分类 支持多种语言
B
nlptown
1.8M
371
Emotion English Distilroberta Base
基于DistilRoBERTa-base微调的英文文本情感分类模型,可预测埃克曼六种基本情绪及中性类别。
文本分类
Transformers 英语

E
j-hartmann
1.1M
402
Robertuito Sentiment Analysis
基于RoBERTuito的西班牙语推文情感分析模型,支持POS(积极)/NEG(消极)/NEU(中性)三类情感分类
文本分类 西班牙语
R
pysentimiento
1.0M
88
Finbert Tone
FinBERT是一款基于金融通讯文本预训练的BERT模型,专注于金融自然语言处理领域。finbert-tone是其微调版本,用于金融情感分析任务。
文本分类
Transformers 英语

F
yiyanghkust
998.46k
178
Roberta Base Go Emotions
MIT
基于RoBERTa-base的多标签情感分类模型,在go_emotions数据集上训练,支持28种情感标签识别。
文本分类
Transformers 英语

R
SamLowe
848.12k
565
Xlm Emo T
XLM-EMO是一个基于XLM-T模型微调的多语言情感分析模型,支持19种语言,专门针对社交媒体文本的情感预测。
文本分类
Transformers 其他

X
MilaNLProc
692.30k
7
Deberta V3 Base Mnli Fever Anli
MIT
基于MultiNLI、Fever-NLI和ANLI数据集训练的DeBERTa-v3模型,擅长零样本分类和自然语言推理任务
文本分类
Transformers 英语

D
MoritzLaurer
613.93k
204
精选推荐AI模型
Llama 3 Typhoon V1.5x 8b Instruct
专为泰语设计的80亿参数指令模型,性能媲美GPT-3.5-turbo,优化了应用场景、检索增强生成、受限生成和推理任务
大型语言模型
Transformers 支持多种语言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一个基于SODA数据集训练的超小型对话模型,专为边缘设备推理设计,体积仅为Cosmo-3B模型的2%左右。
对话系统
Transformers 英语

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基于RoBERTa架构的中文抽取式问答模型,适用于从给定文本中提取答案的任务。
问答系统 中文
R
uer
2,694
98