Training procedure
Framework versions
- SWIFT 1.5.3
Base model information
- BaseModel Class QWenLMHeadModel
情感分析(作业)
SentimentanalysisHomework
简介:
情感分析模型,以问答形式对用户输入内容的情感倾向进行二分类
实验环境:
Ubuntu22.04-cuda12.1.0-py310-torch2.1.2-tf2.14.0-1.11.0
8核32G A10 24G显存
训练方法:
模型:qwen1_8b
数据集:jdsentimentzh
超参数:
sft_type='lora',
train_dataset_sample=2000,
- 示例代码:
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
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)
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)
- 推理效果:
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: 送货很快,书是正品,买书一直京东是首选!
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|>
[LABELS]negative
评论