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.

GitHub Stars Colab

๐Ÿ’ก 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

โš ๏ธ 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
Safetensors
Model size
2B params
Tensor type
F32
ยท
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for FutureMa/Qwen2.5-Coder-Sentiment-Freeze

Base model

Qwen/Qwen2.5-1.5B
Finetuned
(104)
this model