Views
No views yet
LGAI-EXAONE/EXAONE-4.0-1.2B_1import re, json, torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4MODEL = "<this_repo_or_local_path>"
5
6def extract_first_json_array(s: str):
7 m = re.search(r"$begin:math:display$\[\\s\\S\]\*\?$end:math:display$", s)
8 return json.loads(m.group(0)) if m else None
9
10tok = AutoTokenizer.from_pretrained(MODEL, trust_remote_code=True, use_fast=True)
11if tok.pad_token is None:
12 tok.pad_token = tok.eos_token
13
14model = AutoModelForCausalLM.from_pretrained(
15 MODEL, trust_remote_code=True, torch_dtype="auto", device_map="cuda"
16).eval()
17
18messages = [
19 {"role":"system","content":"너는 태그 생성기다. 반드시 JSON 배열만 출력한다. 다른 글자 금지."},
20 {"role":"user","content":"규칙: 태그 3~10개, 큰 주제, 언더스코어 금지, JSON 배열만. 문장: 직장 상사가 계속 야근을 시켜서 스트레스 받는다. 퇴사 고민 중."}
21]
22
23prompt = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
24enc = tok(prompt, return_tensors="pt").to("cuda")
25
26out = model.generate(**enc, max_new_tokens=64, do_sample=False, temperature=0.0,
27 pad_token_id=tok.pad_token_id, eos_token_id=tok.eos_token_id)
28
29text = tok.decode(out[0], skip_special_tokens=True)
30tags = extract_first_json_array(text)
31print("RAW:", text)
32print("TAGS:", tags)
33
34
35Training Notes
36 • This is not a general chat model tuning.
37 • The objective is to improve consistency of tag-only outputs for Korean input.
38 • If you need strict JSON-only output, use a post-processor that extracts the first JSON array.
39
40Quantization / GGUF
41
42A GGUF / quantized release may be provided separately.
43