模型名称与简介
- 模型: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}
评论