※ 이 글은 chatGPT를 기반으로 작성한 글입니다.
① 허깅 페이스(Hugging Face)는 인공 지능 연구 및 개발에 중점을 둔 회사이며, 자연어 처리와 관련된 다양한 오픈 소스 도구와 라이브러리를 제공한다.
② 허깅 페이스는 다양한 언어 모델들을 쉽게 사용할 수 있게 해주는 트랜스포머(Transformers) 라이브러리를 제공한다.
③ 이 라이브러리를 통해 BERT, GPT, T5 등과 같은 고급 언어 모델을 활용하여 텍스트 분석, 번역, 요약 등 NLP 작업을 수행할 수 있다.
④ 허깅 페이스의 트랜스포머 라이브러리 PIP(Package Installer for Python)을 사용하여 설치할 수 있다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install transformers |
⑤ import transformers를 사용해 트랜스포머 라이브러리를 불러와 사용할 수 있다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformers import BertTokenizer, BertForSequenceClassification | |
from transformers import pipeline |
⑥ bert-base-uncased 모델같은 미리 학습된 BERT 모델과 해당 토크나이저를 로드할 수 있다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_name = "bert-base-uncased" | |
model = BertForSequenceClassification.from_pretrained(model_name) | |
tokenizer = BertTokenizer.from_pretrained(model_name) |
⑦ 감정 분석을 위한 파이프라인을 설정할 수 있다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer) |
⑧ "I love using transformers for natural language processing!" 이란 문장에 대해서 모델이 감정을 분석한 결과를 확인할 수 있다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
text = "I love using transformers for natural language processing!" | |
result = nlp(text) | |
print(result) |
⑨ 감정분석한 결과 LABEL_1 에 대해 약 0.64%의 확률로 확신했다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformers import BertTokenizer, BertForSequenceClassification | |
from transformers import pipeline | |
model_name = "bert-base-uncased" | |
model = BertForSequenceClassification.from_pretrained(model_name) | |
tokenizer = BertTokenizer.from_pretrained(model_name) | |
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer) | |
text = "I love using transformers for natural language processing" | |
result = nlp(text) | |
print(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{'label': 'LABEL_1', 'score': 0.6394699215888977}] |
'All about Machine-Learning > NLP' 카테고리의 다른 글
트랜스포머 모델 구현 (0) | 2024.01.12 |
---|---|
어텐션 메커니즘과 트랜스포머 모델 (0) | 2024.01.12 |
어텐션 메커니즘(Attention Mechanism)의 원리 (0) | 2024.01.12 |
Seq2Seq 모델의 이해 (0) | 2024.01.12 |
워드 벡터(Word Vector) -CBOW, Skip-gram (0) | 2024.01.06 |