백엔드 개발 파이썬 튜토리얼 Amazon Bedrock을 사용하여 맞춤형 학습 동반자 구축

Amazon Bedrock을 사용하여 맞춤형 학습 동반자 구축

Jan 04, 2025 pm 08:25 PM

Building a Personalized Study Companion Using Amazon Bedrock

저는 지금 석사 학위 과정에 있는데 매일 학습 시간을 줄일 수 있는 방법을 항상 찾고 싶었습니다. 짜잔! 내 솔루션은 다음과 같습니다. Amazon Bedrock을 사용하여 학습 동반자를 만드는 것입니다.

Amazon Bedrock을 활용하여 GPT-4 또는 T5와 같은 기초 모델(FM)의 성능을 활용할 것입니다.

이러한 모델은 양자 물리학, 기계 학습 등 석사 과정의 다양한 주제에 대한 사용자 질문에 답할 수 있는 생성 AI를 만드는 데 도움이 될 것입니다. 모델을 미세 조정하고, 고급 프롬프트 엔지니어링을 구현하고, 검색 증강 생성(RAG)을 활용하여 학생들에게 정확한 답변을 제공하는 방법을 살펴보겠습니다.

들어가보자!

1단계: AWS에서 환경 설정

먼저 AWS 계정이 Amazon Bedrock, S3 및 Lambda에 액세스하는 데 필요한 권한으로 설정되어 있는지 확인하세요(직불 카드를 넣어야 한다는 사실을 알게 된 후 힘들게 배웠습니다 :( ) . Amazon S3, Lambda, Bedrock과 같은 AWS 서비스를 사용하게 됩니다.

  • 학습 자료를 저장할 S3 버킷 만들기
  • 이를 통해 모델은 미세 조정 및 검색을 위한 자료에 액세스할 수 있습니다.
  • Amazon S3 콘솔로 이동하여 새 버킷(예: "study-materials")을 생성합니다.

S3에 교육 콘텐츠를 업로드하세요. 내 경우에는 석사 과정과 관련된 내용을 추가하기 위해 합성 데이터를 만들었습니다. 필요에 따라 직접 생성하거나 Kaggle에서 다른 데이터세트를 추가할 수 있습니다.

[
    {
        "topic": "Advanced Economics",
        "question": "How does the Lucas Critique challenge traditional macroeconomic policy analysis?",
        "answer": "The Lucas Critique argues that traditional macroeconomic models' parameters are not policy-invariant because economic agents adjust their behavior based on expected policy changes, making historical relationships unreliable for policy evaluation."
    },
    {
        "topic": "Quantum Physics",
        "question": "Explain quantum entanglement and its implications for quantum computing.",
        "answer": "Quantum entanglement is a physical phenomenon where pairs of particles remain fundamentally connected regardless of distance. This property enables quantum computers to perform certain calculations exponentially faster than classical computers through quantum parallelism and superdense coding."
    },
    {
        "topic": "Advanced Statistics",
        "question": "What is the difference between frequentist and Bayesian approaches to statistical inference?",
        "answer": "Frequentist inference treats parameters as fixed and data as random, using probability to describe long-run frequency of events. Bayesian inference treats parameters as random variables with prior distributions, updated through data to form posterior distributions, allowing direct probability statements about parameters."
    },
    {
        "topic": "Machine Learning",
        "question": "How do transformers solve the long-range dependency problem in sequence modeling?",
        "answer": "Transformers use self-attention mechanisms to directly model relationships between all positions in a sequence, eliminating the need for recurrent connections. This allows parallel processing and better capture of long-range dependencies through multi-head attention and positional encodings."
    },
    {
        "topic": "Molecular Biology",
        "question": "What are the implications of epigenetic inheritance for evolutionary theory?",
        "answer": "Epigenetic inheritance challenges the traditional neo-Darwinian model by demonstrating that heritable changes in gene expression can occur without DNA sequence alterations, suggesting a Lamarckian component to evolution through environmentally-induced modifications."
    },
    {
        "topic": "Advanced Computer Architecture",
        "question": "How do non-volatile memory architectures impact traditional memory hierarchy design?",
        "answer": "Non-volatile memory architectures blur the traditional distinction between storage and memory, enabling persistent memory systems that combine storage durability with memory-like performance, requiring fundamental redesign of memory hierarchies and system software."
    }
]
로그인 후 복사
로그인 후 복사

2단계: 기초 모델에 Amazon Bedrock 활용

Amazon Bedrock을 시작한 후:

  • Amazon Bedrock 콘솔로 이동하세요.
  • 새 프로젝트를 만들고 원하는 기초 모델(예: GPT-3, T5)을 선택하세요.
  • 사용 사례를 선택하세요. 이 경우에는 학습 동반자입니다.
  • 미세 조정 옵션(필요한 경우)을 선택하고 미세 조정을 위한 데이터세트(S3의 교육 콘텐츠)를 업로드하세요.
  • 재단 모델 미세 조정:

Bedrock은 데이터 세트의 기초 모델을 자동으로 미세 조정합니다. 예를 들어 GPT-3를 사용하는 경우 Amazon Bedrock은 교육 콘텐츠를 더 잘 이해하고 특정 주제에 대한 정확한 답변을 생성하도록 이를 조정합니다.

다음은 Amazon Bedrock SDK를 사용하여 모델을 미세 조정하는 빠른 Python 코드 조각입니다.

import boto3

# Initialize Bedrock client
client = boto3.client("bedrock-runtime")

# Define S3 path for your dataset
dataset_path = 's3://study-materials/my-educational-dataset.json'

# Fine-tune the model
response = client.start_training(
    modelName="GPT-3",
    datasetLocation=dataset_path,
    trainingParameters={"batch_size": 16, "epochs": 5}
)
print(response)

로그인 후 복사
로그인 후 복사

미세 조정된 모델 저장: 미세 조정이 끝나면 모델이 저장되고 배포할 준비가 됩니다. Amazon S3 버킷의 Fine-tuned-model이라는 새 폴더에서 찾을 수 있습니다.

3단계: 검색 증강 생성(RAG) 구현

1. Amazon Lambda 함수 설정:

  • Lambda는 요청을 처리하고 미세 조정된 모델과 상호 작용하여 응답을 생성합니다.
  • Lambda 기능은 사용자 쿼리를 기반으로 S3에서 관련 학습 자료를 가져오고 RAG를 사용하여 정확한 답변을 생성합니다.

답변 생성을 위한 Lambda 코드: 다음은 답변 생성을 위해 미세 조정된 모델을 사용하도록 Lambda 함수를 구성하는 방법에 대한 예입니다.

[
    {
        "topic": "Advanced Economics",
        "question": "How does the Lucas Critique challenge traditional macroeconomic policy analysis?",
        "answer": "The Lucas Critique argues that traditional macroeconomic models' parameters are not policy-invariant because economic agents adjust their behavior based on expected policy changes, making historical relationships unreliable for policy evaluation."
    },
    {
        "topic": "Quantum Physics",
        "question": "Explain quantum entanglement and its implications for quantum computing.",
        "answer": "Quantum entanglement is a physical phenomenon where pairs of particles remain fundamentally connected regardless of distance. This property enables quantum computers to perform certain calculations exponentially faster than classical computers through quantum parallelism and superdense coding."
    },
    {
        "topic": "Advanced Statistics",
        "question": "What is the difference between frequentist and Bayesian approaches to statistical inference?",
        "answer": "Frequentist inference treats parameters as fixed and data as random, using probability to describe long-run frequency of events. Bayesian inference treats parameters as random variables with prior distributions, updated through data to form posterior distributions, allowing direct probability statements about parameters."
    },
    {
        "topic": "Machine Learning",
        "question": "How do transformers solve the long-range dependency problem in sequence modeling?",
        "answer": "Transformers use self-attention mechanisms to directly model relationships between all positions in a sequence, eliminating the need for recurrent connections. This allows parallel processing and better capture of long-range dependencies through multi-head attention and positional encodings."
    },
    {
        "topic": "Molecular Biology",
        "question": "What are the implications of epigenetic inheritance for evolutionary theory?",
        "answer": "Epigenetic inheritance challenges the traditional neo-Darwinian model by demonstrating that heritable changes in gene expression can occur without DNA sequence alterations, suggesting a Lamarckian component to evolution through environmentally-induced modifications."
    },
    {
        "topic": "Advanced Computer Architecture",
        "question": "How do non-volatile memory architectures impact traditional memory hierarchy design?",
        "answer": "Non-volatile memory architectures blur the traditional distinction between storage and memory, enabling persistent memory systems that combine storage durability with memory-like performance, requiring fundamental redesign of memory hierarchies and system software."
    }
]
로그인 후 복사
로그인 후 복사

3. Lambda 함수 배포: 이 Lambda 함수를 AWS에 배포합니다. 실시간 사용자 쿼리를 처리하기 위해 API Gateway를 통해 호출됩니다.

4단계: API 게이트웨이를 통해 모델 노출

API 게이트웨이 생성:

API Gateway 콘솔로 이동하여 새 REST API를 생성하세요.
답변 생성을 처리하는 Lambda 함수를 호출하도록 POST 엔드포인트를 설정하세요.

API 배포:

API를 배포하고 AWS의 사용자 지정 도메인이나 기본 URL을 사용하여 공개적으로 액세스할 수 있도록 합니다.

5단계: 간소화된 인터페이스 구축

마지막으로 사용자가 학습 동반자와 상호 작용할 수 있는 간단한 Streamlit 앱을 구축합니다.

import boto3

# Initialize Bedrock client
client = boto3.client("bedrock-runtime")

# Define S3 path for your dataset
dataset_path = 's3://study-materials/my-educational-dataset.json'

# Fine-tune the model
response = client.start_training(
    modelName="GPT-3",
    datasetLocation=dataset_path,
    trainingParameters={"batch_size": 16, "epochs": 5}
)
print(response)

로그인 후 복사
로그인 후 복사

Streamlit 앱AWS EC2 또는 Elastic Beanstalk에서 호스팅할 수 있습니다.

모든 일이 잘 진행된다면 축하드립니다. 당신은 방금 공부 동반자를 만들었습니다. 이 프로젝트를 평가해야 한다면 합성 데이터에 대한 몇 가지 예를 더 추가하거나(응??) 내 목표에 완벽하게 부합하는 또 다른 교육 데이터 세트를 얻을 수 있습니다.

읽어주셔서 감사합니다! 어떻게 생각하는지 알려주세요!

위 내용은 Amazon Bedrock을 사용하여 맞춤형 학습 동반자 구축의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)

Python vs. C : 응용 및 사용 사례가 비교되었습니다 Python vs. C : 응용 및 사용 사례가 비교되었습니다 Apr 12, 2025 am 12:01 AM

Python은 데이터 과학, 웹 개발 및 자동화 작업에 적합한 반면 C는 시스템 프로그래밍, 게임 개발 및 임베디드 시스템에 적합합니다. Python은 단순성과 강력한 생태계로 유명하며 C는 고성능 및 기본 제어 기능으로 유명합니다.

파이썬 : 게임, Guis 등 파이썬 : 게임, Guis 등 Apr 13, 2025 am 12:14 AM

Python은 게임 및 GUI 개발에서 탁월합니다. 1) 게임 개발은 Pygame을 사용하여 드로잉, 오디오 및 기타 기능을 제공하며 2D 게임을 만드는 데 적합합니다. 2) GUI 개발은 Tkinter 또는 PYQT를 선택할 수 있습니다. Tkinter는 간단하고 사용하기 쉽고 PYQT는 풍부한 기능을 가지고 있으며 전문 개발에 적합합니다.

2 시간 안에 얼마나 많은 파이썬을 배울 수 있습니까? 2 시간 안에 얼마나 많은 파이썬을 배울 수 있습니까? Apr 09, 2025 pm 04:33 PM

2 시간 이내에 파이썬의 기본 사항을 배울 수 있습니다. 1. 변수 및 데이터 유형을 배우십시오. 이를 통해 간단한 파이썬 프로그램 작성을 시작하는 데 도움이됩니다.

2 시간의 파이썬 계획 : 현실적인 접근 2 시간의 파이썬 계획 : 현실적인 접근 Apr 11, 2025 am 12:04 AM

2 시간 이내에 Python의 기본 프로그래밍 개념과 기술을 배울 수 있습니다. 1. 변수 및 데이터 유형을 배우기, 2. 마스터 제어 흐름 (조건부 명세서 및 루프), 3. 기능의 정의 및 사용을 이해하십시오. 4. 간단한 예제 및 코드 스 니펫을 통해 Python 프로그래밍을 신속하게 시작하십시오.

Python vs. C : 학습 곡선 및 사용 편의성 Python vs. C : 학습 곡선 및 사용 편의성 Apr 19, 2025 am 12:20 AM

Python은 배우고 사용하기 쉽고 C는 더 강력하지만 복잡합니다. 1. Python Syntax는 간결하며 초보자에게 적합합니다. 동적 타이핑 및 자동 메모리 관리를 사용하면 사용하기 쉽지만 런타임 오류가 발생할 수 있습니다. 2.C는 고성능 응용 프로그램에 적합한 저수준 제어 및 고급 기능을 제공하지만 학습 임계 값이 높고 수동 메모리 및 유형 안전 관리가 필요합니다.

파이썬 : 기본 응용 프로그램 탐색 파이썬 : 기본 응용 프로그램 탐색 Apr 10, 2025 am 09:41 AM

Python은 웹 개발, 데이터 과학, 기계 학습, 자동화 및 스크립팅 분야에서 널리 사용됩니다. 1) 웹 개발에서 Django 및 Flask 프레임 워크는 개발 프로세스를 단순화합니다. 2) 데이터 과학 및 기계 학습 분야에서 Numpy, Pandas, Scikit-Learn 및 Tensorflow 라이브러리는 강력한 지원을 제공합니다. 3) 자동화 및 스크립팅 측면에서 Python은 자동화 된 테스트 및 시스템 관리와 ​​같은 작업에 적합합니다.

파이썬과 시간 : 공부 시간을 최대한 활용 파이썬과 시간 : 공부 시간을 최대한 활용 Apr 14, 2025 am 12:02 AM

제한된 시간에 Python 학습 효율을 극대화하려면 Python의 DateTime, Time 및 Schedule 모듈을 사용할 수 있습니다. 1. DateTime 모듈은 학습 시간을 기록하고 계획하는 데 사용됩니다. 2. 시간 모듈은 학습과 휴식 시간을 설정하는 데 도움이됩니다. 3. 일정 모듈은 주간 학습 작업을 자동으로 배열합니다.

파이썬 : 자동화, 스크립팅 및 작업 관리 파이썬 : 자동화, 스크립팅 및 작업 관리 Apr 16, 2025 am 12:14 AM

파이썬은 자동화, 스크립팅 및 작업 관리가 탁월합니다. 1) 자동화 : 파일 백업은 OS 및 Shutil과 같은 표준 라이브러리를 통해 실현됩니다. 2) 스크립트 쓰기 : PSUTIL 라이브러리를 사용하여 시스템 리소스를 모니터링합니다. 3) 작업 관리 : 일정 라이브러리를 사용하여 작업을 예약하십시오. Python의 사용 편의성과 풍부한 라이브러리 지원으로 인해 이러한 영역에서 선호하는 도구가됩니다.

See all articles