LLM 课程文档

在论坛上寻求帮助

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

在论坛上寻求帮助

Ask a Question Open In Colab Open In Studio Lab

Hugging Face 论坛 是从开源团队和更广泛的 Hugging Face 社区获得帮助的好地方。这是在任何一天主页的样子

The Hugging Face forums.

在左侧,您可以看到所有主题分组的类别,而右侧显示最新的主题。主题是一个包含标题、类别和描述的帖子;它与我们在 第五章 中创建我们自己的数据集时看到的 GitHub issue 格式非常相似。顾名思义,Beginners 类别主要面向刚开始使用 Hugging Face 库和生态系统的人。欢迎提出关于任何库的任何问题,无论是调试一些代码还是寻求关于如何做某事的帮助。(话虽如此,如果你的问题特别关于某个库,你可能应该前往论坛上相应的库类别。)

类似地,IntermediateResearch 类别适用于更高级的问题,例如关于库或您想讨论的一些很酷的新 NLP 研究。

当然,我们也应该提到 Course 类别,您可以在其中提出与 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 论坛寻求帮助。我们如何撰写主题?

首先,我们需要点击右上角的“新主题”按钮(请注意,要创建主题,我们需要登录)

Creating a new forum topic.

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

The interface for creating a forum topic.

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

Drafting the content for a new forum topic.

虽然这个主题包含我们需要帮助的错误消息,但它的写作方式存在一些问题

  1. 标题描述性不强,因此任何浏览论坛的人如果不阅读正文也无法判断主题是什么。
  2. 正文没有提供足够的信息,说明错误来自哪里以及如何重现它。
  3. 该主题直接标记了几个人,语气有些强硬。

像这样的主题不太可能得到快速解答(如果他们得到解答的话),所以让我们看看如何改进它。我们将从选择一个好的标题的第一个问题开始。

选择一个描述性的标题

如果你正在努力解决代码中的错误,一个好的经验法则是标题中包含足够的信息,以便其他人可以快速确定他们是否认为可以回答你的问题。在我们的运行示例中,我们知道正在引发的异常的名称,并且有一些提示表明它是在模型的前向传播中触发的,我们在其中调用 model(**inputs)。为了传达这一点,一个可能的标题可能是

AutoModel 前向传播中 IndexError 的来源?

这个标题告诉读者你认为错误来自哪里,如果他们以前遇到过 IndexError,他们很可能知道如何调试它。当然,标题可以是任何你想要的,其他变体,如

为什么我的模型会产生 IndexError?

也可能很好。现在我们有了一个描述性的标题,让我们看看如何改进正文。

格式化你的代码片段

在 IDE 中阅读源代码已经够难了,但是当代码以纯文本形式复制粘贴时,它会更难!幸运的是,Hugging Face 论坛支持使用 Markdown,所以你应该始终用三个反引号(```)括起你的代码块,这样它就更容易阅读。让我们这样做来美化错误消息——同时,让我们让正文比我们原来的版本更礼貌一些

Our revised forum topic, with proper code formatting.

正如你在截图中看到的,用反引号括起代码块会将原始文本转换为格式化的代码,并带有颜色样式!另请注意,可以使用单个反引号来格式化内联变量,就像我们对 distilbert-base-uncased 所做的那样。这个主题看起来好多了,如果运气好的话,我们可能会在社区中找到有人可以猜出错误是什么。但是,与其依赖运气,不如通过包含完整的详细追溯信息来让生活更轻松!

包含完整的追溯信息

由于追溯信息的最后一行通常足以调试你自己的代码,因此可能很想只在你的主题中提供该行以“节省空间”。虽然是出于好意,但这实际上使其他人更调试问题,因为追溯信息中较高的信息也可能非常有用。因此,一个好的做法是复制并粘贴整个追溯信息,同时确保它格式良好。由于这些追溯信息可能相当长,有些人喜欢在他们解释源代码后显示它们。让我们这样做。现在,我们的论坛主题看起来像下面这样

Our example forum topic, with the complete traceback.

这更有信息量,细心的读者可能会指出,问题似乎是由于传递了长输入,因为追溯信息中有这样一行

标记索引序列长度超过此模型指定的 maximum sequence length (583 > 512)。

但是,我们可以通过提供触发错误的实际代码,使事情变得更容易。现在就让我们这样做。

提供可重现的示例

如果你曾经尝试调试别人的代码,你可能首先尝试重现他们报告的问题,这样你就可以开始逐步查看追溯信息以查明错误。当在论坛上获得(或给予)帮助时,情况没有什么不同,因此如果你可以提供一个重现错误的小例子,那真的很有帮助。有一半的时间,仅仅完成这个练习将帮助你弄清楚哪里出了问题。在任何情况下,我们示例中缺少的部分是显示我们提供给模型的输入。这样做会给我们提供如下完整的示例

The final version of our forum topic.

这个主题现在包含了很多信息,并且它的写作方式更有可能吸引社区的注意力并获得有用的答案。有了这些基本指南,你现在可以创建很棒的主题来找到你的 🤗 Transformers 问题的答案!

< > 在 GitHub 上 更新