HuggingFace镜像/Sentiment-Analysis-Customer-Reviews
模型介绍文件和版本分析
下载使用量0

openmind使用教程

from openmind import AutoTokenizer, AutoModel, is_torch_npu_available,pipeline
from openmind_hub import snapshot_download
import torch
import argparse
import torch.nn.functional as F


# 均值池化 - 考虑注意力掩码以进行正确的平均
def mean_pooling(model_output, attention_mask):
    token_embeddings = model_output[0] # model_output的第一个元素包含所有token嵌入
    input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
    return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)

def parse_args():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--model_name_or_path",
        type=str,
        help="Path to model",
        default="../",
    )
    args = parser.parse_args()
    return args

def main():
    args = parse_args()
    model_path = args.model_name_or_path

    if is_torch_npu_available():
        device = "npu:0"
    else:
        device = "cpu"

    # 我们想要获取句子嵌入的句子
    sentences = ['This is an example sentence', 'Each sentence is converted']

    classifier = pipeline("text-classification", model="../")

    result = classifier("The product didn't arrive on time and was damaged.")
    print(result)


if __name__ == "__main__":
    main()

sentiment_mapping = {1: "Negative", 0: "Positive"}

训练详情

该模型在McAuley-Lab/Amazon-Reviews-2023数据集上进行训练。此数据集包含来自亚马逊的带标签客户评论,主要分为两类:正面(Positive)和负面(Negative)。

训练超参数

  • 模型:microsoft/deberta-v3-base
  • 学习率:3e-5
  • 训练轮次:6
  • 训练批次大小:16
  • 梯度累积步数:2
  • 权重衰减:0.015
  • 预热比例:0.1

评估

模型使用亚马逊评论数据集的一个子集进行评估,主要任务是将文本进行二元分类,即分为正面或负面。

评估指标

准确率(Accuracy):0.98

精确率(Precision):0.98

召回率(Recall):0.99

F1分数(F1-Score):0.98

from transformers import pipeline

classifier = pipeline("text-classification", model="dnzblgn/Sentiment-Analysis-Customer-Reviews")
result = classifier("The product didn't arrive on time and was damaged.")
print(result)