Qwen2.5-Coder-Sentiment-Freeze
This is a fine-tuned version of Qwen/Qwen2.5-Coder-1.5B-Instruct
specialized for Chinese sentiment analysis.
The model was trained using the efficient freeze training method on the ChnSentiCorp dataset. By training only the last 6 layers, this approach achieved a significant performance boost, increasing accuracy from 91.6% to 97.8% on the evaluation set.
This model is designed to classify Chinese text into positive (1) or negative (0) sentiment and output the result in a clean JSON format.
๐ Full Tutorial & Repository
This model was trained as part of a comprehensive, beginner-friendly tutorial that walks through every step of the process, from data preparation to evaluation and deployment.
๐ GitHub Repository: IIIIQIIII/MSJ-Factory
The repository includes:
- ๐ป A step-by-step Google Colab notebook.
- โ๏ธ All training and evaluation scripts.
- ๐ Detailed explanations of the training method and results.
If you find this model or the tutorial helpful, please give the repository a โญ๏ธ star! It helps support the author's work.
๐ก How to Use
This model follows a specific instruction format to ensure reliable JSON output. Use the prompt template below for the best results.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Model repository on Hugging Face Hub
model_name = "FutureMa/Qwen2.5-Coder-Sentiment-Freeze"
# Load tokenizer and model
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto"
)
# --- Define the text for sentiment analysis ---
text = "่ฟไธช้
ๅบ็ๆๅกๆๅบฆ้ๅธธๅฅฝ๏ผๆฟ้ดไนๅพๅนฒๅ๏ผ" # Example: "The service at this hotel was excellent, and the room was very clean!"
# --- Create the prompt using the required template ---
prompt = f"""่ฏทๅฏนไปฅไธไธญๆๆๆฌ่ฟ่กๆ
ๆๅๆ๏ผๅคๆญๅ
ถๆ
ๆๅพๅใ
ไปปๅก่ฏดๆ๏ผ
- ๅๆๆๆฌ่กจ่พพ็ๆดไฝๆ
ๆๆๅบฆ
- ๅคๆญๆฏๆญฃ้ข(1)่ฟๆฏ่ด้ข(0)
ๆๆฌๅ
ๅฎน๏ผ
```sentence
{text}
```
่พๅบๆ ผๅผ๏ผ
```json
{{
"sentiment": 0 or 1
}}
```"""
messages = [{"role": "user", "content": prompt}]
text_input = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
model_inputs = tokenizer([text_input], return_tensors="pt").to(model.device)
# --- Generate the response ---
generated_ids = model.generate(
**model_inputs,
max_new_tokens=256,
temperature=0.1
)
response = tokenizer.batch_decode(generated_ids[:, model_inputs.input_ids.shape[1]:], skip_special_tokens=True)[0]
print(f"Input Text: {text}")
print(f"Model Output:\n{response}")
# Expected output for the example text:
# Input Text: ่ฟไธช้
ๅบ็ๆๅกๆๅบฆ้ๅธธๅฅฝ๏ผๆฟ้ดไนๅพๅนฒๅ๏ผ
# Model Output:
# ```json
# {
# "sentiment": 1
# }
# ```
๐ Evaluation Results
The fine-tuned model shows significant improvements across all key metrics compared to the base model. It demonstrates perfect precision, meaning it makes no false positive predictions on the test set.
Model | Accuracy | Precision | Recall | F1-Score |
---|---|---|---|---|
Base Model (Qwen2.5-Coder-1.5B) | 91.62% | 98.57% | 83.13% | 90.20% |
This Model (Fine-tuned) | 97.77% | 100.00% | 95.18% | 97.53% |
โ๏ธ Training Details
- Base Model:
Qwen/Qwen2.5-Coder-1.5B-Instruct
- Dataset: A balanced 3,000-sample subset of ChnSentiCorp.
- Training Method: Freeze Training (only the last 6 layers and embeddings were trained).
- Framework: LLaMA-Factory
- Hardware: T4 GPU (via Google Colab)
- Training Time: ~20 minutes
โ ๏ธ Limitations and Bias
- Task-Specific: This model is highly specialized for Chinese sentiment analysis. It may not perform well on other NLP tasks or languages without further fine-tuning.
- Binary Classification: The model is designed for binary (positive/negative) classification and does not capture neutral or mixed sentiment.
- Data Bias: The model inherits any biases present in the ChnSentiCorp dataset, which primarily consists of hotel and product reviews. Its performance may vary on text from different domains.
Citation
If you use this model or the associated tutorial in your work, please cite the repository:
@misc{msj-factory-2025,
title={Qwen2.5-Coder Sentiment Analysis Fine-tuning Tutorial},
author={MASHIJIAN},
year={2025},
howpublished={\url{https://github.com/IIIIQIIII/MSJ-Factory}}
}
Acknowledgments
This work would not be possible without the incredible open-source tools and models from the community:
- Qwen Team for the powerful base model.
- Hugging Face for the
transformers
library and model hosting. - hiyouga for the excellent
LLaMA-Factory
framework. - Google Colab for providing accessible GPU resources.
- Downloads last month
- 14
Model tree for FutureMa/Qwen2.5-Coder-Sentiment-Freeze
Base model
Qwen/Qwen2.5-1.5B