Հրահանգների ճշգրտում FLAN T5 XL-ի համար Amazon SageMaker Jumpstart-ի հետ

Generative AI-ն գտնվում է ցնցող աճի շրջանի մեջ: Շարունակաբար թողարկվում են ավելի ու ավելի հզոր հիմքի մոդելներ, ընդ որում մեծ լեզվական մոդելները (LLM) մոդելների ամենատեսանելի դասերից են: LLM-ները մոդելներ են, որոնք կազմված են միլիարդավոր պարամետրերից, որոնք պատրաստված են տեքստի ընդարձակ կորպուսների վրա, մինչև հարյուր միլիարդավոր կամ նույնիսկ տրիլիոն նշաններ: Այս մոդելները չափազանց արդյունավետ են ապացուցել տեքստի վրա հիմնված առաջադրանքների լայն շրջանակի համար՝ սկսած հարցերի պատասխանից մինչև տրամադրությունների վերլուծություն:

LLM-ների հզորությունը բխում է նրանց կարողությունից՝ սովորելու և ընդհանրացնելու լայն և բազմազան վերապատրաստման տվյալներից: Այս մոդելների նախնական ուսուցումն իրականացվում է տարբեր նպատակներով՝ վերահսկվող, չվերահսկվող կամ հիբրիդային: Տեքստի լրացումը կամ վերագրումը ամենատարածված չվերահսկվող նպատակներից մեկն է. հաշվի առնելով տեքստի մի հատվածը, մոդելը սովորում է ճշգրիտ կանխատեսել, թե ինչ է լինելու հաջորդը (օրինակ՝ գուշակել հաջորդ նախադասությունը): Մոդելները կարող են նաև վերապատրաստվել վերահսկվող ձևով՝ օգտագործելով պիտակավորված տվյալներ՝ մի շարք առաջադրանքներ կատարելու համար (օրինակ՝ այս ֆիլմի ակնարկը դրական է, բացասական, թե չեզոք): Անկախ նրանից, թե մոդելը պատրաստված է տեքստի լրացման կամ որևէ այլ առաջադրանքի համար, հաճախ հաճախորդները չեն ցանկանում օգտագործել մոդելը:

Որոշակի առաջադրանքի վրա նախապես վերապատրաստված LLM-ի կատարումը բարելավելու համար մենք կարող ենք կարգավորել մոդելը՝ օգտագործելով նպատակային առաջադրանքի օրինակներ մի գործընթացում, որը հայտնի է որպես. նուրբ հրահանգ-թյունինգ. Հրահանգների ճշգրտումը օգտագործում է պիտակավորված օրինակների մի շարք {prompt, answer} զույգերի տեսքով՝ նախապես պատրաստված մոդելին հետագա ուսուցանելու համար՝ համարժեք կերպով կանխատեսելու հուշում տրված պատասխանը: Այս գործընթացը փոփոխում է մոդելի կշիռները:

Այս գրառումը նկարագրում է, թե ինչպես կատարել LLM-ի, մասնավորապես, FLAN T5 XL-ի հրահանգների ճշգրտումը՝ օգտագործելով Amazon SageMaker Jumpstart-ը: Մենք ցույց ենք տալիս, թե ինչպես կարելի է դա իրականացնել՝ օգտագործելով և՛ Jumpstart UI-ը, և՛ նոթատետրը Amazon SageMaker Studio-ում: Ուղեկցող նոթատետրը կարող եք գտնել amazon-sagemaker-examples GitHub շտեմարանում:

Լուծման ակնարկ

Այս գրառման նպատակային խնդիրն է՝ ստանալով տեքստի մի կտոր հուշում, վերադարձնել հարցեր, որոնք առնչվում են տեքստին, բայց չեն կարող պատասխանել՝ հիմնվելով դրա պարունակած տեղեկատվության վրա: Սա օգտակար խնդիր է նկարագրության մեջ բացակայող տեղեկատվությունը բացահայտելու կամ պարզելու համար, թե արդյոք հարցմանը պետք է ավելի շատ տեղեկատվություն պատասխանելու համար:

FLAN T5 մոդելները ճշգրտված հրահանգներ են առաջադրանքների լայն շրջանակի համար, որպեսզի մեծացնեն այս մոդելների զրոյական կատարումը շատ սովորական առաջադրանքների դեպքում:[1]. Հաճախորդի որոշակի առաջադրանքի համար լրացուցիչ նուրբ հրահանգների կարգավորումը կարող է ավելի մեծացնել այս մոդելների ճշգրտությունը, հատկապես, եթե թիրախային առաջադրանքը նախկինում չի օգտագործվել FLAN T5 մոդելը վարժեցնելու համար, ինչպես դա մեր առաջադրանքի դեպքում է:

Մեր օրինակի առաջադրանքում մենք շահագրգռված ենք ստեղծել համապատասխան, բայց անպատասխան հարցեր: Այդ նպատակով մենք օգտագործում ենք Stanford Question Answering Dataset-ի 2-րդ տարբերակի ենթաբազմությունը (SQuAD2.0):[2] մոդելը ճշգրտելու համար: Այս տվյալների շտեմարանը պարունակում է Վիքիպեդիայի մի շարք հոդվածների վերաբերյալ մարդկանց ծանոթագրողների կողմից տրված հարցեր: Բացի պատասխաններով հարցերից, SQuAD2.0-ը պարունակում է մոտ 50000 անպատասխանատու հարցեր: Նման հարցերը հավանական են, բայց չեն կարող ուղղակիորեն պատասխանել հոդվածների բովանդակությունից: Մենք օգտագործում ենք միայն անպատասխան հարցերը։ Մեր տվյալները կառուցված են որպես JSON Lines ֆայլ, որտեղ յուրաքանչյուր տող պարունակում է համատեքստ և հարց:

SQuADv2 տվյալների բազայի մի քանի գրառումների սքրինշոթ:

Նախադրյալներ

Սկսելու համար ձեզ հարկավոր է ընդամենը AWS հաշիվ, որտեղ կարող եք օգտվել Studio-ից: Դուք պետք է ստեղծեք օգտվողի պրոֆիլ Studio-ի համար, եթե դեռ չունեք:

Կարգավորեք FLAN-T5-ը Jumpstart UI-ով

Jumpstart UI-ով մոդելը ճշգրտելու համար կատարեք հետևյալ քայլերը.

  1. SageMaker վահանակում բացեք Studio:
  2. Տակ SageMaker Jumpstart նավիգացիոն վահանակում ընտրեք Մոդելներ, տետրեր, լուծումներ.

Դուք կտեսնեք հիմքի մոդելների ցանկը, ներառյալ FLAN T5 XL-ը, որը նշված է որպես լավ կարգավորվող:

  1. Ընտրեք դիտել մոդելը.

JumpStart UI FLAN-T5 XL-ով:

  1. Տակ տվյալների աղբյուր, կարող եք տրամադրել ձեր վերապատրաստման տվյալների ուղին: Այս գրառման մեջ օգտագործված տվյալների աղբյուրը տրամադրված է լռելյայն:
  2. Դուք կարող եք պահպանել լռելյայն արժեքը տեղակայման կազմաձևման համար (ներառյալ օրինակի տեսակը), անվտանգությունը և հիպերպարամետրերը, բայց լավ արդյունքներ ստանալու համար պետք է դարաշրջանների թիվը հասցնել առնվազն երեքի:
  3. Ընտրեք Գնացք մոդելին վարժեցնելու համար։

JumpStart գնացքի միջերեսը FLAN-T5 XL մոդելի համար:

Դուք կարող եք հետևել վերապատրաստման աշխատանքի կարգավիճակին UI-ում:

Jumpstart UI-ն ընթացքի մեջ գտնվող ուսուցման համար:

  1. Երբ մարզումն ավարտվի (մեր դեպքում մոտ 53 րոպե հետո), ընտրեք Տեղակայել լավ կարգավորված մոդելը տեղակայելու համար:

JumpStart UI-ի ուսուցումն ավարտված է:

Վերջնական կետը ստեղծելուց հետո (մի քանի րոպե), դուք կարող եք բացել նոթատետր և սկսել օգտագործել ձեր ճշգրտված մոդելը:

Կարգավորել FLAN-T5-ը Python նոթատետրով

Մեր օրինակի նոթատետրը ցույց է տալիս, թե ինչպես օգտագործել Jumpstart-ը և SageMaker-ը՝ FLAN T5 XL մոդելը ծրագրային կերպով ճշգրտելու և տեղակայելու համար: Այն կարող է գործարկվել Studio-ում կամ տեղական մակարդակում:

Այս բաժնում մենք նախ քայլում ենք որոշ ընդհանուր կարգավորումների միջով: Այնուհետև դուք ճշգրտում եք մոդելը՝ օգտագործելով SQuADv2 տվյալների հավաքածուները: Հաջորդը, դուք տեղադրում եք մոդելի նախապես պատրաստված տարբերակը SageMaker-ի վերջնակետի հետևում և նույնն անում եք մանրակրկիտ կարգավորված մոդելի հետ: Վերջապես, դուք կարող եք հարցումներ կատարել վերջնական կետերում և համեմատել նախապես պատրաստված և ճշգրտված մոդելի արդյունքի որակը: Դուք կգտնեք, որ ճշգրտված մոդելի արտադրանքը շատ ավելի բարձր որակի է:

Նախադրեք նախադրյալներ

Սկսեք տեղադրելով և թարմացնելով անհրաժեշտ փաթեթները: Վերագործարկեք միջուկը հետևյալ ծածկագիրը գործարկելուց հետո.

!pip install nest-asyncio==1.5.5 --quiet
!pip install ipywidgets==8.0.4 --quiet
!pip install --upgrade sagemaker --quiet

Հաջորդը, ստացեք կատարման դերը, որը կապված է ընթացիկ նոթատետրի օրինակի հետ.

import boto3
import sagemaker
# Get current region, role, and default bucket
aws_region = boto3.Session().region_name
aws_role = sagemaker.session.Session().get_caller_identity_arn()
output_bucket = sagemaker.Session().default_bucket()
# This will be useful for printing
newline, bold, unbold = "\n", "\033[1m", "\033[0m"
print(f"{bold}aws_region:{unbold} {aws_region}")
print(f"{bold}aws_role:{unbold} {aws_role}")
print(f"{bold}output_bucket:{unbold} {output_bucket}"

Դուք կարող եք սահմանել հարմար բացվող ընտրացանկ, որը կցուցադրի մոդելի չափերը, որոնք մատչելի են ճշգրտման համար.

import IPython
from ipywidgets import Dropdown
from sagemaker.jumpstart.filters import And
from sagemaker.jumpstart.notebook_utils import list_jumpstart_models
# Default model choice
model_id = "huggingface-text2text-flan-t5-xl"
# Identify FLAN T5 models that support fine-tuning
filter_value = And(
"task == text2text", "framework == huggingface", "training_supported == true"
)
model_list = [m for m in list_jumpstart_models(filter=filter_value) if "flan-t5" in m]
# Display the model IDs in a dropdown, for user to select
dropdown = Dropdown(
value=model_id,
options=model_list,
description="FLAN T5 models available for fine-tuning:",
style={"description_width": "initial"},
layout={"width": "max-content"},
)
display(IPython.display.Markdown("### Select a pre-trained model from the dropdown below"))
display(dropdown)

Jumpstart-ը ավտոմատ կերպով առբերում է համապատասխան ուսուցման և եզրակացության օրինակների տեսակները ձեր ընտրած մոդելի համար.

from sagemaker.instance_types import retrieve_default
model_id, model_version = dropdown.value, "*"
# Instance types for training and inference
training_instance_type = retrieve_default(
model_id=model_id, model_version=model_version, scope="training"
)
inference_instance_type = retrieve_default(
model_id=model_id, model_version=model_version, scope="inference"
)
print(f"{bold}model_id:{unbold} {model_id}")
print(f"{bold}training_instance_type:{unbold} {training_instance_type}")
print(f"{bold}inference_instance_type:{unbold} {inference_instance_type}")

If you have chosen the FLAN T5 XL, you will see the following output:

model_id: huggingface-text2text-flan-t5-xl

training_instance_type: ml.p3.16xlarge

inference_instance_type: ml.g5.2xlarge

Այժմ դուք պատրաստ եք սկսել կարգավորել:

Վերապատրաստեք մոդելը ճշգրտված տվյալների բազայի վրա

Կարգավորումն ավարտվելուց հետո կատարեք հետևյալ քայլերը.

Անհրաժեշտ արտեֆակտների համար URI-ն առբերելու համար օգտագործեք հետևյալ կոդը.

from sagemaker import image_uris, model_uris, script_uris
# Training instance will use this image
train_image_uri = image_uris.retrieve(
region=aws_region,
framework=None,  # automatically inferred from model_id
model_id=model_id,
model_version=model_version,
image_scope="training",
instance_type=training_instance_type,
)
# Pre-trained model
train_model_uri = model_uris.retrieve(
model_id=model_id, model_version=model_version, model_scope="training"
)
# Script to execute on the training instance
train_script_uri = script_uris.retrieve(
model_id=model_id, model_version=model_version, script_scope="training"
)
print(f"{bold}image uri:{unbold} {train_image_uri}")
print(f"{bold}model uri:{unbold} {train_model_uri}")
print(f"{bold}script uri:{unbold} {train_script_uri}")

Ուսուցման տվյալները գտնվում են հանրային Amazon Simple Storage Service (Amazon S3) դույլում:

Օգտագործեք հետևյալ ծածկագիրը՝ մատնանշելու տվյալների գտնվելու վայրը և կարգավորելու ելքային գտնվելու վայրը ձեր հաշվի դույլով.

from sagemaker.s3 import S3Downloader

# We will use the train split of SQuAD2.0
original_data_file = "train-v2.0.json"

# The data was mirrored in the following bucket
original_data_location = f"s3://sagemaker-sample-files/datasets/text/squad2.0/{original_data_file}"
S3Downloader.download(original_data_location, ".")

Բնօրինակ տվյալները այնպիսի ձևաչափով չեն, որը համապատասխանում է այն առաջադրանքին, որի համար դուք ճշգրտում եք մոդելը, այնպես որ կարող եք վերափոխել այն.

import json

local_data_file = "task-data.jsonl"  # any name with .jsonl extension

with open(original_data_file) as f:
data = json.load(f)

with open(local_data_file, "w") as f:
for article in data["data"]:
for paragraph in article["paragraphs"]:
# iterate over questions for a given paragraph
for qas in paragraph["qas"]:
if qas["is_impossible"]:
# the question is relevant, but cannot be answered
example = {"context": paragraph["context"], "question": qas["question"]}
json.dump(example, f)
f.write("\n")

template = {
"prompt": "Ask a question which is related to the following text, but cannot be answered based on the text. Text: {context}",
"completion": "{question}",
}
with open("template.json", "w") as f:
json.dump(template, f)

from sagemaker.s3 import S3Uploader

train_data_location = f"s3://{output_bucket}/train_data"
S3Uploader.upload(local_data_file, train_data_location)
S3Uploader.upload("template.json", train_data_location)
print(f"{bold}training data:{unbold} {train_data_location}")

Այժմ դուք կարող եք սահմանել որոշ հիպերպարամետրեր վերապատրաստման համար.

from sagemaker import hyperparameters

# Retrieve the default hyper-parameters for fine-tuning the model
hyperparameters = hyperparameters.retrieve_default(model_id=model_id, model_version=model_version)

# We will override some default hyperparameters with custom values
hyperparameters["epochs"] = "3"
# TODO
# hyperparameters["max_input_length"] = "300"  # data inputs will be truncated at this length
# hyperparameters["max_output_length"] = "40"  # data outputs will be truncated at this length
# hyperparameters["generation_max_length"] = "40"  # max length of generated output
print(hyperparameters)

Այժմ դուք պատրաստ եք սկսել վերապատրաստման աշխատանքը.

from sagemaker.estimator import Estimator
from sagemaker.utils import name_from_base

model_name = "-".join(model_id.split("-")[2:])  # get the most informative part of ID
training_job_name = name_from_base(f"js-demo-{model_name}-{hyperparameters['epochs']}")
print(f"{bold}job name:{unbold} {training_job_name}")

training_metric_definitions = [
{"Name": "val_loss", "Regex": "'eval_loss': ([0-9\\.]+)"},
{"Name": "train_loss", "Regex": "'loss': ([0-9\\.]+)"},
{"Name": "epoch", "Regex": "'epoch': ([0-9\\.]+)"},
]

# Create SageMaker Estimator instance
sm_estimator = Estimator(
role=aws_role,
image_uri=train_image_uri,
model_uri=train_model_uri,
source_dir=train_script_uri,
entry_point="transfer_learning.py",
instance_count=1,
instance_type=training_instance_type,
volume_size=300,
max_run=360000,
hyperparameters=hyperparameters,
output_path=output_location,
metric_definitions=training_metric_definitions,
)

# Launch a SageMaker training job over data located in the given S3 path
# Training jobs can take hours, it is recommended to set wait=False,
# and monitor job status through SageMaker console
sm_estimator.fit({"training": train_data_location}, job_name=training_job_name, wait=False)

Կախված ճշգրտման տվյալների և ընտրված մոդելի չափից, ճշգրտումը կարող է տևել մինչև մի քանի ժամ:

Դուք կարող եք վերահսկել կատարողականի չափանիշները, ինչպիսիք են մարզումները և վավերացման կորուստը, օգտագործելով Amazon CloudWatch-ը մարզումների ընթացքում: Հարմար է, դուք կարող եք նաև ստանալ չափումների ամենավերջին պատկերը՝ գործարկելով հետևյալ կոդը.

from sagemaker import TrainingJobAnalytics

# This can be called while the job is still running
df = TrainingJobAnalytics(training_job_name=training_job_name).dataframe()
df.head(10)

model uri: s3://sagemaker-us-west-2-802376408542/avkan/training-huggingface-text2text-huggingface-text2text-flan-t5-xl-repack.tar.gz
job name: jumpstart-demo-xl-3-2023-04-06-08-16-42-738
INFO:sagemaker:Creating training-job with name: jumpstart-demo-xl-3-2023-04-06-08-16-42-738

Երբ վերապատրաստումն ավարտված է, դուք ունեք լավ կարգավորված մոդել model_uri. Եկեք օգտագործենք այն:

Դուք կարող եք ստեղծել երկու եզրահանգման վերջնակետ՝ մեկը նախնական պատրաստված մոդելի համար, և մեկը՝ ճշգրտված մոդելի համար: Սա թույլ է տալիս համեմատել մոդելի երկու տարբերակների արդյունքը: Հաջորդ քայլում դուք տեղադրում եք եզրակացության վերջնակետ նախապես պատրաստված մոդելի համար: Այնուհետև տեղադրում եք վերջնական կետ ձեր ճշգրտված մոդելի համար:

Տեղադրեք նախապես պատրաստված մոդելը

Եկեք սկսենք տեղակայելով նախապես պատրաստված մոդելը, որը կվերցնի Docker պատկերի URI-ի եզրակացությունը: Սա Hugging Face կոնտեյների բազային պատկերն է: Օգտագործեք հետևյալ կոդը.

from sagemaker import image_uris

# Retrieve the inference docker image URI. This is the base HuggingFace container image
deploy_image_uri = image_uris.retrieve(
region=None,
framework=None,  # automatically inferred from model_id
model_id=model_id,
model_version=model_version,
image_scope="inference",
instance_type=inference_instance_type,
)

Այժմ կարող եք ստեղծել վերջնակետը և կիրառել նախապես պատրաստված մոդելը: Նկատի ունեցեք, որ դուք պետք է անցնեք Predictor դասը, երբ մոդելը տեղադրեք Model դասի միջով, որպեսզի կարողանաք եզրակացություններ կատարել SageMaker API-ի միջոցով: Տես հետևյալ կոդը.

from sagemaker import model_uris, script_uris
from sagemaker.model import Model
from sagemaker.predictor import Predictor
from sagemaker.utils import name_from_base

# Retrieve the URI of the pre-trained model
pre_trained_model_uri = model_uris.retrieve(
model_id=model_id, model_version=model_version, model_scope="inference"
)

pre_trained_name = name_from_base(f"jumpstart-demo-pre-trained-{model_id}")

# Create the SageMaker model instance of the pre-trained model
if ("small" in model_id) or ("base" in model_id):
deploy_source_uri = script_uris.retrieve(
model_id=model_id, model_version=model_version, script_scope="inference"
)
pre_trained_model = Model(
image_uri=deploy_image_uri,
source_dir=deploy_source_uri,
entry_point="inference.py",
model_data=pre_trained_model_uri,
role=aws_role,
predictor_cls=Predictor,
name=pre_trained_name,
)
else:
# For those large models, we already repack the inference script and model
# artifacts for you, so the `source_dir` argument to Model is not required.
pre_trained_model = Model(
image_uri=deploy_image_uri,
model_data=pre_trained_model_uri,
role=aws_role,
predictor_cls=Predictor,
name=pre_trained_name,
)

print(f"{bold}image URI:{unbold}{newline} {deploy_image_uri}")
print(f"{bold}model URI:{unbold}{newline} {pre_trained_model_uri}")
print("Deploying an endpoint ...")

# Deploy the pre-trained model. 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
pre_trained_predictor = pre_trained_model.deploy(
initial_instance_count=1,
instance_type=inference_instance_type,
predictor_cls=Predictor,
endpoint_name=pre_trained_name,
)
print(f"{newline}Deployed an endpoint {pre_trained_name}")

Վերջնական կետի ստեղծումը և մոդելի տեղակայումը կարող է տևել մի քանի րոպե, այնուհետև ձեր վերջնակետը պատրաստ է ստանալ եզրակացության զանգեր:

Տեղադրեք մանրակրկիտ կարգավորված մոդելը

Եկեք տեղակայենք ճշգրտված մոդելը իր վերջնական կետում: Գործընթացը գրեթե նույնն է, ինչ մենք ավելի վաղ օգտագործել էինք նախապես պատրաստված մոդելի համար: Միակ տարբերությունն այն է, որ մենք օգտագործում ենք ճշգրտված մոդելի անվանումը և URI.

from sagemaker.model import Model
from sagemaker.predictor import Predictor
from sagemaker.utils import name_from_base

fine_tuned_name = name_from_base(f"jumpstart-demo-fine-tuned-{model_id}")
fine_tuned_model_uri = f"{output_location}{training_job_name}/output/model.tar.gz"

# Create the SageMaker model instance of the fine-tuned model
fine_tuned_model = Model(
image_uri=deploy_image_uri,
model_data=fine_tuned_model_uri,
role=aws_role,
predictor_cls=Predictor,
name=fine_tuned_name,
)

print(f"{bold}image URI:{unbold}{newline} {deploy_image_uri}")
print(f"{bold}model URI:{unbold}{newline} {fine_tuned_model_uri}")
print("Deploying an endpoint ...")

# Deploy the fine-tuned model.
fine_tuned_predictor = fine_tuned_model.deploy(
initial_instance_count=1,
instance_type=inference_instance_type,
predictor_cls=Predictor,
endpoint_name=fine_tuned_name,
)
print(f"{newline}Deployed an endpoint {fine_tuned_name}")

Երբ այս գործընթացն ավարտվի, և՛ նախապես պատրաստված, և՛ ճշգրտված մոդելները տեղադրվում են իրենց վերջնական կետերի հետևում: Եկեք համեմատենք դրանց արդյունքները:

Ստեղծեք արդյունք և համեմատեք արդյունքները

Սահմանեք որոշ օգտակար գործառույթներ՝ վերջնակետը հարցնելու և պատասխանը վերլուծելու համար.

import boto3
import json

# Parameters of (output) text generation. A great introduction to generation
# parameters can be found at https://huggingface.co/blog/how-to-generate
parameters = {
"max_length": 40,  # restrict the length of the generated text
"num_return_sequences": 5,  # we will inspect several model outputs
"num_beams": 10,  # use beam search
}

# Helper functions for running inference queries
def query_endpoint_with_json_payload(payload, endpoint_name):
encoded_json = json.dumps(payload).encode("utf-8")
client = boto3.client("runtime.sagemaker")
response = client.invoke_endpoint(
EndpointName=endpoint_name, ContentType="application/json", Body=encoded_json
)
return response

def parse_response_multiple_texts(query_response):
model_predictions = json.loads(query_response["Body"].read())
generated_text = model_predictions["generated_texts"]
return generated_text

def generate_questions(endpoint_name, text):
expanded_prompt = prompt.replace("{context}", text)
payload = {"text_inputs": expanded_prompt, **parameters}
query_response = query_endpoint_with_json_payload(payload, endpoint_name=endpoint_name)
generated_texts = parse_response_multiple_texts(query_response)
for i, generated_text in enumerate(generated_texts):
print(f"Response {i}: {generated_text}{newline}")

Կոդի հաջորդ հատվածում մենք սահմանում ենք հուշումը և թեստի տվյալները: Այն նկարագրում է մեր նպատակային առաջադրանքը, որն է՝ ստեղծել հարցեր, որոնք առնչվում են տրամադրված տեքստին, բայց դրա հիման վրա չեն կարող պատասխանել:

Փորձարկման տվյալները բաղկացած են երեք տարբեր պարբերություններից՝ մեկը Ավստրալիայի Ադելաիդա քաղաքի մասին՝ Վիքիպեդիայի էջի առաջին երկու պարբերություններից, մեկը՝ Amazon Elastic Block Store-ի (Amazon EBS) մասին Amazon EBS փաստաթղթերից, և մեկը՝ Amazon Comprehend-ի՝ Amazon-ից: Համապատասխանության փաստաթղթեր: Մենք ակնկալում ենք, որ մոդելը կբացահայտի այս պարբերություններին առնչվող հարցերը, սակայն դրանք չեն կարող պատասխանել այնտեղ ներկայացված տեղեկատվության հետ:

prompt = "Ask a question which is related to the following text, but cannot be answered based on the text. Text: {context}"

test_paragraphs = [
"""
Adelaide is the capital city of South Australia, the state's largest city and the fifth-most populous city in Australia.
"Adelaide" may refer to either Greater Adelaide (including the Adelaide Hills) or the Adelaide city centre.
The demonym Adelaidean is used to denote the city and the residents of Adelaide. The Traditional Owners of the Adelaide
region are the Kaurna people. The area of the city centre and surrounding parklands is called Tarndanya in the Kaurna language.

Adelaide is situated on the Adelaide Plains north of the Fleurieu Peninsula, between the Gulf St Vincent in the west and
the Mount Lofty Ranges in the east. Its metropolitan area extends 20 km (12 mi) from the coast to the foothills of
the Mount Lofty Ranges, and stretches 96 km (60 mi) from Gawler in the north to Sellicks Beach in the south.
""",
"""
Amazon Elastic Block Store (Amazon EBS) provides block level storage volumes for use with EC2 instances. EBS volumes behave like raw, unformatted block devices. You can mount these volumes as devices on your instances. EBS volumes that are attached to an instance are exposed as storage volumes that persist independently from the life of the instance. You can create a file system on top of these volumes, or use them in any way you would use a block device (such as a hard drive). You can dynamically change the configuration of a volume attached to an instance.

We recommend Amazon EBS for data that must be quickly accessible and requires long-term persistence. EBS volumes are particularly well-suited for use as the primary storage for file systems, databases, or for any applications that require fine granular updates and access to raw, unformatted, block-level storage. Amazon EBS is well suited to both database-style applications that rely on random reads and writes, and to throughput-intensive applications that perform long, continuous reads and writes.
""",
"""
Amazon Comprehend uses natural language processing (NLP) to extract insights about the content of documents. It develops insights by recognizing the entities, key phrases, language, sentiments, and other common elements in a document. Use Amazon Comprehend to create new products based on understanding the structure of documents. For example, using Amazon Comprehend you can search social networking feeds for mentions of products or scan an entire document repository for key phrases. 
You can access Amazon Comprehend document analysis capabilities using the Amazon Comprehend console or using the Amazon Comprehend APIs. You can run real-time analysis for small workloads or you can start asynchronous analysis jobs for large document sets. You can use the pre-trained models that Amazon Comprehend provides, or you can train your own custom models for classification and entity recognition. 
All of the Amazon Comprehend features accept UTF-8 text documents as the input. In addition, custom classification and custom entity recognition accept image files, PDF files, and Word files as input. 
Amazon Comprehend can examine and analyze documents in a variety of languages, depending on the specific feature. For more information, see Languages supported in Amazon Comprehend. Amazon Comprehend's Dominant language capability can examine documents and determine the dominant language for a far wider selection of languages.
"""
]

Այժմ կարող եք ստուգել վերջնակետերը՝ օգտագործելով օրինակ հոդվածները

print(f"{bold}Prompt:{unbold} {repr(prompt)}")
for paragraph in test_paragraphs:
print("-" * 80)
print(paragraph)
print("-" * 80)
print(f"{bold}pre-trained{unbold}")
generate_questions(pre_trained_name, paragraph)
print(f"{bold}fine-tuned{unbold}")
generate_questions(fine_tuned_name, paragraph)

Փորձարկման տվյալներ՝ Ադելաիդա

Մենք օգտագործում ենք հետևյալ համատեքստը.

delaide is the capital city of South Australia, the state's largest city and the fifth-most populous city in Australia.
"Adelaide" may refer to either Greater Adelaide (including the Adelaide Hills) or the Adelaide city centre.
The demonym Adelaidean is used to denote the city and the residents of Adelaide. The Traditional Owners of the Adelaide
region are the Kaurna people. The area of the city centre and surrounding parklands is called Tarndanya in the Kaurna language.

Adelaide is situated on the Adelaide Plains north of the Fleurieu Peninsula, between the Gulf St Vincent in the west and
the Mount Lofty Ranges in the east. Its metropolitan area extends 20 km (12 mi) from the coast to the foothills of
the Mount Lofty Ranges, and stretches 96 km (60 mi) from Gawler in the north to Sellicks Beach in the south.

Նախապես պատրաստված մոդելի պատասխանը հետևյալն է.

Response 0: What is the area of the city centre and surrounding parklands called in the Kaurna language?
Response 1: What is the area of the city centre and surrounding parklands is called Tarndanya in the Kaurna language?
Response 2: What is the area of the city centre and surrounding parklands called in Kaurna?
Response 3: What is the capital city of South Australia?
Response 4: What is the area of the city centre and surrounding parklands known as in the Kaurna language?

Մանրացված մոդելի պատասխանները հետևյալն են.

Response 0: What is the second most populous city in Australia?
Response 1: What is the fourth most populous city in Australia?
Response 2: What is the population of Gawler?
Response 3: What is the largest city in Australia?
Response 4: What is the fifth most populous city in the world?

Փորձարկման տվյալներ՝ Amazon EBS

Մենք օգտագործում ենք հետևյալ համատեքստը.

Amazon Elastic Block Store (Amazon EBS) provides block level storage volumes for use with EC2 instances. EBS volumes behave like raw, unformatted block devices. You can mount these volumes as devices on your instances. EBS volumes that are attached to an instance are exposed as storage volumes that persist independently from the life of the instance. You can create a file system on top of these volumes, or use them in any way you would use a block device (such as a hard drive). You can dynamically change the configuration of a volume attached to an instance.

We recommend Amazon EBS for data that must be quickly accessible and requires long-term persistence. EBS volumes are particularly well-suited for use as the primary storage for file systems, databases, or for any applications that require fine granular updates and access to raw, unformatted, block-level storage. Amazon EBS is well suited to both database-style applications that rely on random reads and writes, and to throughput-intensive applications that perform long, continuous reads and writes.

Նախապես պատրաստված մոդելի պատասխանները հետևյալն են.

esponse 0: What is the difference between Amazon EBS and Amazon Elastic Block Store (Amazon EBS)?
Response 1: What is the difference between Amazon EBS and Amazon Elastic Block Store?
Response 2: What is the difference between Amazon EBS and Amazon Simple Storage Service (Amazon S3)?
Response 3: What is Amazon Elastic Block Store (Amazon EBS)?
Response 4: What is the difference between Amazon EBS and a hard drive?

Մանրացված մոդելի պատասխանները հետևյալն են.

Response 0: What type of applications are not well suited to Amazon EBS?
Response 1: What behaves like formatted block devices?
Response 2: What type of applications are not suited to Amazon EBS?
Response 3: What type of applications are not well suited for Amazon EBS?
Response 4: What type of applications are not suited for Amazon EBS?

Փորձարկման տվյալներ՝ Amazon Compliance

Մենք օգտագործում ենք հետևյալ համատեքստը.

Amazon Comprehend uses natural language processing (NLP) to extract insights about the content of documents. It develops insights by recognizing the entities, key phrases, language, sentiments, and other common elements in a document. Use Amazon Comprehend to create new products based on understanding the structure of documents. For example, using Amazon Comprehend you can search social networking feeds for mentions of products or scan an entire document repository for key phrases. 
You can access Amazon Comprehend document analysis capabilities using the Amazon Comprehend console or using the Amazon Comprehend APIs. You can run real-time analysis for small workloads or you can start asynchronous analysis jobs for large document sets. You can use the pre-trained models that Amazon Comprehend provides, or you can train your own custom models for classification and entity recognition. 
All of the Amazon Comprehend features accept UTF-8 text documents as the input. In addition, custom classification and custom entity recognition accept image files, PDF files, and Word files as input. 
Amazon Comprehend can examine and analyze documents in a variety of languages, depending on the specific feature. For more information, see Languages supported in Amazon Comprehend. Amazon Comprehend's Dominant language capability can examine documents and determine the dominant language for a far wider selection of languages.

Նախապես պատրաստված մոդելի պատասխանները հետևյալն են.

Response 0: What does Amazon Comprehend use to extract insights about the content of documents?
Response 1: How does Amazon Comprehend extract insights about the content of documents?
Response 2: What does Amazon Comprehend use to develop insights about the content of documents?
Response 3: How does Amazon Comprehend develop insights about the content of documents?
Response 4: What does Amazon Comprehend use to extract insights about the content of a document?

Մանրացված մոդելի պատասխանները հետևյալն են.

Response 0: What does Amazon Comprehend use to extract insights about the structure of documents?
Response 1: How does Amazon Comprehend recognize sentiments in a document?
Response 2: What does Amazon Comprehend use to extract insights about the content of social networking feeds?
Response 3: What does Amazon Comprehend use to extract insights about the content of documents?
Response 4: What type of files does Amazon Comprehend reject as input?

Արդյունքների որակի տարբերությունը նախապես պատրաստված մոդելի և ճշգրտված մոդելի միջև ակնհայտ է: Հարմարեցված մոդելի կողմից տրված հարցերը շոշափում են թեմաների ավելի լայն շրջանակ: Դրանք համակարգված իմաստալից հարցեր են, ինչը միշտ չէ, որ տեղի է ունենում նախապես պատրաստված մոդելի դեպքում, ինչպես ցույց է տրված Amazon EBS-ի օրինակով:

Թեև սա պաշտոնական և համակարգված գնահատում չէ, պարզ է, որ ճշգրտման գործընթացը բարելավել է այս առաջադրանքի վերաբերյալ մոդելի պատասխանների որակը:

մաքրել

Ի վերջո, հիշեք մաքրել և ջնջել վերջնակետերը.

# Delete resources
pre_trained_predictor.delete_model()
pre_trained_predictor.delete_endpoint()
fine_tuned_predictor.delete_model()
fine_tuned_predictor.delete_endpoint()

Եզրակացություն

Այս գրառման մեջ մենք ցույց տվեցինք, թե ինչպես օգտագործել հրահանգների ճշգրտումը FLAN T5 մոդելների հետ՝ օգտագործելով Jumpstart UI կամ Jupyter նոթատետր, որն աշխատում է Studio-ում: Մենք տրամադրեցինք ծածկագիր, որը բացատրում է, թե ինչպես կարելի է վերապատրաստել մոդելը՝ օգտագործելով տվյալներ նպատակային առաջադրանքի համար և տեղակայել ճշգրտված մոդելը վերջնակետի հետևում: Այս գրառման նպատակային խնդիրն էր բացահայտել այն հարցերը, որոնք վերաբերում են մուտքագրված տեքստի մի հատվածին, բայց չեն կարող պատասխանվել այդ տեքստում ներկայացված տեղեկատվության հիման վրա: Մենք ցույց տվեցինք, որ այս կոնկրետ առաջադրանքի համար ճշգրտված մոդելը ավելի լավ արդյունքներ է տալիս, քան նախապես պատրաստված մոդելը:

Այժմ, երբ դուք գիտեք, թե ինչպես ճշգրտել մոդելը Jumpstart-ով, կարող եք ստեղծել ձեր հավելվածի համար հարմարեցված հզոր մոդելներ: Հավաքեք որոշ տվյալներ ձեր օգտագործման դեպքի համար, վերբեռնեք այն Amazon S3-ում և օգտագործեք Studio UI կամ նոթատետր՝ FLAN T5 մոդելը կարգավորելու համար:

Հղումներ

[1] Չունգ, Հյոնգ Վոն և այլն: «Հրահանգների մասշտաբում՝ լավ կարգավորված լեզվական մոդելներ»: arXiv նախատպել arXiv:2210.11416 (2022):

[2] Ռաջպուրկարը, Պրանավը, Ռոբին Ջիան և Պերսի Լիանգը: «Իմացիր այն, ինչ չգիտես. անպատասխան հարցեր SQuAD-ի համար»: Հաշվողական լեզվաբանության ասոցիացիայի 56-րդ տարեկան ժողովի նյութեր (հատոր 2. կարճ աշխատություններ). 2018 թ.


Հեղինակների մասին

Լորան Կալլո AWS AI Labs-ի գլխավոր կիրառական գիտնական և մենեջեր է, ով աշխատել է մեքենայական ուսուցման մի շարք խնդիրների վրա՝ հիմնարար մոդելներից և գեներատիվ AI-ից մինչև կանխատեսում, անոմալիաների հայտնաբերում, պատճառականություն և AI Ops:

Անդրեյ Կան AWS AI Labs-ում ավագ կիրառական գիտնական է՝ մեքենայական ուսուցման տարբեր ոլորտներում հետաքրքրությունների և փորձի շրջանակներում: Դրանք ներառում են հիմքերի մոդելների հետազոտություն, ինչպես նաև գրաֆիկների և ժամանակային շարքերի ML հավելվածներ:

Դոկտ. Աշիշ Խեթան Ավագ կիրառական գիտնական է Amazon SageMaker-ի ներկառուցված ալգորիթմներով և օգնում է մշակել մեքենայական ուսուցման ալգորիթմներ: Նա իր PhD է ստացել Իլինոյսի համալսարանի Urbana Champaign-ում: Նա մեքենայական ուսուցման և վիճակագրական եզրակացության ակտիվ հետազոտող է և հրապարակել է բազմաթիվ հոդվածներ NeurIPS, ICML, ICLR, JMLR, ACL և EMNLP կոնֆերանսներում:

Բարիս Կուրտ AWS AI Labs-ում կիրառական գիտնական է: Նրա հետաքրքրությունները վերաբերում են ժամանակային շարքերի անոմալիաների հայտնաբերմանը և հիմքի մոդելներին: Նա սիրում է զարգացնել օգտագործողի համար հարմար ML համակարգեր:

Յոնաս Կուբլեր AWS AI Labs-ում կիրառական գիտնական է: Նա աշխատում է հիմքի մոդելների վրա՝ նպատակ ունենալով հեշտացնել օգտագործման դեպքերի հատուկ հավելվածները:

Source link