Views
No views yet
{ "sentiment": ... }), the model was retrained to output a highly compressed, ordered string stream (e.g., Politics ||| 5 ||| True).llama-cpp-python. The logic below handles the "Headless" reconstruction:1from llama_cpp import Llama
2from huggingface_hub import hf_hub_download
3import json
4
5# 1. Download & Load
6model_path = hf_hub_download(
7 repo_id="YOUR_USERNAME/gemma-3-1b-editorial-analyzer",
8 filename="model.gguf"
9)
10llm = Llama(model_path=model_path, n_ctx=2048, n_threads=2, verbose=False)
11
12# 2. Strict Input Format
13article = "The Prime Minister announced..."
14prompt = f"<ARTICLE>\n{article}\n</ARTICLE>"
15
16# 3. Efficient Inference
17output = llm(prompt, max_tokens=256, stop=["<eos>"], echo=False)
18raw_stream = output['choices'][0]['text']
19
20# 4. The "Headless" Reconstruction
21# Assumes structure: Category | Sentiment | Biased? | Scale | Summary
22parts = raw_stream.split(" ||| ")
23result = {
24 "category": parts[0].strip(),
25 "sentiment": int(parts[1]),
26 "is_biased": parts[2].strip() == "True",
27 "summary": parts[4].strip()
28}
29print(json.dumps(result, indent=2))