Hugging Face 파이프라인¶
Model Registry는 ``transformers.Pipeline``에서 파생되는 `변환기<https://huggingface.co/docs/transformers/index>`_로 정의된 Hugging Face 모델 클래스를 지원합니다. 예를 들면 다음과 같습니다.
lm_hf_model = transformers.pipeline(
task="text-generation",
model="bigscience/bloom-560m",
token="...", # Put your HuggingFace token here.
return_full_text=False,
max_new_tokens=100,
)
lmv = reg.log_model(lm_hf_model, model_name='bloom', version_name='v560m')
log_model 을 호출할 때 options 사전에서 다음 추가 옵션을 사용할 수 있습니다.
옵션 |
설명 |
|---|---|
|
모델 오브젝트에서 사용할 수 있는 메서드 이름 목록입니다. Hugging Face 모델에는 |
|
GPU 가 있는 플랫폼에 배포할 때 사용되는 CUDA 런타임 버전은 기본적으로 12.4입니다. 수동으로 |
중요
huggingface_pipeline.HuggingFacePipelineModel 기반 모델에는 구성 데이터만 포함되는데, 모델을 사용할 때마다 Hugging Face Hub에서 모델 가중치가 다운로드됩니다.
현재, Model Registry는 외부 네트워크 액세스 없이도 실행할 수 있는 독립형 모델만 지원합니다. 가장 좋은 방법은 위의 예와 같이 transformers.Pipeline 을 사용하는 것입니다. 이렇게 하면 모델 가중치를 로컬 시스템인 log_model 에 다운로드한 다음 인터넷 액세스가 필요 없는 독립형 모델 오브젝트를 업로드합니다.
레지스트리는 파이프라인에 다음 목록의 작업이 하나 포함되어 있는 경우에만 signatures 인자를 추론합니다.
conversationalfill-maskquestion-answeringsummarizationtable-question-answeringtext2text-generationtext-classification(sentiment-analysis라고도 함)text-generationtoken-classification(ner라고도 함)translationtranslation_xx_to_yyzero-shot-classification
log_model 에 대한 sample_input_data 인자는 Hugging Face 모델에서 완전히 무시됩니다. 레지스트리가 대상 메서드의 서명을 알 수 있도록 위 목록에 없는 Hugging Face 모델을 로깅할 때 signatures 인자를 지정하십시오.
추론된 서명을 보려면 show_functions 메서드를 사용하십시오. 예를 들어 다음 사전은 lmv.show_functions() 의 결과이며, 여기서 lmv 는 위에 로깅된 모델입니다.
{'name': '__CALL__',
'target_method': '__call__',
'signature': ModelSignature(
inputs=[
FeatureSpec(dtype=DataType.STRING, name='inputs')
],
outputs=[
FeatureSpec(dtype=DataType.STRING, name='outputs')
]
)}]
다음 코드를 사용하여 lmv 모델을 호출합니다.
import pandas as pd
remote_prediction = lmv.run(pd.DataFrame(["Hello, how are you?"], columns=["inputs"]))
사용법 노트¶
많은 Hugging Face 모델은 크기가 커서 표준 웨어하우스에 맞지 않습니다. Snowpark에 최적화된 웨어하우스를 사용하거나 더 작은 버전의 모델을 선택하십시오. 예를 들어
Llama-2-70b-chat-hf모델을 사용하는 대신Llama-2-7b-chat-hf를 사용해 보십시오.Snowflake 웨어하우스에는 GPU가 없습니다. CPU에 최적화된 Hugging Face 모델만 사용하십시오.
일부 Hugging Face 변환기는 입력 행마다 사전 배열을 반환합니다. 레지스트리는 사전 배열을 JSON 배열 표현이 포함된 문자열로 변환합니다. 예를 들어 다중 출력 질문 답변 출력은 이와 비슷하게 보입니다.
'[{"score": 0.61094731092453, "start": 139, "end": 178, "answer": "learn more about the world of athletics"}, {"score": 0.17750297486782074, "start": 139, "end": 180, "answer": "learn more about the world of athletics.\""}]'
예¶
# Prepare model
import transformers
import pandas as pd
finbert_model = transformers.pipeline(
task="text-classification",
model="ProsusAI/finbert",
top_k=2,
)
# Log the model
mv = registry.log_model(
finbert_model,
model_name="finbert",
version_name="v1",
)
# Use the model
mv.run(pd.DataFrame(
[
["I have a problem with my Snowflake that needs to be resolved asap!!", ""],
["I would like to have udon for today's dinner.", ""],
]
)
)
결과:
0 [{"label": "negative", "score": 0.8106237053871155}, {"label": "neutral", "score": 0.16587384045124054}]
1 [{"label": "neutral", "score": 0.9263970851898193}, {"label": "positive", "score": 0.05286872014403343}]
Hugging Face 파이프라인에 대한 추론된 서명¶
Snowflake Model Registry는 다음 목록에서 단일 작업을 포함하는 Hugging Face 파이프라인의 시그니처를 자동으로 추론합니다.
conversationalfill-maskquestion-answeringsummarizationtable-question-answeringtext2text-generationtext-classification(별칭은sentiment-analysis)text-generationtoken-classification(별칭은ner)translationtranslation_xx_to_yyzero-shot-classification
이 섹션에서는 요구 사항 및 예상 출력에 대한 설명과 예시를 포함하여 이러한 유형의 Hugging Face 파이프라인의 서명에 대해 설명합니다. 모든 입력과 출력은 Snowpark DataFrames입니다.
대화형 파이프라인¶
작업이 대화형 인 파이프라인으로, 입력과 출력은 다음과 같습니다.
입력¶
user_inputs: 사용자의 이전 입력과 현재 입력을 나타내는 문자열 목록입니다. 목록의 마지막 항목은 현재 입력입니다.generated_responses: 모델의 이전 응답을 나타내는 문자열 목록입니다.
예:
---------------------------------------------------------------------------
|"user_inputs" |"generated_responses" |
---------------------------------------------------------------------------
|[ |[ |
| "Do you speak French?", | "Yes I do." |
| "Do you know how to say Snowflake in French?" |] |
|] | |
---------------------------------------------------------------------------
출력¶
generated_responses: 모델의 이전 응답과 현재 응답을 나타내는 문자열 목록입니다. 목록의 마지막 항목은 현재 응답입니다.
예:
-------------------------
|"generated_responses" |
-------------------------
|[ |
| "Yes I do.", |
| "I speak French." |
|] |
-------------------------
마스크 채우기 파이프라인¶
작업이 “마스크 채우기 “ 인 파이프라인으로, 입력과 출력은 다음과 같습니다.
입력¶
inputs: 채워야 할 마스크가 있는 문자열입니다.
예:
--------------------------------------------------
|"inputs" |
--------------------------------------------------
|LynYuu is the [MASK] of the Grand Duchy of Yu. |
--------------------------------------------------
출력¶
outputs: 오브젝트 목록의 JSON 표현이 포함된 문자열로, 각 키에는score,token,token_str또는sequence같은 키가 포함될 수 있습니다. 자세한 내용은 FillMaskPipeline 섹션을 참조하십시오.
예:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|"outputs" |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|[{"score": 0.9066258072853088, "token": 3007, "token_str": "capital", "sequence": "lynyuu is the capital of the grand duchy of yu."}, {"score": 0.08162177354097366, "token": 2835, "token_str": "seat", "sequence": "lynyuu is the seat of the grand duchy of yu."}, {"score": 0.0012052370002493262, "token": 4075, "token_str": "headquarters", "sequence": "lynyuu is the headquarters of the grand duchy of yu."}, {"score": 0.0006560495239682496, "token": 2171, "token_str": "name", "sequence": "lynyuu is the name of the grand duchy of yu."}, {"score": 0.0005427763098850846, "token": 3200, "token_str"... |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
토큰 분류¶
작업이 “ner” 또는 “token-classification “인 파이프라인으로, 입력과 출력은 다음과 같습니다.
입력¶
inputs: 분류할 토큰이 포함된 문자열입니다.
예:
------------------------------------------------
|"inputs" |
------------------------------------------------
|My name is Izumi and I live in Tokyo, Japan. |
------------------------------------------------
출력¶
outputs: 결과 오브젝트 목록의 JSON 표현이 포함된 문자열로, 각 키에는entity,score,index,word,name,start또는end같은 키가 포함될 수 있습니다. 자세한 내용은 TokenClassificationPipeline 섹션을 참조하십시오.
예:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|"outputs" |
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|[{"entity": "PRON", "score": 0.9994392991065979, "index": 1, "word": "my", "start": 0, "end": 2}, {"entity": "NOUN", "score": 0.9968984127044678, "index": 2, "word": "name", "start": 3, "end": 7}, {"entity": "AUX", "score": 0.9937735199928284, "index": 3, "word": "is", "start": 8, "end": 10}, {"entity": "PROPN", "score": 0.9928083419799805, "index": 4, "word": "i", "start": 11, "end": 12}, {"entity": "PROPN", "score": 0.997334361076355, "index": 5, "word": "##zumi", "start": 12, "end": 16}, {"entity": "CCONJ", "score": 0.999173104763031, "index": 6, "word": "and", "start": 17, "end": 20}, {... |
쿼리 응답(단일 출력)¶
작업이 “question-answering “인 파이프라인으로, 여기서 top_k 는 설정 취소되거나 1로 설정되고, 입력과 출력은 다음과 같습니다.
입력¶
question: 답변할 질문이 포함된 문자열입니다.context: 답변을 포함할 수 있는 문자열입니다.
예:
-----------------------------------------------------------------------------------
|"question" |"context" |
-----------------------------------------------------------------------------------
|What did Doris want to do? |Doris is a cheerful mermaid from the ocean dept... |
-----------------------------------------------------------------------------------
출력¶
score: 0.0~1.0 사이의 부동소수점 신뢰도 점수입니다.start: 컨텍스트에서 답변의 첫 번째 토큰의 정수 인덱스입니다.end: 원래 컨텍스트에서 답변의 마지막 토큰의 정수 인덱스입니다.answer: 찾은 답변이 포함된 문자열입니다.
예:
--------------------------------------------------------------------------------
|"score" |"start" |"end" |"answer" |
--------------------------------------------------------------------------------
|0.61094731092453 |139 |178 |learn more about the world of athletics |
--------------------------------------------------------------------------------
쿼리 응답(다중 출력)¶
작업이 “question-answering “인 파이프라인으로, 여기서 top_k 는 설정되고 1보다 큰 값이며, 입력과 출력은 다음과 같습니다.
입력¶
question: 답변할 질문이 포함된 문자열입니다.context: 답변을 포함할 수 있는 문자열입니다.
예:
-----------------------------------------------------------------------------------
|"question" |"context" |
-----------------------------------------------------------------------------------
|What did Doris want to do? |Doris is a cheerful mermaid from the ocean dept... |
-----------------------------------------------------------------------------------
출력¶
outputs: 결과 오브젝트 목록의 JSON 표현이 포함된 문자열로, 각 키에는score,start,end또는answer같은 키가 포함될 수 있습니다.
예:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|"outputs" |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|[{"score": 0.61094731092453, "start": 139, "end": 178, "answer": "learn more about the world of athletics"}, {"score": 0.17750297486782074, "start": 139, "end": 180, "answer": "learn more about the world of athletics.\""}, {"score": 0.06438097357749939, "start": 138, "end": 178, "answer": "\"learn more about the world of athletics"}] |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
요약¶
작업이 “요약 “ 인 파이프라인으로, 여기서 return_tensors 는 False 또는 설정 취소되며, 입력과 출력은 다음과 같습니다.
입력¶
documents: 요약할 텍스트가 포함된 문자열입니다.
예:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|"documents" |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|Neuro-sama is a chatbot styled after a female VTuber that hosts live streams on the Twitch channel "vedal987". Her speech and personality are generated by an artificial intelligence (AI) system wh... |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
출력¶
summary_text: 생성된 요약이 포함된 문자열 또는num_return_sequences가 1보다 큰 경우 결과 목록의 JSON 표현식이 포함된 문자열이며, 각 문자열은summary_text를 포함한 필드가 포함된 사전입니다.
예:
---------------------------------------------------------------------------------
|"summary_text" |
---------------------------------------------------------------------------------
| Neuro-sama is a chatbot styled after a female VTuber that hosts live streams |
---------------------------------------------------------------------------------
테이블 질문 답변¶
작업이 table-question-answering 인 파이프라인으로, 입력과 출력은 다음과 같습니다.
입력¶
query: 답변할 질문이 포함된 문자열입니다.table: 답변을 포함할 수 있는 테이블을 나타내는{column -> [values]}형식의 JSON 직렬화 사전이 포함된 문자열입니다.
예:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|"query" |"table" |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|Which channel has the most subscribers? |{"Channel": ["A.I.Channel", "Kaguya Luna", "Mirai Akari", "Siro"], "Subscribers": ["3,020,000", "872,000", "694,000", "660,000"], "Videos": ["1,200", "113", "639", "1,300"], "Created At": ["Jun 30 2016", "Dec 4 2017", "Feb 28 2014", "Jun 23 2017"]} |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
출력¶
answer: 가능한 답변이 포함된 문자열입니다.coordinates: 답변이 이 위치한 셀의 좌표를 나타내는 정수 목록입니다.cells: 답변이 위치한 셀의 내용이 포함된 문자열 목록입니다.aggregator: 사용된 집계 장치의 이름이 포함된 문자열입니다.
예:
----------------------------------------------------------------
|"answer" |"coordinates" |"cells" |"aggregator" |
----------------------------------------------------------------
|A.I.Channel |[ |[ |NONE |
| | [ | "A.I.Channel" | |
| | 0, |] | |
| | 0 | | |
| | ] | | |
| |] | | |
----------------------------------------------------------------
텍스트 분류(단일 출력)¶
작업이 “text-clasification “ 또는 “sentiment-analysis”인 파이프라인으로, 여기서 top_k 는 설정되지 않거나 None이며, 입력과 출력은 다음과 같습니다.
입력¶
text: 분류할 문자열입니다.text_pair:text로 분류되는 문자열로, 텍스트 유사도를 계산하는 모델과 함께 사용됩니다. 모델에서 사용하지 않으면 비워둡니다.
예:
----------------------------------
|"text" |"text_pair" |
----------------------------------
|I like you. |I love you, too. |
----------------------------------
출력¶
label: 텍스트의 분류 레이블을 나타내는 문자열입니다.score: 0.0~1.0 사이의 부동소수점 신뢰도 점수입니다.
예:
--------------------------------
|"label" |"score" |
--------------------------------
|LABEL_0 |0.9760091304779053 |
--------------------------------
텍스트 분류(다중 출력)¶
작업이 “text-clasification “ 또는 “sentiment-analysis”인 파이프라인으로, 여기서 top_k 는 숫자로 설정되며, 입력과 출력은 다음과 같습니다.
참고
텍스트 분류 작업은 top_k 가 임의의 숫자로 설정되어 있으면 그 숫자가 1이더라도 다중 출력으로 간주됩니다. 단일 출력 을 얻으려면 None의 top_k 값을 사용합니다.
입력¶
text: 분류할 문자열입니다.text_pair:text로 분류되는 문자열로, 텍스트 유사도를 계산하는 모델과 함께 사용됩니다. 모델에서 사용하지 않으면 비워둡니다.
예:
--------------------------------------------------------------------
|"text" |"text_pair" |
--------------------------------------------------------------------
|I am wondering if I should have udon or rice fo... | |
--------------------------------------------------------------------
출력¶
outputs: 결과 목록의 JSON 표현을 포함하는 문자열로, 각 목록에는label및score등의 필드가 포함되어 있습니다.
예:
--------------------------------------------------------
|"outputs" |
--------------------------------------------------------
|[{"label": "NEGATIVE", "score": 0.9987024068832397}] |
--------------------------------------------------------
텍스트 생성¶
작업이 “text-generation “ 인 파이프라인으로, 여기서 return_tensors 는 False 또는 설정 취소되며, 입력과 출력은 다음과 같습니다.
참고
return_tensors 가 True인 텍스트 생성 파이프라인은 지원되지 않습니다.
입력¶
inputs: 프롬프트가 포함된 문자열입니다.
예:
--------------------------------------------------------------------------------
|"inputs" |
--------------------------------------------------------------------------------
|A descendant of the Lost City of Atlantis, who swam to Earth while saying, " |
--------------------------------------------------------------------------------
출력¶
outputs: 결과 오브젝트 목록의 JSON을 나타내는 문자열로, 각 필드에는generated_text등의 필드가 포함됩니다.
예:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|"outputs" |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|[{"generated_text": "A descendant of the Lost City of Atlantis, who swam to Earth while saying, \"For my life, I don't know if I'm gonna land upon Earth.\"\n\nIn \"The Misfits\", in a flashback, wh... |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
텍스트-텍스트 생성¶
작업이 “text2text-generation “ 인 파이프라인으로, 여기서 return_tensors 는 False 또는 설정 취소되며, 입력과 출력은 다음과 같습니다.
참고
return_tensors 가 True인 텍스트-텍스트 생성 파이프라인은 지원되지 않습니다.
입력¶
inputs: 프롬프트가 포함된 문자열입니다.
예:
--------------------------------------------------------------------------------
|"inputs" |
--------------------------------------------------------------------------------
|A descendant of the Lost City of Atlantis, who swam to Earth while saying, " |
--------------------------------------------------------------------------------
출력¶
generated_text:
num_return_sequences가 1이면 생성된 텍스트를 포함하는 문자열, num_return_sequences가 1보다 크면generated_text를 포함한 필드를 포함하는 결과 사전의 JSON 목록을 문자열로 표현합니다.
예:
----------------------------------------------------------------
|"generated_text" |
----------------------------------------------------------------
|, said that he was a descendant of the Lost City of Atlantis |
----------------------------------------------------------------
번역 생성¶
작업이 “번역 “ 인 파이프라인으로, 여기서 return_tensors 는 False 또는 설정 취소되며, 입력과 출력은 다음과 같습니다.
참고
return_tensors 가 True인 번역 생성 파이프라인은 지원되지 않습니다.
입력¶
inputs: 번역할 텍스트가 포함된 문자열입니다.
예:
------------------------------------------------------------------------------------------------------
|"inputs" |
------------------------------------------------------------------------------------------------------
|Snowflake's Data Cloud is powered by an advanced data platform provided as a self-managed service. |
------------------------------------------------------------------------------------------------------
출력¶
translation_text:num_return_sequences가 1인 경우 생성된 번역을 나타내는 문자열 또는translation_text등 필드가 각각 포함된 결과 사전의 JSON 목록을 나타내는 문자열입니다.
예:
---------------------------------------------------------------------------------------------------------------------------------
|"translation_text" |
---------------------------------------------------------------------------------------------------------------------------------
|Le Cloud de données de Snowflake est alimenté par une plate-forme de données avancée fournie sous forme de service autogérés. |
---------------------------------------------------------------------------------------------------------------------------------
제로샷 분류¶
작업이 zero-shot-classification 인 파이프라인으로, 입력과 출력은 다음과 같습니다.
입력¶
sequences: 분류할 텍스트가 포함된 문자열입니다.candidate_labels: 텍스트에 적용할 레이블이 포함된 문자열 목록입니다.
예:
-----------------------------------------------------------------------------------------
|"sequences" |"candidate_labels" |
-----------------------------------------------------------------------------------------
|I have a problem with Snowflake that needs to be resolved asap!! |[ |
| | "urgent", |
| | "not urgent" |
| |] |
|I have a problem with Snowflake that needs to be resolved asap!! |[ |
| | "English", |
| | "Japanese" |
| |] |
-----------------------------------------------------------------------------------------
출력¶
sequence: 입력 문자열입니다.labels: 적용된 레이블을 나타내는 문자열 목록입니다.scores: 각 레이블에 대한 부동소수점 신뢰도 점수 목록입니다.
예:
--------------------------------------------------------------------------------------------------------------
|"sequence" |"labels" |"scores" |
--------------------------------------------------------------------------------------------------------------
|I have a problem with Snowflake that needs to be resolved asap!! |[ |[ |
| | "urgent", | 0.9952737092971802, |
| | "not urgent" | 0.004726255778223276 |
| |] |] |
|I have a problem with Snowflake that needs to be resolved asap!! |[ |[ |
| | "Japanese", | 0.5790848135948181, |
| | "English" | 0.42091524600982666 |
| |] |] |
--------------------------------------------------------------------------------------------------------------