AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。

AlexaTM 20B 现已在 Amazon SageMaker JumpStart 中推出

今天,我们宣布公开提供亚马逊最先进的 具有 20 亿个参数的 Alexa 教师模型  (AlexaTM 20B) 通过 亚马逊SageMaker JumpStart,SageMaker 的机器学习中心。 AlexaTM 20B 是亚马逊开发的多语言大规模序列到序列(seq2seq)语言模型。 您可以将 AlexaTM 20B 用于广泛的行业用例,从汇总财务报告到客户服务聊天机器人的问题解答。 即使只有少数可用的训练示例,甚至根本没有,它也可以应用。 AlexaTM 20B 性能优于 175亿 GPT-3模型 在诸如 SuperGLUE 之类的零样本学习任务上,并展示了诸如 XNLI 之类的多语言零样本任务的最先进性能。

在这篇文章中,我们概述了如何通过 JumpStart API 以编程方式部署和运行 AlexaTM 20B 模型的推理,可在 SageMaker Python 开发工具包. 我们举例说明了如何使用此模型在多种语言之间进行翻译、总结长文本、根据给定的上下文回答问题以及生成看起来与人类编写的文本没有区别的文本。

AlexaTM 20B 和情境学习

Amazon Alexa AI 的 Alexa Teacher Model (AlexaTM) 程序旨在构建大规模、多语言的深度学习模型(主要基于 Transformer),旨在提高下游任务的泛化能力和处理数据稀缺性。 通过大规模预训练,教师模型可以很好地泛化以从稀疏数据中学习新任务,并帮助开发人员提高下游任务的性能。 AlexaTM 20B 已经显示 竞技表现 在常见的自然语言处理 (NLP) 基准和任务上,例如机器翻译、数据生成和摘要。

使用 AlexaTM 20B 等基础模型可减少对昂贵的模型预训练的需求,并提供最先进的起点,以更少的工作量和更少的特定于任务的训练数据来开发任务模型。 基础模型的关键能力之一是我们可以教模型执行新任务,例如用不同语言进行问答,输入示例非常少,不需要微调或梯度更新。 这被称为 情境学习. 只需提供几个新任务示例作为推理上下文,AlexaTM 20B 模型就可以从大规模预训练期间学到的知识进行迁移,甚至可以跨语言迁移。 这就是所谓的 少数学习. 在某些情况下,模型可以在根本没有任何训练数据的情况下表现良好,只需要解释应该预测的内容。 这就是所谓的 零镜头学习. 例如,假设我们使用 AlexaTM 20B 进行一次性自然语言生成。 传递给模型的输入是属性值对形式的训练示例,以及相应的输出文本叙述。 然后附加测试示例以形成完整的输入提示,如下图所示。

要了解有关该模型的更多信息,请查看 20B 参数 Alexa 模型在少样本学习中树立新标杆 或原始 .

AlexaTM 20B 的使用可用于非商业用途,并受 Alexa 教师模型许可协议.

解决方案概述

以下部分提供了有关如何部署模型、运行推理和进行上下文学习以解决少样本学习任务的分步演示。

请注意,以下部分包含代码片段; 包含此演示中所有步骤的完整代码可在随附的笔记本中找到: 在 SageMaker JumpStart 中使用 AlexaTM 20B 进行情境学习.

部署模型

要在 SageMaker 中使用大型语言模型,您需要一个特定于模型的推理脚本,其中包括模型加载、并行化等步骤。 您还需要为脚本、模型和所需的实例类型创建端到端测试,以验证这三者是否可以协同工作。 JumpStart 通过提供已经过可靠测试的现成脚本来消除这种努力。

SageMaker 使您能够广泛运行 Docker 容器以进行训练和推理。 JumpStart 使用这些可用的特定框架 SageMaker 深度学习容器 (DLC)。 我们首先获取优化的 DLC (deploy_image_uri) 使用 model_id. 然后我们获取 model_uri 包含模型参数,以及推理处理脚本和任何相关的依赖项。 接下来,我们创建一个 模型实例 在 SageMaker 中并将其部署到实时端点。 请参见以下代码:

# model_version="*" fetches the latest version of the model
model_id, model_version = "pytorch-textgeneration1-alexa20b", "*"

instance_type = "ml.g4dn.12xlarge"

# Retrieve the inference docker container uri
deploy_image_uri = image_uris.retrieve(
    region=None,
    framework=None,  # automatically inferred from model_id
    image_scope="inference",
    model_id=model_id,
    model_version=model_version,
    instance_type=inference_instance_type,
)

# Retrieve the model uri. This includes the model parameters, all dependencies and scripts for model loading, inference handling etc.
 model_uri = model_uris.retrieve(
 model_id=model_id, 
 model_version=model_version, 
 model_scope="inference")

部署 AlexaTM 20B 需要一个 GPU 支持的实例,该实例具有至少 50 GB 的 CPU 内存和至少 42 GB 的 GPU 内存。 SageMaker 提供了许多支持实时推理的此类实例。 我们在三个实例上测试了该解决方案:ml.g4dn.12xlarge、ml.p3.8xlarge、ml.p3.16xlarge。 请参见以下代码:

env = {
        "SAGEMAKER_MODEL_SERVER_TIMEOUT": str(3600),
        "MODEL_CACHE_ROOT": "/opt/ml/model",
        "SAGEMAKER_ENV": "1",
        "SAGEMAKER_SUBMIT_DIRECTORY":"/opt/ml/model/code/",
        "SAGEMAKER_PROGRAM": "inference.py",
        "SAGEMAKER_MODEL_SERVER_WORKERS": "1", # One worker for the endpoint rather than one worker per GPU by default
        "TS_DEFAULT_WORKERS_PER_MODEL":"1" # 1 TS worker which allocates all memory to the single master worker.
    }
    
#Create the SageMaker model instance. Note that we need to pass Predictor class when we deploy model through Model class,
#for being able to run inference through the sagemaker API.
model = Model(
    image_uri=deploy_image_uri,
    model_data=model_uri,
    role=aws_role,
    predictor_cls=Predictor,
    name=endpoint_name,
    env=env
)

接下来,我们将模型部署到 SageMaker 实时端点:

# deploy the Model.
model_predictor = model.deploy(
    initial_instance_count=1,
    instance_type=instance_type,
    endpoint_name=endpoint_name,
    volume_size= volume_size, # Specify the size of the Amazon EBS volume in GBs.
    model_data_download_timeout = 3600, # Specify the model download timeout in seconds.
    container_startup_health_check_timeout = 3600, # Specify the health checkup timeout in seconds
)

AlexaTM 20B 在推理容器中需要 40 GB 的磁盘空间。 ml.g4dn.12xlarge 实例满足此要求。 例如类型 ml.p3.8xlarge 和 ml.p3.16xlarge,我们附上一个 Amazon Elastic Block商店 (Amazon EBS) 卷来处理大模型尺寸。 因此,我们设 volume_size = None 在 ml.g4dn.12xlarge 和 volume_size=256 在 ml.p3.8xlarge 或 ml.p3.16xlarge 上部署时。

部署模型最多可能需要 10 分钟。 部署模型后,我们可以从中实时获得预测!

运行推理

AlexaTM 20B 是一种文本生成模型,它在给定部分序列(句子或一段文本)的情况下生成下一组单词。 以下代码片段让您大致了解如何查询我们部署的端点并解析自动完成任务的输出。 为了向部署的模型发送请求,我们使用以 UTF-8 格式编码的 JSON 字典。 端点响应是一个包含生成文本列表的 JSON 对象。

def query(model_predictor, text, kwargs = None):
    """Query the model predictor."""

    payload = {"text_inputs": text}
    if kwargs is not None:
        payload.update(kwargs)
        
    encoded_inp = json.dumps(payload).encode("utf-8")

    query_response = model_predictor.predict(
        encoded_inp,
        {
            "ContentType": "application/json",
            "Accept": "application/json",
        },
    )
    return query_response
 
def parse_response(query_response):
    """Parse response and return the generated texts."""

    model_predictions = json.loads(query_response)
    generated_texts = model_predictions["generated_texts"]
    return generated_texts

接下来,我们查询端点并解析示例输入文本的响应:

# text can be a single string or a list of strings
text = “[CLM]My name is Lewis and I like to"
kwargs = {"num_beams": 5, "no_repeat_ngram_size": 2, “max_length”: 50}
query_response = query_endpoint(model_predictor, text, kwargs)
generated_texts = parse_response(query_response)

Generated_texts: “travel and meet new people. I have been to many countries and I like to meet people from all over the world. If you are interested in meeting me, please feel free to send me a message and we can arrange a meeting.”

AlexaTM 20B 目前在推理时支持 10 个文本生成参数: max_length, num_return_sequences, num_beams, no_repeat_ngram_size, temperature, early_stopping, do_sample, top_k, top_pseed. 有关每个参数的有效值及其对输出的影响的详细信息,请参阅随附的笔记本: 在 SageMaker JumpStart 中使用 AlexaTM 20B 进行情境学习.

情境学习

上下文学习是指以下内容:我们为语言模型提供提示,其中包含演示任务的训练输入输出对。 我们将测试输入附加到提示中,并允许语言模型通过以提示为条件并预测下一个标记或单词来进行预测。 这是一种解决少数镜头学习问题的高效技术,我们从几个训练样本中学习任务。

接下来,我们将展示如何使用 AlexaTM 20B 通过上下文学习来完成多个 1-shot 和 20-shot 任务。 与之前的序列到序列模型不同,AlexaTM XNUMXB 除了去噪外还接受了因果语言建模训练,这使其成为上下文学习的良好模型。

1-shot 文本摘要

文本摘要是缩短数据并创建代表原始文本中最重要信息的摘要的任务。 1-shot text summarization 是指我们学习基于单个训练样本来总结文本的设置。 以下代码是来自 XSUM 数据集:

train_article = "The announcement ends months of uncertainty for Cornish Language Partnership staff whose contracts had been due to end. Local government minister Andrew Stunnell said the three-year funding package for the service would help make sure the language survived. But he warned that long term funding should come from Cornwall. He said it was "important to make sure the Cornish were given the opportunity to put down sound foundations." "In the longer term support for the Cornish language is going to be something which is going to have to be based in Cornwall and will not come from London," he added. The Cornish Language Partnership's, Jennifer Lowe, said: "We can now plan for the future thanks to the funding." The United Nations recently upgraded the status of the Cornish language from "extinct" to "critically endangered". It is thought fewer than 500 people worldwide are fluent in the language.""
                
train_summary = "The government is spending nearly £400,000 to help save the Cornish language."

test_article = "Torrents of water brought down a suspended ceiling and damaged stock "
                "in the Victoria Centre store at about 22:40 BST on Tuesday. Managers "
                "had hoped for a weekend reopening but it is now closed "until "
                "further notice". Staff have been helping with the clean-up "
                "operation. Water poured through from a rooftop room, leaving the "
                "top floor under three inches of water and stock "significantly" "
                "damaged. A spokeswoman said: "Our teams are working around the "
                "clock to get the shop open as quickly as possible and we're sorry "
                "for the inconvenience this has caused to our customers.""

当只提供一个训练样本时,我们使用以下提示进行总结。 模型生成的文本被解释为测试文章的预测摘要。

AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。

输出如下:

AlexaTM 20B output: 'The top floor of a London department store has been flooded.'

1-shot 自然语言生成

自然语言生成是在给定输入文本的情况下生成文本叙述的任务。 以下示例显示了来自 端到端数据集:

train_inp = "name[The Punter], food[Indian], priceRange[cheap]"
train_out = "The Punter provides Indian food in the cheap price range."

test_inp = "name[Blue Spice], eatType[coffee shop], area"

当只提供一个训练样本(1-shot)时,我们使用以下提示进行自然语言生成。 模型生成的文本被解释为测试输入的预测文本叙述(test_inp).

AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。

输出如下:

AlexaTM 20B output: 'Blue Spice is a coffee shop in the city centre. '

1-shot 机器翻译

机器翻译是将文本从一种语言翻译成另一种语言的任务。 以下示例显示了来自 WMT19 数据集 我们需要将其中的德语翻译成英语:

train_inp = "Das Parlament erhebt sich zu einer Schweigeminute."
train_out = "The House rose and observed a minute' s silence"

test_inp = "Kleingärtner bewirtschaften den einstigen Grund von Bauern."

当只提供一个训练样本(1-shot)时,我们使用以下提示进行机器翻译。 从模型生成的文本被解释为测试输入的翻译(test_inp).

AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。

输出如下:

AlexaTM 20B translation: 'Gardeners cultivate the former land of farmers.'

零样本抽取式问答

抽取式问答是从上下文段落中找到问题答案的任务。 以下是上下文和问题的示例 SQuAD v2 数据集:

test_context = "The Normans (Norman: Nourmands; French: Normands; Latin: Normanni) were the people who in the 10th and 11th centuries gave their name to Normandy, a region in France. They were descended from Norse ("Norman" comes from "Norseman") raiders and pirates from Denmark, Iceland and Norway who, under their leader Rollo, agreed to swear fealty to King Charles III of West Francia. Through generations of assimilation and mixing with the native Frankish and Roman-Gaulish populations, their descendants would gradually merge with the Carolingian-based cultures of West Francia. The distinct cultural and ethnic identity of the Normans emerged initially in the first half of the 10th century, and it continued to evolve over the succeeding centuries."
test_question = "In what country is Normandy located?"

请注意,我们的任务没有任何训练样本。 相反,我们创建了一个关于提示中最后一个词的虚拟问题,基于 test_context (假人射击)。 因此,我们实际上是在进行零样本抽取式问答。

当没有提供训练样本时,我们使用以下提示进行抽取式问答。 从模型生成的文本被解释为测试问题的答案。

AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。

输出如下:

AlexaTM 20B output: 'France'

即时工程

及时的工程有时可以成为一门艺术。 即使对提示模板进行微小的更改也可能导致模型在特定任务上的性能发生重大变化。 以下是编写好的提示模板的一些建议。 首先,重要的是要记住该模型是为学习真实句子的结构而训练的(因果语言建模)。 因此,最好确保您的提示模板在自然语言中的语法和结构都是正确的。 其次,这个特定的模型受益于虚拟镜头,以帮助教会它答案中预期的结构,如上所示。 第三,始终建议通过各种候选提示模板检查任务绩效。 提示源 和 自然指令 是两个用于标准化提示模板的开源框架,它们提供了用于现有建模任务的各种示例提示。 此外,附录 B AlexaTM 20B 纸 提供用于生成论文中呈现的结果的提示模板。 有一个不断发展的子领域致力于自动创建和学习任务的最佳提示,包括自然语言和连续提示。 这超出了本教程的范围。

结论

在本文中,我们展示了如何在 SageMaker 端点上部署 AlexaTM 20B 模型并运行推理。 您可以使用 AlexaTM 20B 模型进行各种小样本学习任务的情境学习。 要了解有关 AlexaTM 20B 的更多信息,请参阅 20B 参数 Alexa 模型在少样本学习中树立新标杆 或原始 .

作者要感谢 Maciej Rudnicki、Jakub Debski、Ashish Khetan、Anastasiia Dubinina、Vitaliy Korolev、Karl Albertsen、Saleh Soltan 和 Mariusz Momotko 为使此次发布成为可能所做的技术贡献。


关于 JumpStart

JumpStart 是 Amazon SageMaker 的机器学习 (ML) 中心,提供超过 350 个预训练模型、内置算法和预构建解决方案模板,可帮助您快速开始使用 ML。 JumpStart 托管来自 TensorFlow、PyTorch、Hugging Face 和 MXNet 等流行模型中心的最先进模型,这些模型支持对象检测、文本分类和文本生成等流行的 ML 任务。 ML 研究社区付出了大量努力,使大多数最近开发的模型都可以公开使用。 JumpStart 旨在帮助您找到正确的 ML 模型和算法,并立即开始构建模型。 具体而言,JumpStart 提供以下优势:

  • 通过 UI 和 SDK 轻松访问 – 您可以使用 SageMaker Python SDK 或通过 Amazon SageMaker Studio 中的 JumpStart UI 以编程方式访问 JumpStart 中的模型和算法。 目前,只能通过 SageMaker Python SDK 访问 AlexaTM 20B。
  • SageMaker 内置算法 – JumpStart 提供超过 350 种内置算法和预训练模型,以及相应的训练脚本(如果支持)、推理脚本和示例笔记本。 脚本针对每个框架和任务进行了优化,并提供 GPU 支持、自动模型调整和增量训练等功能。 脚本还针对 SageMaker 实例和功能进行了测试,因此您不会遇到兼容性问题。
  • 预构建的解决方案——JumpStart 为常见的 ML 用例提供了一套 23 种解决方案,例如需求预测以及工业和金融应用程序,您只需单击几下即可部署这些解决方案。 解决方案是端到端的 ML 应用程序,它们将各种 AWS 服务串在一起以解决特定的业务用例。 他们使用 AWS CloudFormation 模板和参考架构进行快速部署,这意味着它们是完全可定制的。
  • 支持——SageMaker 提供一系列支持,例如在发布新的 SageMaker 功能或 Deep Learning Container 版本时维护最新版本,以及创建有关如何在 SageMaker 环境中使用 JumpStart 内容的文档。

要了解有关 JumpStart 以及如何将开源预训练模型用于各种其他 ML 任务的更多信息,请查看以下内容 AWS re:Invent 2020 视频.


作者简介

AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。Vivek Madan 博士 是 Amazon SageMaker JumpStart 团队的一名应用科学家。 他在伊利诺伊大学厄巴纳-香槟分校获得博士学位,并且是乔治亚理工学院的博士后研究员。 他是机器学习和算法设计方面的活跃研究员,并在 EMNLP、ICLR、COLT、FOCS 和 SODA 会议上发表过论文。

AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。杰克菲茨杰拉德 是 Alexa AI 的高级应用科学家,目前专注于大型语言建模、多语言文本建模和机器学习操作。

AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。若昂·莫拉 是 Amazon Web Services 的 AI/ML 专家解决方案架构师。 他主要专注于 NLP 用例并帮助客户优化深度学习模型训练和部署。 他还是低代码 ML 解决方案和 ML 专用硬件的积极支持者。

AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。 六月赢了 是 SageMaker JumpStart 和内置算法的产品经理。 他专注于使 ML 内容易于为 SageMaker 客户发现和使用。

AlexaTM 20B 现已在 Amazon SageMaker JumpStart PlatoBlockchain 数据智能中提供。 垂直搜索。 哎呀。保吉卡普尔 是 Alexa AI 的 Alexa 教师模型项目的产品负责人,专注于 Alexa 的多任务多模态基础模型的通用智能和应用。

时间戳记:

更多来自 AWS机器学习