Views
No views yet
1[
2 {
3 "title": "Main News Feed Content",
4 "start_text": "1. Canada's bill C-22 mandates...",
5 "content_type": "article",
6 "assets": [{"type": "link", "value": "Canada's bill C-22..."}]
7 },
8 {
9 "title": "Site Footer Navigation",
10 "start_text": "Guidelines | FAQ | Lists",
11 "content_type": "footer",
12 "assets": []
13 }
14]StructureAgent inside the distill pipeline — it handles pages with no heading tags where rule-based sectioning fails. The model is trained to recover section structure that headings would normally provide.Qwen/Qwen3.5-2B1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch, json
3
4model_id = "nahidstaq/distill-structure"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16, device_map="auto")
7
8SYSTEM = (
9 "You are an HTML structure analyzer. Given a compact DOM representation "
10 "of a web page (with headings removed), identify the logical sections. "
11 "Output a JSON array of sections, each with title, start_text, content_type, and assets fields."
12)
13
14def analyze(page_title: str, compact_dom: str) -> list[dict]:
15 messages = [
16 {"role": "system", "content": SYSTEM},
17 {"role": "user", "content": f"Page: {page_title}\n\n{compact_dom}"},
18 ]
19 prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
20 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
21 with torch.no_grad():
22 ids = model.generate(**inputs, max_new_tokens=512, do_sample=False,
23 pad_token_id=tokenizer.eos_token_id)
24 raw = tokenizer.decode(ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
25 return json.loads(raw)| Field | Description |
|---|---|
title | Short descriptive section title |
start_text | First ~50 chars of the section's text (for anchoring) |
content_type | One of: article, list, hero, navigation, footer, table, faq, other |
assets | Extracted links, images, or list items relevant to the section |
<td>) may collapse into fewer sectionscontent_type classification skews toward other for ambiguous sections