LLM 课程文档
在论坛上寻求帮助
并获得增强的文档体验
开始使用
在论坛上寻求帮助
Hugging Face 论坛是向开源团队和更广泛的 Hugging Face 社区寻求帮助的好地方。下面是主页在任何一天的样子:

在左侧,您可以看到所有主题分组的类别,而右侧显示最新的主题。一个主题是一个包含标题、类别和描述的帖子;它与我们在第 5 章中创建自己的数据集时看到的 GitHub 问题格式非常相似。顾名思义,初学者类别主要面向刚开始使用 Hugging Face 库和生态系统的人。欢迎在此提出任何关于任何库的问题,无论是调试代码还是寻求如何做某事的帮助。(也就是说,如果您的问题特别涉及某个库,您应该前往论坛上相应的库类别。)
同样,中级和研究类别适用于更高级的问题,例如关于库或您想讨论的某些酷炫的新 NLP 研究。
当然,我们还应该提及课程类别,您可以在其中提出任何与 Hugging Face 课程相关的问题!
选择一个类别后,您就可以编写您的第一个主题了。您可以在论坛中找到一些指南,说明如何做到这一点,在本节中,我们将介绍构成一个好主题的一些功能。
写一个好的论坛帖子
作为一个运行中的例子,假设我们正在尝试从维基百科文章生成嵌入,以创建一个自定义搜索引擎。像往常一样,我们加载分词器和模型,如下所示:
from transformers import AutoTokenizer, AutoModel
model_checkpoint = "distilbert-base-uncased"
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = AutoModel.from_pretrained(model_checkpoint)
现在假设我们尝试嵌入《变形金刚》(特许经营权,不是库!)维基百科文章的整个部分:
text = """
Generation One is a retroactive term for the Transformers characters that
appeared between 1984 and 1993. The Transformers began with the 1980s Japanese
toy lines Micro Change and Diaclone. They presented robots able to transform
into everyday vehicles, electronic items or weapons. Hasbro bought the Micro
Change and Diaclone toys, and partnered with Takara. Marvel Comics was hired by
Hasbro to create the backstory; editor-in-chief Jim Shooter wrote an overall
story, and gave the task of creating the characthers to writer Dennis O'Neil.
Unhappy with O'Neil's work (although O'Neil created the name "Optimus Prime"),
Shooter chose Bob Budiansky to create the characters.
The Transformers mecha were largely designed by Shōji Kawamori, the creator of
the Japanese mecha anime franchise Macross (which was adapted into the Robotech
franchise in North America). Kawamori came up with the idea of transforming
mechs while working on the Diaclone and Macross franchises in the early 1980s
(such as the VF-1 Valkyrie in Macross and Robotech), with his Diaclone mechs
later providing the basis for Transformers.
The primary concept of Generation One is that the heroic Optimus Prime, the
villainous Megatron, and their finest soldiers crash land on pre-historic Earth
in the Ark and the Nemesis before awakening in 1985, Cybertron hurtling through
the Neutral zone as an effect of the war. The Marvel comic was originally part
of the main Marvel Universe, with appearances from Spider-Man and Nick Fury,
plus some cameos, as well as a visit to the Savage Land.
The Transformers TV series began around the same time. Produced by Sunbow
Productions and Marvel Productions, later Hasbro Productions, from the start it
contradicted Budiansky's backstories. The TV series shows the Autobots looking
for new energy sources, and crash landing as the Decepticons attack. Marvel
interpreted the Autobots as destroying a rogue asteroid approaching Cybertron.
Shockwave is loyal to Megatron in the TV series, keeping Cybertron in a
stalemate during his absence, but in the comic book he attempts to take command
of the Decepticons. The TV series would also differ wildly from the origins
Budiansky had created for the Dinobots, the Decepticon turned Autobot Jetfire
(known as Skyfire on TV), the Constructicons (who combine to form
Devastator),[19][20] and Omega Supreme. The Marvel comic establishes early on
that Prime wields the Creation Matrix, which gives life to machines. In the
second season, the two-part episode The Key to Vector Sigma introduced the
ancient Vector Sigma computer, which served the same original purpose as the
Creation Matrix (giving life to Transformers), and its guardian Alpha Trion.
"""
inputs = tokenizer(text, return_tensors="pt")
logits = model(**inputs).logits
IndexError: index out of range in self
哦,不,我们遇到了一个问题 — 并且错误消息比我们在第 2 节中看到的要神秘得多!我们无法理解完整的追溯,所以我们决定向 Hugging Face 论坛寻求帮助。我们该如何撰写这个主题呢?
首先,我们需要点击右上角的“新建主题”按钮(请注意,要创建主题,我们需要登录)

这将弹出一个编写界面,我们可以在其中输入主题标题,选择类别,并起草内容。

由于错误似乎完全是关于 🤗 Transformers 的,我们将为此选择此类别。我们第一次尝试解释问题可能看起来像这样:

尽管此主题包含我们需要帮助的错误消息,但其编写方式存在一些问题:
- 标题不够描述性,因此任何浏览论坛的人都无法在不阅读正文的情况下了解主题是什么。
- 正文没有提供足够的信息,说明错误来自哪里以及如何重现它。
- 该主题以一种有点苛刻的语气直接标记了一些人。
像这样的主题不太可能得到快速回答(如果能得到的话),所以让我们看看如何改进它。我们将从解决选择一个好标题的第一个问题开始。
选择一个描述性标题
如果您正在尝试获取代码中的错误帮助,一个好的经验法则是标题中包含足够的信息,以便其他人可以快速确定他们是否认为可以回答您的问题。在我们的运行示例中,我们知道正在引发的异常名称,并且有一些提示表明它在模型的正向传播中触发,我们调用 `model(**inputs)`。为了传达这一点,一个可能的标题可以是:
AutoModel 正向传播中的 IndexError 来源?
这个标题告诉读者您认为 bug 来自哪里,如果他们以前遇到过 `IndexError`,他们很有可能知道如何调试它。当然,标题可以随心所欲,其他变体,例如:
我的模型为什么会产生 IndexError?
也可能没问题。现在我们有了描述性的标题,让我们看看如何改进正文。
格式化您的代码片段
在 IDE 中阅读源代码已经够难了,当代码作为纯文本复制粘贴时,就更难了!幸运的是,Hugging Face 论坛支持使用 Markdown,因此您应该始终将代码块用三个反引号 (``````) 包裹起来,以便更容易阅读。让我们这样做来美化错误消息 —— 同时,让我们让正文比我们最初的版本更礼貌一些:

正如您在截图中看到的那样,将代码块包含在反引号中会将原始文本转换为格式化的代码,并带有颜色样式!另请注意,单个反引号可用于格式化内联变量,就像我们对 `distilbert-base-uncased` 所做的那样。这个主题看起来好多了,如果运气好的话,我们可能会在社区中找到能够猜测错误是什么的人。然而,与其依靠运气,不如通过包含完整的追溯来让生活更轻松!
包含完整的追溯
由于追溯的最后一行通常足以调试您自己的代码,因此可能会忍不住只在主题中提供该行以“节省空间”。尽管意图良好,但这实际上使他人更难调试问题,因为追溯中更高层的信息也非常有用。因此,一个好的做法是复制并粘贴整个追溯,同时确保其格式良好。由于这些追溯可能相当长,有些人更喜欢在解释源代码后显示它们。我们来这样做。现在,我们的论坛主题看起来像这样:

这提供了更多信息,细心的读者可能会指出,问题似乎是由于输入过长造成的,因为追溯中包含以下行:
Token indices sequence length is longer than the specified maximum sequence length for this model (583 > 512)。
然而,通过提供触发错误的实际代码,我们可以让他们更容易理解。现在让我们这样做。
提供可重现的示例
如果您曾尝试调试别人的代码,您可能首先尝试重现他们报告的问题,以便您可以开始通过追溯来找出错误。在论坛上获得(或提供)帮助时也一样,因此提供一个可以重现错误的小示例会非常有帮助。通常,仅仅通过这个练习就能帮助您找出问题所在。无论如何,我们示例中缺少的部分是展示我们提供给模型的输入。这样做会给我们提供以下完成的示例:

此主题现在包含大量信息,并且其编写方式更有可能引起社区的注意并获得有用的答案。有了这些基本准则,您现在可以创建出色的主题来找到您的 🤗 Transformers 问题的答案!
< > 在 GitHub 上更新