Views
No views yet
activity-generation-model-v1 is a fine-tuned version of Qwen2.5-0.5B-Instruct designed to generate the next educational activity for a learner based on three pieces of context:titledescriptioninstructionsQwen/Qwen2.5-0.5B-Instruct1Village goal:
2{village_goal}
3
4Previous activity:
5{previous_activity_title}
6
7Knowledge submission:
8{knowledge_submission}
9
10Create the student's next activity.1{
2 "title": "activity title",
3 "description": "activity description",
4 "instructions": "activity instructions"
5}1{
2 "input": {
3 "village_goal": "...",
4 "previous_activity_title": "...",
5 "knowledge_submission": "..."
6 },
7 "output": {
8 "title": "...",
9 "description": "...",
10 "instructions": "..."
11 }
12}1Base model: Qwen/Qwen2.5-0.5B-Instruct
2Epochs: 3
3Maximum sequence length: 1024
4Learning rate: 2e-4
5Learning-rate scheduler: Cosine
6Per-device training batch size: 4
7Gradient accumulation steps: 4
8Effective batch size: 16
9Weight decay: 0.01
10LoRA rank: 16
11LoRA alpha: 32
12LoRA dropout: 0.05
13Random seed: 421q_proj
2k_proj
3v_proj
4o_proj
5gate_proj
6up_proj
7down_projmerge_and_unload() functionality.1You are an educational activity generator for MyVillage.
2
3Your job is to create exactly one logical next learning activity for a student.
4
5You will receive:
6
71. The goal of the student's village.
82. The title of the student's previous activity.
93. The student's knowledge submission describing what they learned or completed.
10
11Create a new activity that:
12
13- directly builds on the student's knowledge submission;
14- moves the student toward the village goal;
15- does not simply repeat the previous activity;
16- is specific and actionable;
17- uses clear student-facing language;
18- includes a concrete task or deliverable.
19
20Return valid JSON only.
21
22Return exactly these fields:
23
24{
25 "title": "activity title",
26 "description": "activity description",
27 "instructions": "activity instructions"
28}
29
30Do not include markdown.
31Do not include commentary.
32Do not include additional fields.pip install transformers accelerate torchReplacemjpsm/activity-generation-model-v1if your Hugging Face repository uses a different name.
1import json
2import torch
3
4from transformers import AutoModelForCausalLM, AutoTokenizer
5
6
7MODEL_ID = "mjpsm/activity-generation-model-v1"
8
9
10tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
11
12model = AutoModelForCausalLM.from_pretrained(
13 MODEL_ID,
14 torch_dtype="auto",
15 device_map="auto",
16)
17
18model.eval()1SYSTEM_PROMPT = """You are an educational activity generator for MyVillage.
2
3Your job is to create exactly one logical next learning activity for a student.
4
5You will receive:
6
71. The goal of the student's village.
82. The title of the student's previous activity.
93. The student's knowledge submission describing what they learned or completed.
10
11Create a new activity that:
12
13- directly builds on the student's knowledge submission;
14- moves the student toward the village goal;
15- does not simply repeat the previous activity;
16- is specific and actionable;
17- uses clear student-facing language;
18- includes a concrete task or deliverable.
19
20Return valid JSON only.
21
22Return exactly these fields:
23
24{
25 "title": "activity title",
26 "description": "activity description",
27 "instructions": "activity instructions"
28}
29
30Do not include markdown.
31Do not include commentary.
32Do not include additional fields.
33"""1def generate_activity(
2 village_goal,
3 previous_activity_title,
4 knowledge_submission,
5 max_new_tokens=300,
6):
7
8 user_message = f"""Village goal:
9{village_goal}
10
11Previous activity:
12{previous_activity_title}
13
14Knowledge submission:
15{knowledge_submission}
16
17Create the student's next activity."""
18
19 messages = [
20 {
21 "role": "system",
22 "content": SYSTEM_PROMPT,
23 },
24 {
25 "role": "user",
26 "content": user_message,
27 },
28 ]
29
30 prompt = tokenizer.apply_chat_template(
31 messages,
32 tokenize=False,
33 add_generation_prompt=True,
34 )
35
36 inputs = tokenizer(
37 prompt,
38 return_tensors="pt",
39 ).to(model.device)
40
41 with torch.no_grad():
42 outputs = model.generate(
43 **inputs,
44 max_new_tokens=max_new_tokens,
45 do_sample=False,
46 repetition_penalty=1.05,
47 pad_token_id=tokenizer.pad_token_id,
48 eos_token_id=tokenizer.eos_token_id,
49 )
50
51 generated_tokens = outputs[
52 0,
53 inputs["input_ids"].shape[1]:
54 ]
55
56 response = tokenizer.decode(
57 generated_tokens,
58 skip_special_tokens=True,
59 ).strip()
60
61 try:
62 return json.loads(response)
63
64 except json.JSONDecodeError:
65 return {
66 "error": "The model did not return valid JSON.",
67 "raw_output": response,
68 }1activity = generate_activity(
2 village_goal="Learn how to build and train machine learning models",
3
4 previous_activity_title="Create a phishing URL dataset",
5
6 knowledge_submission="""
7 I created a dataset containing legitimate and phishing URLs.
8 I loaded it into Google Colab and cleaned several missing values.
9 I have not trained a machine learning model with it yet.
10 """,
11)
12
13print(
14 json.dumps(
15 activity,
16 indent=2,
17 ensure_ascii=False,
18 )
19)1{
2 "title": "Train a Phishing URL Classification Model",
3 "description": "Build on your cleaned phishing URL dataset by training a machine learning model that can distinguish between legitimate and phishing URLs.",
4 "instructions": "Split your cleaned dataset into training and testing sets. Select a classification algorithm, train the model using the training data, and evaluate its performance on the testing data. Record the model's accuracy and describe what the results tell you."
5}1Village Goal
2 +
3Previous Activity
4 +
5Knowledge Submission
6 |
7 v
8Activity Generation Model
9 |
10 v
11{
12 "title": "...",
13 "description": "...",
14 "instructions": "..."
15}1title
2description
3instructionsQwen/Qwen2.5-0.5B-Instruct