符露露的情感分类模型

我要开发同款
匿名用户2024年07月31日
33阅读
所属分类aipytorch
开源地址https://modelscope.cn/models/fululu2/SentimentAnalysis

作品详情

模型名称与简介

  • 模型:Sentiment Analysis(情感分类模型)
  • 简介:输入一段文本,模型可以给出对应的情感分类,该模型不需要支持多轮对话,对应的情感分类的类别可以根据选择的数据集进行自行设计,可以是二分类,也可以是多分类。

实验环境

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

训练方法

  • 模型选择:ModelType.qwen18b
  • 使用的数据集:DatasetName.jdsentimentzh
  • 超参数设置:详见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

示例代码

import os

os.environ['CUDAVISIBLEDEVICES'] = '0'

import torch

from swift.llm import (

DatasetName, InferArguments, ModelType, SftArguments,

infermain, sftmain, appuimain, mergeloramain

)

modeltype = ModelType.qwen1_8b

sft_args = SftArguments(

modeltype=modeltype,

sft_type='lora',

traindatasetsample=2000,

dataset=[DatasetName.jdsentimentzh],

output_dir='output')

result = sftmain(sftargs)

bestmodelcheckpoint = result['bestmodelcheckpoint']

print(f'bestmodelcheckpoint: {bestmodelcheckpoint}')

torch.cuda.empty_cache()

infer_args = InferArguments(

ckptdir=bestmodel_checkpoint,

loaddatasetconfig=True,

do_sample=False)

result = infermain(inferargs)

运行结果

{'loss': 0.12845068, 'acc': 0.95, 'learningrate': 8.47e-06, 'epoch': 0.92, 'globalstep': 115}

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

评论