什么是 Llama?

使用 Llama 3

Imtihan Ahmed

Machine Learning Engineer

认识讲师

 

  • Imtihan Ahmed
  • 机器学习工程师
  • 6 年经验
  • 大规模 AI 实践

  Instructor profile photo

使用 Llama 3

什么是 Llama 3?

 

  • 摘要生成

Screenshot 2025-02-19 at 11.01.25.png

使用 Llama 3

什么是 Llama 3?

 

  • 摘要生成

 

  • 数据分析

Screenshot 2025-02-19 at 11.01.16.png

使用 Llama 3

什么是 Llama 3?

 

  • 摘要生成

 

  • 数据分析

 

  • 编码助手

Screenshot 2025-02-19 at 11.01.07.png

使用 Llama 3

什么是 Llama 3?

Screenshot 2025-02-19 at 11.32.24.png

Llama 3:

  • 由 Meta 开发
使用 Llama 3

什么是 Llama 3?

Screenshot 2025-02-19 at 11.32.18.png

Llama 3:

  • 由 Meta 开发
  • 文本生成
使用 Llama 3

什么是 Llama 3?

Screenshot 2025-02-19 at 11.32.12.png

  • 由 Meta 开发
  • 文本生成
  • 以海量数据训练
    • 相当于 2000 个维基百科
  • 开源
使用 Llama 3

为何本地运行 Llama 3

  • 示例:工业自动化
    • Llama 预测维护需求

3.jpg

1 https://ai.meta.com/blog/aitomatic-built-with-llama/
使用 Llama 3

为何本地运行 Llama 3

 

  • 隐私与安全

Screenshot 2025-02-19 at 11.48.10.png

使用 Llama 3

为何本地运行 Llama 3

 

  • 隐私与安全

 

  • 降低成本

Screenshot 2025-02-19 at 11.48.03.png

使用 Llama 3

为何本地运行 Llama 3

 

  • 隐私与安全

 

  • 降低成本

 

  • 可定制化

Screenshot 2025-02-19 at 11.47.54.png

使用 Llama 3

本地使用 Llama

  • 安装 Python 后可在本地使用

Screenshot 2025-02-19 at 11.54.07.png

  • 可通过 llama-cpp-python 库使用
  • 运行 pip 安装
pip install llama-cpp-python
使用 Llama 3

向 Llama 提问

from llama_cpp import Llama

llm = Llama(model_path = "path/to/model.gguf")
output = llm("What are some ways to improve customer retention?")
  • 导入 Llama 类
  • 初始化 LLM
    • 可发送提示并获取回复
    • 模型为 GGUF 格式
  • 向 LLM 提问
使用 Llama 3

向 Llama 提问

 

  • 模型接收提示
  • 处理提示
  • 返回回复

prompting.jpg

使用 Llama 3

解读输出

  • 输出为字典格式
output
{'id': 'cmpl-af88304f-97b0-49f5-ba20-db87f86c4068',
 'object': 'text_completion',
 'created': 1715222298,
 'model': './Llama3-gguf-unsloth.Q4_K_M.gguf',
 'choices': [{'text': 'Improving customer retention is crucial for any business, as 
 it leads to increased revenue, positive word-of-mouth, and cost savings...'},
 ...]
}
使用 Llama 3

解读输出

  • "choices" 的第 0 个元素取 "text"
output["choices"][0]["text"]
'Improving customer retention is crucial for any business, as 
 it leads to increased revenue, positive word-of-mouth, and cost savings. 
 Here are some effective ways to boost customer retention:
 1. Personalize the Customer Experience
 Tailor your interactions with customers based on their preferences, behaviors, and 
 purchase history. Use data and analytics to create personalized offers, 
 recommendations, and communications.
 2. Foster Strong Relationships
 Build strong, human connections with your customers. Train your...'
使用 Llama 3

Passons à la pratique !

使用 Llama 3

Preparing Video For Download...