感情分类模型

我要开发同款
匿名用户2024年07月31日
40阅读
所属分类ai
开源地址https://modelscope.cn/models/swordlesszzj/emotion-classify
授权协议Apache License 2.0

作品详情

情感分类模型(Emotion Classification Model)

简介

输⼊⼀段⽂本, 模型可以给出对应的情感分类。分类为二分类,将情感分为积极(positive)和消极(negative)。

实验环境

魔搭社区GPU环境

  • 8核 32GB 显存24G
  • 预装 ModelScope Library
  • 预装镜像 ubuntu22.04-cuda12.1.0-py310-torch2.1.2-tf2.14.0-1.11.0

训练方法

数据集

基于深度学习(LSTM)的情感分析(京东商城数据)jd_sentiment_zh

示例代码

# 设置pip全局镜像
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
# 安装ms-swift
git clone https://github.com/modelscope/swift.git
cd swift
pip install -e .[llm]
# It requires 5 minutes of training.
# Experimental environment: A10
# 13GB GPU memory
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
import torch
from swift.llm import (
DatasetName, InferArguments, ModelType, SftArguments,
infer_main, sft_main, app_ui_main, merge_lora_main
)
model_type = ModelType.qwen_1_8b
# 超参数:
# https://github.com/modelscope/swift/blob/main/docs/source/LLM/%E5%91%BD%E4%BB%A
# 4%E8%A1%8C%E5%8F%82%E6%95%B0.md
sft_args = SftArguments(
    model_type=model_type,
    sft_type='lora',
    train_dataset_sample=2000,
    dataset=[DatasetName.jd_sentiment_zh],
    output_dir='output')
result = sft_main(sft_args)
# adapter的⼤⼩: 6.1MiB
best_model_checkpoint = result['best_model_checkpoint']
print(f'best_model_checkpoint: {best_model_checkpoint}')
torch.cuda.empty_cache()
infer_args = InferArguments(
    ckpt_dir=best_model_checkpoint,
    load_dataset_config=True,
    do_sample=False)
result = infer_main(infer_args)

推理效果

positive<|endoftext|>

[LABELS]positive

[PROMPT]Task: Sentiment Classification \ Sentence: 店家太不负责任了,衣服质量太差劲了,和图片上的不一样 \ Category: negative, positive \ Output: [OUTPUT]negative<|endoftext|>

[LABELS]negative

[PROMPT]Task: Sentiment Classification \ Sentence: 送国际友人挺好的,不错不错! \ Category: negative, positive \ Output: [OUTPUT]positive<|endoftext|>

[LABELS]positive

[PROMPT]Task: Sentiment Classification \ Sentence: 很好,装好一定很漂亮 \ Category: negative, positive \ Output: [OUTPUT]positive<|endoftext|>

[LABELS]positive

[PROMPT]Task: Sentiment Classification \ Sentence: 东西给你退回去了,你要黑我钱!!! \ Category: negative, positive \ Output: [OUTPUT]

negative<|endoftext|>

[LABELS]negative

[PROMPT]Task: Sentiment Classification \ Sentence: 送货很快,书是正品,买书一直京东是首选! \ Category: negative, positive \ Output: [OUTPUT]positive<|endoftext|>

[LABELS]positive

[PROMPT]Task: Sentiment Classification \ Sentence: 口感相当的好 都想买第二次了 \ Category: negative, positive \ Output: [OUTPUT]positive<|endoftext|>

[LABELS]positive

[PROMPT]Task: Sentiment Classification \ Sentence: 硅胶味道太重,样子与图片差距太大 \ Category: negative, positive \ Output: [OUTPUT]negative<|endoftext|>

[LABELS]negative

[PROMPT]Task: Sentiment Classification \ Sentence: 很伤心,买了放到三星n4尽然不能用,客服各种推 \ Category: negative, positive \ Output: [OUTPUT]negative<|endoftext|>

[LABELS]negative

[PROMPT]Task: Sentiment Classification \ Sentence: 质量不错,大小合适,应当是正品!但是我买的是黑灰,发来的却是纯黑,懒得换了,给个差评,希望以后改进! \ Category: negative, positive \ Output: [OUTPUT]positive<|endoftext|> [INFO:swift] saveresultpath: /mnt/workspace/output/qwen-18b/v0-20240126-230928/checkpoint-100/inferresult_20240126-231510.jsonl

[LABELS]negative

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论