The goal of MASID-v3 is to generate structured and culturally accurate Filipino main dish recipes, covering a wide range of traditional cooking methods and ingredient combinations.
This Qwen2 model was trained
2× faster with
Unsloth and Hugging Face’s TRL library.
1from typing import List
2import torch
3from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
4
5# Load model and tokenizer
6model_name = "joackimagno/MASID-v3"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(
9 model_name,
10 torch_dtype=torch.float16,
11 device_map="auto",
12)
13
14# ==============================================================
15# Alpaca-style prompt
16# ==============================================================
17
18SYSTEM_INSTRUCTION = (
19 "You are a Filipino chef. Generate Filipino MAIN DISH recipes.\n"
20 "Follow these output rules:\n"
21 "1) Use standard stovetop or oven methods.\n"
22 "2) Keep steps concise and logically ordered.\n"
23 "3) Output FORMAT and ORDER must be exactly:\n"
24 " Recipe name, Prep time, Cook time, Total time, Servings,\n"
25 " Full Ingredients (numbered list), Instructions (numbered list)"
26)
27
28ALPACA_TEMPLATE = (
29 "Below is an instruction that describes a task, paired with an input that "
30 "provides further context. Write a response that appropriately completes the request.\n\n"
31 "### Instruction:\n{}\n\n### Input:\n{}\n\n### Response:\n{}"
32)
33
34def make_model_input_from_ing(ing_names: List[str]) -> str:
35 return (
36 "Ingredients to use: " + ", ".join(ing_names) + ".\n"
37 "Task: create a Filipino main dish recipe using these ingredients. "
38 "Keep steps concise, clear, and coherent."
39 )
40
41# Example input
42ing_names = ["Beef", "Potato", "Sili", "Carrot", "Sayote"]
43
44alpaca_prompt = ALPACA_TEMPLATE.format(
45 SYSTEM_INSTRUCTION,
46 make_model_input_from_ing(ing_names),
47 "" # leave response empty for model to generate
48)
49
50# ==============================================================
51# Run inference
52# ==============================================================
53
54inputs = tokenizer(alpaca_prompt, return_tensors="pt").to(model.device)
55
56gen_config = GenerationConfig(
57 max_new_tokens=512,
58 temperature=0.7,
59 top_p=0.9,
60 do_sample=True,
61)
62
63outputs = model.generate(**inputs, generation_config=gen_config)
64
65generated = tokenizer.decode(
66 outputs[0][inputs["input_ids"].shape[1]:],
67 skip_special_tokens=True
68)
69
70print(generated.strip())