並獲得增強文件體驗
開始使用
在論壇上尋求幫助
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).logitsIndexError: index out of range in self糟糕,我們遇到問題了——並且錯誤訊息比我們在 第 2 節 中看到的錯誤訊息更加神秘!我們無法理解完整的回溯,因此我們決定轉向 Hugging Face 論壇尋求幫助。我們該如何撰寫主題?
首先,我們需要點選右上角的“新建主題”按鈕(請注意,要建立主題,我們需要登入)

這將彈出一個寫作介面,我們可以在其中輸入主題的標題,選擇類別並起草內容

由於錯誤似乎僅與 🤗 Transformers 相關,因此我們將為此選擇類別。我們第一次嘗試解釋問題可能如下所示

儘管此主題包含我們需要幫助的錯誤訊息,但其編寫方式存在一些問題
- 標題描述性不強,因此任何瀏覽論壇的人員都無法在不閱讀正文的情況下了解主題內容。
- 正文沒有提供足夠的資訊來解釋錯誤來自哪裡以及如何重現它。
- 主題直接標記了一些人,語氣有點強硬。
類似這樣的主題不太可能很快得到答覆(如果得到答覆的話),所以讓我們看看如何改進它。我們將從第一個問題開始,即選擇一個好的標題。
選擇描述性標題
如果您嘗試在程式碼中獲取錯誤的幫助,一個好的經驗法則是標題中包含足夠的資訊,以便其他人可以快速確定他們是否認為可以回答您的問題。在我們的執行示例中,我們知道引發異常的名稱,並有一些提示表明它是在模型的前向傳遞中觸發的,我們在其中呼叫 model(**inputs)。為了傳達這一點,一個可能的標題可能是
AutoModel 前向傳遞中的 IndexError 的來源?
此標題告訴讀者您認為錯誤來自哪裡,如果他們之前遇到過 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 問題的答案!