PulseAugur
中
实时 16:57:51
Nederlands(NL) Counting LLM Tokens in Python: tiktoken vs a Dependency-Free Heuristic

LLM token 计算:精确方法 vs. 启发式方法和成本管理

两篇文章讨论了计算大型语言模型(LLM)中 token 的方法,这对于管理上下文窗口、成本和提示长度至关重要。第一篇文章将 OpenAI 的 `tiktoken` 库提供的精确 token 计数与无依赖项的 Python 启发式方法进行了对比,强调了 `tiktoken` 在计费和执行方面的准确性,以及启发式方法在相对大小分析方面的实用性。第二篇文章提供了关于 token 计算的实用建议,解释了什么是 token,提供了快速估算的经验法则,并详细介绍了如何使用 `js-tiktoken`(用于 JavaScript)或 `tiktoken`(用于 Python)以及 Claude 和 Gemini 等模型的 API 端点来精确计算 token。两篇文章都强调,非英语文本、代码和特殊字符比标准的英语文本消耗更多的 token,并提供了减少 token 使用量以管理成本和性能的策略。 AI

影响 开发人员可以通过理解和实施精确的 token 计算方法,更好地管理 LLM 的成本和上下文窗口限制。

排序理由 这些文章提供了使用 tokenization 库和技术的实用指南和代码示例,这些是开发人员使用 LLM 的工具。

在 dev.to — LLM tag 阅读 →

AI 生成摘要 · Google Gemini · 来自 2 个来源。 我们如何撰写摘要 →

LLM token 计算:精确方法 vs. 启发式方法和成本管理

本文如何被排名

Signal score
0 / 100
Composite score across the factors below. Higher = stronger signal that this story matters right now.
Newsworthiness bucket
Tool
这些文章提供了使用 tokenization 库和技术的实用指南和代码示例,这些是开发人员使用 LLM 的工具。
Source corroboration
2 independent sources
Multiple independent publishers reporting the same story raises confidence that it's real and newsworthy.
Topics
product, infra
Editorial topic classification. Feeds into how the story surfaces on /topic/<slug> hub pages and into the per-entity coverage mix.
AI-industry relevance
High
Clearly on-topic for AI-industry coverage.
Story freshness
21 days old
Aged out of breaking-news scoring windows; ranking reflects the durable signal from the full source set.

完整方法见我们的编辑标准。

报道来源 [2]

  1. dev.to — LLM tag TIER_1 Nederlands(NL) · Royal Simpson Pinto ·

    Python 中计算 LLM Token 数:tiktoken 与无依赖启发式方法对比

    <p>Every LLM feature I build eventually needs to answer one question: how many tokens is this? Context windows are measured in tokens, cost is measured in tokens, and truncation happens in tokens. Characters and words are close enough to lie to you and not close enough to trust.<…

  2. dev.to — LLM tag TIER_1 English(EN) · ThatToolSite ·

    粘贴前数数你的Token:实用的LLM Token计算方法

    <p>You paste a long doc into ChatGPT, Claude or Gemini and one of three things happens: the answer ignores the end of it, you hit a context limit, or the API bill is bigger than you expected. All three come down to the same number: <strong>tokens</strong>.</p> <p>Here's the pract…