KEMBAR78
AWS Summit Seoul 2023 | 생성 AI 모델의 임베딩 벡터를 이용한 서버리스 추천 검색 구현하기 | PDF
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
S E O U L | M A Y 4 , 2 0 2 3
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
생성 AI 모델의 임베딩벡터를 이용한
서버리스 추천/검색 구현하기
이상현
CEO
Mirror Co., Ltd.
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
• AWS Serverless Hero
• CEO, Mirror
• CTO,
• Tech Lead,
/ Kurt Lee
breath103@gmail.com
https://github.com/breath103
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1. AI /
2. AI / +
3. Serverless
Agenda
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
function cosineSimilarity(a: Array<Number>, b: Array<Number>) {
return dotProduct(a, b) / (length(a) * length(b))
}
function dotProduct(a: Array<Number>, b: Array<Number>) {
return zip(a, b).map((pair) => pair[0] * pair[1]).sum()
}
function length(a: Array<Number>) {
return sqrt(a.sum(s => Math.pow(s, 2)));
}
Disclaimer
• AI / ( ). Software Engineer
• .
•
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1. AI
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ML Model
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Deep Neural Network
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
…
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Convolutional Neural Network
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
/ / RNN
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Transformer
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
..
Activation Function,
Learning Rate,
Parameter count
…
variation
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
,
( )
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1. Encoder
Input “ ”
(Human readable Input) → (Latent Vector)
Decoder
“ ” Output
(Latent Vector) → (Human readable Output)
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ex) CNN Encoder
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1. “ ” Embedding Vector
2. “ ”
3. .
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Vector “ ” ?
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Not a joke
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
[0.10, 0.95]
[0.60, 0.60]
[0.95, 0.10]
[0.10, 0.10]
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1. , “ (feature)”
/
Latent Vector Space
( = Latent Vector Space)
Latent Vector =
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
,
3 .
“ ” , Vector
=
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
PCA / T-SNE ,
A.I. Experiments: Visualizing High-Dimensional Space
https://www.youtube.com/watch?v=wvsE8jm1GzE
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Latent space / Latent Feature Space / Embedding Space
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
function cosineSimilarity(a: Array<Number>, b: Array<Number>) {
return dotProduct(a, b) / (length(a) * length(b))
}
function dotProduct(a: Array<Number>, b: Array<Number>) {
return zip(a, b).map((pair) => pair[0] * pair[1]).sum()
}
function length(a: Array<Number>) {
return sqrt(a.sum(s => Math.pow(s, 2)));
}
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
2. Embedding Vector /
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
“ Vector ”
/
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Matrix Factorization / Collaborative Filtering
/ Latent Vector
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
?
1. vector
2. vector
3. vector
vector
1. vector
2. vector
3. vector
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ML ?
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1. “ ” .
( inference )
• , ,
• ex) “ ” → “ classification ”
• ,
• “ ” , .
• → GPT / Llama / BERT ,
Large Language Model
• → ImageNet (ResNet,
SAM…)
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
2. embedding .
• PyTorch / Tensorflow raw-level access :
.
embeddings .
• Huggingface , :
Huggingface transformers ,
.
• OpenAI , API SaaS :
text Array<Float> API .
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
🤗 Huggingface
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
🤗 Huggingface + Local Machine (BART)
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
🤗 Huggingface + SageMaker Inference
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
3. Context
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
?
1. vector
2. vector
3. vector
vector
1. vector
2. vector
3. vector
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
3. Serverless
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Serverless
• Computing Platform
• ( , …)
• (Memory, CPU, Persistency…)
• , , …
• Serverless ? ( X )
• Memory / CPU / Local storage ? ( O )
• Highly distributed computing system ? ( O )
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
)
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. www.mirror.work
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
• , emoji
Unicode ,
,
.
“🏠️”: “ , , ” — “ ” ?
“🏖️”: “ , ” — “ ” ?
“💰”: “ , , ” — “ ” ?
“🤖”: “ ” — “AI” ?
🎉🎉 Emoji 🎉🎉
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
1. Emoji + Vector (GPT-3.5 )
emoji_openai_embeddings.json (36 MB)
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
2. AWS Lambda
// Global context
const allEmojis: Array<{
emoji: string,
embeddings: number[]
}> = require("./emoji_openai_embeddings.json");
async function handler(event: { label: string }) {
// openAI embedding vector
const embedding: [number] = _.first((await OpenAIEmbeddings.getEmbeddings([event.label])));
return _.chain(allEmojis) // ,
.map((candidate) => {
//
return {
emoji: candidate.emoji,
distance: Math.sqrt(
_.chain(candidate.embeddings)
.sumBy((value, index) => {
Math.pow(candidate.embeddings[index] - embedding[index], 2)
})
) //
};
})
.sortBy((r) => r.distance)
.head(4) // 4
.map((r) => r.emoji)
}
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Demo
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Application
• ,
100%
• Q&A : “ ” =>
“Q: ”
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
• ?
Emoji embedding = 36MB
embedding ,
?
Serverless ?
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Vector Database
https://www.pinecone.io/learn/vector-database/
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Redis Vector Database
https://redis.io/docs/stack/search/reference/vectors/
Postgres pgVector
https://redis.io/docs/stack/search/reference/vectors/
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
SaaS
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Batch Computing / ?
서비스 종류
Fully
Serverless
Managed
데이터 수집 Kinesis Kafka
대용량 데이터 저장
S3 / Redshift
Serverless
Redshift /
ElasticSearch…
데이터 처리 Lambda Amazon EMR
실시간 데이터 저장 DynamoDB Redis / RDS
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ML + Serverless = 🎉🎉🎉
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved.
.

AWS Summit Seoul 2023 | 생성 AI 모델의 임베딩 벡터를 이용한 서버리스 추천 검색 구현하기

  • 1.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. S E O U L | M A Y 4 , 2 0 2 3
  • 2.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. 생성 AI 모델의 임베딩벡터를 이용한 서버리스 추천/검색 구현하기 이상현 CEO Mirror Co., Ltd.
  • 3.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. • AWS Serverless Hero • CEO, Mirror • CTO, • Tech Lead, / Kurt Lee breath103@gmail.com https://github.com/breath103
  • 4.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 1. AI / 2. AI / + 3. Serverless Agenda
  • 5.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. function cosineSimilarity(a: Array<Number>, b: Array<Number>) { return dotProduct(a, b) / (length(a) * length(b)) } function dotProduct(a: Array<Number>, b: Array<Number>) { return zip(a, b).map((pair) => pair[0] * pair[1]).sum() } function length(a: Array<Number>) { return sqrt(a.sum(s => Math.pow(s, 2))); } Disclaimer • AI / ( ). Software Engineer • . •
  • 6.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 1. AI
  • 7.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. ML Model
  • 8.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Deep Neural Network
  • 9.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. …
  • 10.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Convolutional Neural Network
  • 11.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. / / RNN
  • 12.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Transformer
  • 13.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. .. Activation Function, Learning Rate, Parameter count … variation
  • 14.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. , ( )
  • 15.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 1. Encoder Input “ ” (Human readable Input) → (Latent Vector) Decoder “ ” Output (Latent Vector) → (Human readable Output)
  • 16.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. ex) CNN Encoder
  • 17.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 1. “ ” Embedding Vector 2. “ ” 3. .
  • 18.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Vector “ ” ?
  • 19.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved.
  • 20.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved.
  • 21.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Not a joke
  • 22.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. [0.10, 0.95] [0.60, 0.60] [0.95, 0.10] [0.10, 0.10]
  • 23.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 1. , “ (feature)” / Latent Vector Space ( = Latent Vector Space) Latent Vector =
  • 24.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. , 3 . “ ” , Vector =
  • 25.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. PCA / T-SNE , A.I. Experiments: Visualizing High-Dimensional Space https://www.youtube.com/watch?v=wvsE8jm1GzE
  • 26.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Latent space / Latent Feature Space / Embedding Space
  • 27.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. function cosineSimilarity(a: Array<Number>, b: Array<Number>) { return dotProduct(a, b) / (length(a) * length(b)) } function dotProduct(a: Array<Number>, b: Array<Number>) { return zip(a, b).map((pair) => pair[0] * pair[1]).sum() } function length(a: Array<Number>) { return sqrt(a.sum(s => Math.pow(s, 2))); }
  • 28.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 2. Embedding Vector /
  • 29.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. “ Vector ” /
  • 30.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Matrix Factorization / Collaborative Filtering / Latent Vector
  • 31.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. ? 1. vector 2. vector 3. vector vector 1. vector 2. vector 3. vector
  • 32.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. ML ?
  • 33.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 1. “ ” . ( inference ) • , , • ex) “ ” → “ classification ” • , • “ ” , . • → GPT / Llama / BERT , Large Language Model • → ImageNet (ResNet, SAM…)
  • 34.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 2. embedding . • PyTorch / Tensorflow raw-level access : . embeddings . • Huggingface , : Huggingface transformers , . • OpenAI , API SaaS : text Array<Float> API .
  • 35.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 🤗 Huggingface
  • 36.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 🤗 Huggingface + Local Machine (BART)
  • 37.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 🤗 Huggingface + SageMaker Inference
  • 38.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 3. Context
  • 39.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. ? 1. vector 2. vector 3. vector vector 1. vector 2. vector 3. vector
  • 40.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 3. Serverless
  • 41.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Serverless • Computing Platform • ( , …) • (Memory, CPU, Persistency…) • , , … • Serverless ? ( X ) • Memory / CPU / Local storage ? ( O ) • Highly distributed computing system ? ( O )
  • 42.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. )
  • 43.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. www.mirror.work
  • 44.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved.
  • 45.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. • , emoji Unicode , , . “🏠️”: “ , , ” — “ ” ? “🏖️”: “ , ” — “ ” ? “💰”: “ , , ” — “ ” ? “🤖”: “ ” — “AI” ? 🎉🎉 Emoji 🎉🎉
  • 46.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 1. Emoji + Vector (GPT-3.5 ) emoji_openai_embeddings.json (36 MB)
  • 47.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. 2. AWS Lambda // Global context const allEmojis: Array<{ emoji: string, embeddings: number[] }> = require("./emoji_openai_embeddings.json"); async function handler(event: { label: string }) { // openAI embedding vector const embedding: [number] = _.first((await OpenAIEmbeddings.getEmbeddings([event.label]))); return _.chain(allEmojis) // , .map((candidate) => { // return { emoji: candidate.emoji, distance: Math.sqrt( _.chain(candidate.embeddings) .sumBy((value, index) => { Math.pow(candidate.embeddings[index] - embedding[index], 2) }) ) // }; }) .sortBy((r) => r.distance) .head(4) // 4 .map((r) => r.emoji) }
  • 48.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Demo
  • 49.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Application • , 100% • Q&A : “ ” => “Q: ”
  • 50.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. • ? Emoji embedding = 36MB embedding , ? Serverless ?
  • 51.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Vector Database https://www.pinecone.io/learn/vector-database/
  • 52.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Redis Vector Database https://redis.io/docs/stack/search/reference/vectors/ Postgres pgVector https://redis.io/docs/stack/search/reference/vectors/
  • 53.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. SaaS
  • 54.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. Batch Computing / ? 서비스 종류 Fully Serverless Managed 데이터 수집 Kinesis Kafka 대용량 데이터 저장 S3 / Redshift Serverless Redshift / ElasticSearch… 데이터 처리 Lambda Amazon EMR 실시간 데이터 저장 DynamoDB Redis / RDS
  • 55.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. ML + Serverless = 🎉🎉🎉
  • 56.
    © 2023, AmazonWeb Services, Inc. or its affiliates. All rights reserved. © 2023, Amazon Web Services, Inc. or its affiliates. All rights reserved. .