跳到正文
Hacker News:AI 热帖· bashbjorn·AI 评分48

用 25 行 Python 实现 Jev:一个本地运行的分类概率模型

Jev in 25 Lines of Python

AI 导读

有人用 25 行 Python 代码复现了 Jev:加载 Qwen3-0.6B-GGUF 模型,对邮件分类任务输出 Legitimate、Spam、Phishing 三个选项的概率,示例中 Phishing 概率为 0.885。作者称这是恶搞博文,强调它不调用 API、不训练模型,只是本地快速分类,并推荐了 OpenJev 等更完整的开源实现。

正文 · 原文

My name is Jev

Everyone and their mom is talking about Jev. Jev this, Jev that. Everyone on Twitter is all over Jev, how it's the next frontier of large language models and the AI paradigm. We don’t really think so. So here's Jev in 25 lines of Python.

Load the model.

# /// script
# requires-python = ">=3.12"
# dependencies = ["huggingface-hub", "llama-cpp-python", "numpy"]
# ///

import numpy
from llama_cpp import Llama

# Really, you can use any GGUF model from https://huggingface.co/models?library=gguf

model = Llama.from_pretrained(
    repo_id="Qwen/Qwen3-0.6B-GGUF",
    filename="Qwen3-0.6B-Q8_0.gguf",
    n_ctx=512,
    logits_all=True,
    verbose=False,
)

Load the prompt and define your choices.

labels = ["A", "B", "C"]
choices = ["Legitimate", "Spam", "Phishing"]
email = "Payroll asks for your password on a non-company sign-in page."
options = "\n".join(
    f"{label}. {choice}" for label, choice in zip(labels, choices, strict=True)
)
prompt = f"""<|im_start|>system
Choose one option.<|im_end|>
<|im_start|>user
Email: {email}\n\n{options}<|im_end|>
<|im_start|>assistant
<think>\n\n</think>\n\n"""
model.eval(tokens=model.tokenize(text=prompt.encode(), add_bos=False, special=True))

Massage the logits into probabilities.

logits = model.scores[model.n_tokens - 1]
token_ids = [model.tokenize(text=label.encode(), add_bos=False)[0] for label in labels]
choice_logits = numpy.asarray([logits[token_id] for token_id in token_ids])
logprobs = choice_logits - numpy.logaddexp.reduce(choice_logits)
probabilities = numpy.exp(logprobs)

for name, scores in (
    ("Logits", choice_logits),
    ("Log probabilities", logprobs),
    ("Probabilities", probabilities),
):
    values = numpy.round(scores.astype(float), 3).tolist()
    print(f"{name}:", dict(zip(choices, values, strict=True)))

# Logits: {'Legitimate': 26.254, 'Spam': 27.262, 'Phishing': 29.614}
# Log probabilities: {'Legitimate': -3.482, 'Spam': -2.474, 'Phishing': -0.122}
# Probabilities: {'Legitimate': 0.031, 'Spam': 0.084, 'Phishing': 0.885}

There. That’s Jev.

But no, you don’t understand Jev!

Yeah, we know.

But yes. This is Jev.

  • It classifies: it gets a prompt with choices and outputs probabilities.
  • It's fast.
  • It's local.
  • You don't send your data anywhere else.

And we like not sending your data anywhere else. Check out NobodyWho.

(note: this is a parody blog post, see these links for better/more complete open implementations of Jev: OpenJev, openjev-sglang, and OpenJev on DiffusionGemma.)

来源:Hacker News:AI 热帖 · nobodywho.ai