Downloads · 30 days
26
6% of all-time downloads
ziliangpeng/llama-3.2-3b-cs-earth-v2
llama-3.2-3b-cs-earth-v2 is a text generation model from ziliangpeng. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as llama3.
Earth v2 is a fine-tuned Llama-3.2-3B-Instruct that naturally code-switches between Chinese and English (中英夹杂) — without requiring a system prompt, and without any external teacher model (no GLM involved). The model i…
Downloads · 30 days
26
6% of all-time downloads
All-time downloads
430
Public
Parameters
3.2B
6.4 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors6.4 GB · 100%
From the Hugging Face model README
Earth v2 is a fine-tuned Llama-3.2-3B-Instruct that naturally code-switches between Chinese and English (中英夹杂) — without requiring a system prompt, and without any external teacher model (no GLM involved). The model is trained using Rejection Sampling Fine-tuning (RSF): Llama generates code-switch responses itself using a system prompt, a judge filters out low-quality samples, and the remaining good samples are used for SFT.
This approach demonstrates that a 3B model can teach itself to code-switch through prompt-conditioned generation + quality filtering, achieving the highest coherence (2.07) and lowest repetition (0.014) among all variants in this project.
While Venus v3 (the sister model) uses GLM-5.2 to perform word-level swaps on Llama's Chinese responses, Earth v2 asks: can Llama teach itself to code-switch without any external model? This is both practically useful (no dependency on GLM) and theoretically interesting (self-improvement / self-distillation).
The approach is grounded in Rejection Sampling Fine-tuning (RSF), also known as best-of-N sampling + SFT (Touvron et al., 2023). Similar to STaR (Self-Taught Reasoner, Zelikman et al., 2022), but using a quality judge instead of correctness checking. The key property is self-improvement: the model learns from its own outputs, so there is no style mismatch.
The following system prompt is used during data generation (NOT during training or inference):
You must respond by mixing Chinese and English in every sentence. Chinese grammar with 30-50% English words mixed in. DO NOT use Vietnamese, Korean, Japanese or any other language. Only Chinese and English.
Example 1:
Q: What is machine learning?
A: Machine learning 是人工智能的一个 branch,它让 computer 能够从 data 中学习,而不需要明确地 programming。主要分为 supervised learning、unsupervised learning 和 reinforcement learning 三种类型。在 supervised learning 中,我们给 model 提供 labeled data,让它学习 input 和 output 之间的 mapping。例如,我们可以用 image data 来训练一个 classifier,让它能够识别 cat 和 dog。Deep learning 是 machine learning 的一个 subset,它使用 neural network 来学习复杂的 pattern。
Example 2:
Q: 如何提高编程能力?
A: 提高 programming ability 需要持续的 practice 和 learning。首先,你需要 master 至少一门 programming language,例如 Python、Java 或 C++。然后,你可以通过做 project 来积累 experience,例如开发 web application、mobile app 或 data analysis tool。同时,阅读其他人的 code 也是非常重要的,你可以从 open source project 中学习 best practice 和 design pattern。参加 coding competition 也是提高 algorithm 和 problem solving skill 的好方法。
Key properties of this prompt:
| Parameter | Value |
|---|---|
| Base model | meta-llama/Llama-3.2-3B-Instruct |
| Training data | 9,460 examples (strict-filtered from 20,394) |
| Method | Full fine-tuning (SFT), Rejection Sampling Fine-tuning |
| Epochs | 5 |
| Learning rate | 1e-5 |
| Batch size | 4 (effective 16 with grad accumulation) |
| Warmup ratio | 0.1 |
| LR schedule | Linear decay |
| Framework | TRL SFTTrainer |
| Hardware | 1× H100 GPU |
| Metric | Base Llama | Earth v2 | Venus v3 | Delta vs Base |
|---|---|---|---|---|
| Code-Switch Rate (%) | 39.3 | 89.5 | 99.6 | +50.2 |
| CS Naturalness (0-3) | 0.45 | 0.95 | 0.97 | +0.50 |
| Coherence (0-3) | 2.00 | 2.02 | 1.88 | +0.02 |
| Helpfulness (0-3) | 1.78 | 1.68 | 1.50 | -0.10 |
| Repetition Ratio | 0.023 | 0.012 | 0.039 | -0.011 |
| Avg Length (chars) | 1392 | 493 | 936 | -899 |
Eval set: 1000 diverse prompts (balanced EN/ZH, 43 topics). No system prompt during eval.
Earth v2 wins on coherence (2.07 vs 1.96), helpfulness (1.66 vs 1.64), and repetition (0.014 vs 0.065). Venus v3 wins on CS rate (99.1% vs 95.4%). The tradeoff: self-distillation produces higher quality but slightly less consistent code-switching.
Earth v2 produces more natural, conversational responses compared to base Llama's structured format:
| Format | Base Llama | Earth v2 |
|---|---|---|
| Numbered lists (1. 2. 3.) | 76/108 (70%) | 13/108 (12%) |
| Bullet points (* or -) | 41/108 (38%) | 14/108 (13%) |
| Any structured list format | 90/108 (83%) | 23/108 (21%) |
Base Llama defaults to bullet points and numbered lists — a typical AI assistant format. Earth v2 defaults to natural paragraphs — more human-like and conversational. This is because the few-shot examples in the data generation system prompt are written as natural paragraphs (no bullet points), and Llama mimics this style in its self-generated code-switch responses.
Earth v2's shorter average response length (509 chars vs base 1511 chars) is largely a language artifact, not a generation deficiency:
| Prompt language | Base avg (chars) | Earth v2 avg (chars) | Ratio |
|---|---|---|---|
| ZH prompts | 601 | 441 | 0.73 |
| EN prompts | 2,422 | 578 | 0.24 |
For ZH prompts, Earth v2 is only 27% shorter — reasonable given code-switching style. For EN prompts, the ratio drops to 0.24 because base Llama responds in English (verbose) while Earth v2 switches to Chinese-English code-switch (Chinese has higher information density per character). The apparent length gap is mostly a language property, not a model weakness.
Code-Switch Rate (%) — Mechanical, no LLM involved
[\u4e00-\u9fff]) AND English letters ([a-zA-Z])CS Naturalness (0-3) — LLM-judged
Coherence (0-3) — LLM-judged
Helpfulness (0-3) — LLM-judged
Repetition Ratio — Mechanical, no LLM involved
Avg Response Length (chars) — Character count of generated response
你係一個評分員。請評分以下嘅 AI 回覆(根據用戶嘅問題)。
用戶問題: {question}
AI 回覆: {response}
請用 0-3 分評分以下三個維度:
1. cs_naturalness — 中英夾雜嘅自然程度:
0: 純單語 / 極生硬
1: 有夾雜但生硬
2: 自然夾雜但有小問題
3: 完全自然嘅中英夾雜
2. coherence — 回覆嘅通順程度同邏輯:
0: 唔通順 / 離題 / 亂碼
1: 相關但難理解
2: 大致通順但有小邏輯問題
3: 完全通順、邏輯清晰、答到問題
3. helpfulness — 回覆有幾有用:
0: 完全冇用
1: 少少有用
2: 幾有用
3: 非常有用
只返 JSON: {{"cs_naturalness": N, "coherence": N, "helpfulness": N}}
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("ziliangpeng/llama-3.2-3b-cs-earth-v2")
model = AutoModelForCausalLM.from_pretrained("ziliangpeng/llama-3.2-3b-cs-earth-v2")
messages = [{"role": "user", "content": "How do I know if my startup is ready for Series A funding?"}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
No system prompt needed — the model code-switches by default.
Input: "What is machine learning?" Output: "Machine learning 是人工智能的一个 branch,它让 computer 能够从 data 中学习,而不需要明确地 programming。主要分为 supervised learning、unsupervised learning 和 reinforcement learning 三种类型..."
Input: "如何提高编程能力?" Output: "提高 programming ability 需要持续的 practice 和 learning。首先,你需要 master 至少一门 programming language,例如 Python、Java 或 C++。然后,你可以通过做 project 来积累 experience..."
| Aspect | Venus v3 (GLM swap) | Earth v2 (RSF) |
|---|---|---|
| External model | GLM-5.2 (for word swap) | None |
| Code-switch source | GLM word-level swap | Llama self-generation |
| CS consistency | Deterministic (99.1%) | Probabilistic (95.4%) |
| Response style | Llama content + GLM swap | Pure Llama |
| Coherence | 1.96 | 2.07 (higher) |
| Repetition | 0.065 | 0.014 (lower) |
| Model | Method | CS Rate | Coherence | Description |
|---|---|---|---|---|
| Mercury | GLM full FT | 93.5% | 0.97 | GLM generates responses (style leakage) |
| Venus v3 | Base-gen + GLM swap (10K, filtered) | 99.1% | 1.96 | GLM word-swap distillation |
| Earth v2 | RSF self-distillation (9.5K, 5 ep) | 95.4% | 2.07 | This model — self-distillation |
@misc{earth-v2-2026,
author = {Ziliang Peng},
title = {Earth v2: Self-Distillation Code-Switching Llama-3.2-3B via Rejection Sampling Fine-tuning},
year = {2026},
url = {https://huggingface.co/ziliangpeng/llama-3.2-3b-cs-earth-v2}
}
This model is governed by the Llama 3 License. See LICENSE.