8 篇文章带有标签 “DeepLearningAI”

PyTorch 神经网络实战:从训练到推理的完整指南

该文本提供了一个关于PyTorch二分类神经网络的实现与性能分析的全面概述。首先,它通过具体代码示例展示了如何构建、训练、评估和保存一个基础的神经网络模型,并演示了如何加载模型进行推理。其次,文章深入探讨了不同模型参数规模下Apple的MPS(Metal Performance Shaders)框架与CPU训练时间上的性能对比,通过表格数据清晰地呈现了MPS在处理大型模型时相较于CPU的显著优势,并指出了性能的“转折点”

我的电脑是 Apple MacBook Pro M2 Max 16寸 64G内存

这不是好的实践,因为训练和数据加载在同一个 for 循环中顺序进行。每次我们加载下一个小批量时,模型和 GPU 都处于空闲状态。

理想情况下,我们希望模型在后向调用和参数更新(通过.step())后立即处理下一个小批量。换句话说,目标是在模型准备就绪后立即准备好下一个小批量,因此我们希望在模型训练期间持续在后台加载小批量。遗憾的是,由于 Python 有一个全局解释器锁 (GIL),默认情况下只允许它运行单个进程,因此我们必须编写一个复杂的解决方法。

值得庆幸的是,我们可以使用 PyTorch 的 DataLoader 来实现这一点。

Functions, Tools and Agents with LangChain

messages.append(response["choices"][0]["message"].to_dict())

args = json.loads(response["choices"][0]["message"]['function_call']['arguments'])
observation = get_current_weather(args)

messages.append(
        {
            "role": "function",
            "name": "get_current_weather",
            "content": observation,
        }
)

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
// ...

Prompt Engineering with Llama 2

prompt = """
What is the sentiment of:
Hi Amit, thanks for the thoughtful birthday card!
"""
response = llama(prompt)
print(response)
  The sentiment of the message "Hi Amit, thanks for the thoughtful birthday card!" is positive. The use of the word "thoughtful" implies that the sender appreciated the effort put into the card, and the tone is friendly and sincere.

中文

Open Source Models with Hugging Face

安装依赖库

pip install transformers
from transformers.utils import logging
logging.set_verbosity_error()

from transformers import pipeline
chatbot = pipeline(task="conversational", model="facebook/blenderbot-400M-distill")

from transformers import Conversation
user_message = "What are some fun activities I can do in the winter?"
conversation = Conversation(user_message)
conversation = chatbot(conversation)
print(conversation)

# 继续对话:要在 LLM 上下文中包含之前的对话,您可以添加一条“消息”以包含之前的聊天历史记录。
conversation.add_message(
    {
// ...

生成式AI

  • 闭源
    • 云 API
    • 易用
    • 功能强大
    • 成本低
    • 安全性低

每个角色的工作一般由多个任务组成,需要先分解任务,然后对每个任务进行生成式人工智能潜力分析。

人工智能赋能任务的方式

  • 增强
  • 自动化

要完成使用人工智能来增强或自动化任务,需要考虑的主要因素:

  • 技术可行性
  • 业务价值
  • 成本节省 -> 收入增长
  • 改造工作流程