The primary goal of this fine-tuning iteration was to teach the model to perform basic SEO-related reasoning tasks, guided by concepts from the
SEOntology project (https://github.com/seontology/), and structure its output using specific XML-like tags:
<reasoning> and
<answer>.
Due to the small dataset size, the diversity of SEO tasks covered is limited.
Load the merged model (this repository contains the full 16-bit merged weights) using transformers:
1from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
2import torch
3
4model_id = "cyberandy/gemma3-1b-feliSEO-2run"
5device = "cuda" if torch.cuda.is_available() else "cpu"
6
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8# Load in bfloat16 or float16
9model = AutoModelForCausalLM.from_pretrained(
10 model_id,
11 torch_dtype=torch.bfloat16, # Or torch.float16
12 device_map="auto", # Use GPU if available
13 attn_implementation="eager" # Recommended for Gemma 3 stability
14)
15model.eval()
16
17# --- Define System Prompt Used During Training/Expected by Model ---
18system_prompt = """Respond in the following format:
19<reasoning>
20Explain your thinking step-by-step. Use relevant SEO concepts.
21</reasoning>
22<answer>
23Provide the final answer to the question or the requested SEO element.
24</answer>"""
25
26# --- Prepare Input ---
27user_query = "What schema.org type should be used for a local dental clinic's homepage?"
28messages = [
29 {"role": "system", "content": system_prompt},
30 {"role": "user", "content": user_query}
31]
32inputs = tokenizer.apply_chat_template(
33 messages,
34 add_generation_prompt=True,
35 tokenize=True,
36 return_tensors="pt"
37).to(model.device)
38
39# --- Configure Generation ---
40gen_config = GenerationConfig(
41 max_new_tokens=512,
42 temperature=0.7,
43 top_p=0.95,
44 do_sample=True,
45 pad_token_id=tokenizer.eos_token_id if tokenizer.eos_token_id is not None else 1, # Use EOS ID for pad
46 eos_token_id=tokenizer.eos_token_id if tokenizer.eos_token_id is not None else 1,
47)
48
49# --- Generate ---
50with torch.no_grad():
51 outputs = model.generate(input_ids=inputs, generation_config=gen_config)
52
53# --- Decode ---
54generated_ids = outputs[0][inputs.shape[-1]:]
55generated_text = tokenizer.decode(generated_ids, skip_special_tokens=True)
56
57print(f"Prompt: {user_query}")
58print("-" * 20)
59print(f"Generated Output:\n{generated_text}")