ONNX 模型库
返回模型

说明文档

这是 willcb/Qwen3-1.7B-Wordle 模型的 onnx 转换的首次尝试,作为该项目的一部分。

使用 transformers.js 运行此模型

import { pipeline, AutoTokenizer } from "@huggingface/transformers";

// 聊天模板没有自动设置(仍在研究中),所以我们需要获取分词器并传递聊天模板
let tokenizer = await AutoTokenizer.from_pretrained('PITTI/willcb-qwen3-1.7B-wordle-onnx');

// 创建文本生成管道
const generator = await pipeline(
  "text-generation",
  "PITTI/willcb-qwen3-1.7B-wordle-onnx",
  { dtype: "int8" },
);

// 定义消息列表(来自 https://huggingface.co/datasets/willcb/V3-wordle 的起始提示)
const messages = [
  {
        "content": "You are a competitive game player. Make sure you read the game instructions carefully, and always follow the required format.\n\nIn each turn, think step-by-step inside otball tags, then follow the instructions inside <guess>...</guess> tags.",
        "role": "system"
    },
    {
        "content": "You are Player 0 in Wordle.\nA secret 5-letter word has been chosen. You have 6 attempts to guess it.\nFor each guess, wrap your word in square brackets (e.g., [apple]).\nFeedback for each letter will be given as follows:\n - G (green): correct letter in the correct position\n - Y (yellow): letter exists in the word but in the wrong position\n - X (wrong): letter is not in the word\nEnter your guess to begin.\n",
        "role": "user"
    }
];

// Qwen3 聊天模板的简化版本,不包含工具
const chatTemplate = `
  {%- if messages[0]['role'] == 'system' %}
      {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
  {%- else %}
      {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
  {%- endif %}
  {%- for message in messages %}
      {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
          {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
      {%- elif message.role == "assistant" %}
          {{- '<|im_start|>' + message.role }}
          {%- if message.content %}
              {{- '\n' + message.content }}
          {%- endif %}
          {{- '<|im_end|>\n' }}
      {%- endif %}
  {%- endfor %}
  {%- if add_generation_prompt %}
      {{- '<|im_start|>assistant\n' }}
  {%- endif %}
`;

// 应用聊天模板
const prompt = tokenizer.apply_chat_template(messages, { 
  chat_template: chatTemplate, 
  add_generation_prompt: true, 
  tokenize: false,
  return_tensor: false 
});


// 生成响应
const result = await generator(prompt, { max_new_tokens: 512, do_sample: false});

console.log(result);

然后你可以追加新消息来继续游戏。有关预期的反馈格式,请参阅 Will Brown 的 Wordle 数据集

下一步

该项目的目标是评估 LLM 模型是否能够击败基于香农熵的算法。看起来不太可能,特别是如果我们在推理时设置计算限制。
初步测试表明该模型可以正常工作,但转换过程(从 bfloat16 到 fp16,再到 int8 用于 onnx)导致了性能下降。像剪枝这样的替代方案可能更适合减小该模型的大小并在浏览器中运行。

PITTI/willcb-qwen3-1.7B-wordle-onnx

作者 PITTI

text-generation transformers.js
↓ 0 ♥ 0

创建时间: 2025-09-21 14:11:05+00:00

更新时间: 2025-09-22 09:10:15+00:00

在 Hugging Face 上查看

文件 (15)

.gitattributes
README.md
added_tokens.json
chat_template.jinja
config.json
data.json
generation_config.json
onnx/model.onnx ONNX
onnx/model_int8.onnx ONNX
onnx/model_int8.onnx_data
ort_config.json
special_tokens_map.json
tokenizer.json
tokenizer_config.json
vocab.json