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 上更新