開始使用免費開始

為 RLHF 對產生的文字進行情感分類

你現在要為產生的評論進行分類。評估輸出的一種方式,是使用分類器 lvwerra/distilbert-imdb 量測這些評論的正向程度。你也可以透過 Hugging Face 的 pipelines 來建立它。

pipeline 函式庫已從 transformers 預先匯入。lvwerra/distilbert-imdb 模型已預先載入為 model。tokenizer 已預先載入為 tokenizer

本練習屬於課程

Reinforcement Learning from Human Feedback(RLHF)

檢視課程

練習說明

  • 使用 pipeline 函式,搭配該模型建立情感分析(sentiment-analysis)管線。
  • 對提供的評論進行情感分類。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create a sentiment analysis pipeline
sentiment_analyzer = pipeline(____, model=____, tokenizer=____)

review_text = "Surprisingly, the film is a very good one"

# Classify the sentiment of the review
sentiment = sentiment_analyzer(____)
print(f"Sentiment Analysis Result: {sentiment}")
編輯並執行程式碼