微调方法

Python 中的 LLM 入门

Jasmin Ludolf

Senior Data Science Content Developer, DataCamp

微调

 

LLMs fine-tuning chemistry use case

Python 中的 LLM 入门

全量微调

 

  • 更新整个模型权重
  • 计算成本高

 

Full fine-tuning

Python 中的 LLM 入门

部分微调

 

  • 固定部分层
  • 仅更新任务相关层

 

Partial fine-tuning

Python 中的 LLM 入门

迁移学习

 

  • 将预训练模型适配到不同但相关的任务
  • 利用一个领域的知识迁移到相关领域

The transfer learning paradigm

Python 中的 LLM 入门

N-shot 学习

  • 零样本学习:无示例
  • 一次示例学习:1 个示例
  • 小样本学习:多个示例
Python 中的 LLM 入门

一次示例学习(One-shot)

from transformers import pipeline

generator = pipeline(task="sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")

input_text = """
Classify the sentiment of this sentence as either Positive or Negative.
Example:
Text: "I'm feeling great today!" Sentiment: Positive
Text: "The weather today is lovely." Sentiment:
"""

result = generator(input_text, max_length=100)
print(result[0]["label"])
POSITIVE
Python 中的 LLM 入门

Passons à la pratique !

Python 中的 LLM 入门

Preparing Video For Download...