HuggingFace镜像/Sentiment-Analysis-Customer-Reviews
Model Introduction
Files & versions
Analysis

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"}

Training Details

The model was trained on the McAuley-Lab/Amazon-Reviews-2023 dataset. This dataset contains labeled customer reviews from Amazon, focusing on two primary categories: Positive and Negative.

Training Hyperparameters

  • Model: microsoft/deberta-v3-base
  • Learning Rate: 3e-5
  • Epochs: 6
  • Train Batch Size: 16
  • Gradient Accumulation Steps: 2
  • Weight Decay: 0.015
  • Warm-up Ratio: 0.1

Evaluation

The model was evaluated using a subset of the Amazon reviews dataset, focusing on the binary classification of text as either positive or negative.

Metrics

Accuracy: 0.98

Precision: 0.98

Recall: 0.99

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)