[60일차] ASAC 빅데이터 분석가 4기(DL-9)

2024. 2. 27. 10:58· ASAC 빅데이터 분석가 4기/Deep Learning
목차
  1. ⚙️ Transformers - NLP
  2. 📌 기본 세팅
  3. 📌 텍스트 분류
  4. 📌 텍스트 객체 추출
  5. 📌 텍스트 기반 Q&A
  6. 📌 텍스트 요약
  7. 📌 텍스트 번역
  8. 📌 텍스트 생성

⚙️ Transformers - NLP

📌 기본 세팅

!git clone https://github.com/rickiepark/nlp-with-transformers.git
%cd nlp-with-transformers
from install import *
install_requirements(chapter=1)
text = """Dear Amazon, last week I ordered an Optimus Prime action figure \
from your online store in Germany. Unfortunately, when I opened the package, \
I discovered to my horror that I had been sent an action figure of Megatron \
instead! As a lifelong enemy of the Decepticons, I hope you can understand my \
dilemma. To resolve the issue, I demand an exchange of Megatron for the \
Optimus Prime figure I ordered. Enclosed are copies of my records concerning \
this purchase. I expect to hear from you soon. Sincerely, Bumblebee."""

access_token="허깅페이스 access token"

📌 텍스트 분류

from transformers import pipeline
classifier = pipeline("text-classification", token=access_token)
import pandas as pd
outputs = classifier(text)
pd.DataFrame(outputs)

텍스트 분류 결과


📌 텍스트 객체 추출

ner_tagger = pipeline("ner", aggregation_strategy="simple", token=access_token)
outputs = ner_tagger(text)
print(text)
print("-"*80)
pd.DataFrame(outputs)

텍스트 객체 추출 결과


📌 텍스트 기반 Q&A

reader = pipeline("question-answering", token=access_token)
question = "What does the customer want?"
outputs = reader(question=question, context=text)
pd.DataFrame([outputs])

Q&A 결과

question = "Where did he buy the Megatron?"
outputs = reader(question=question, context=text)
pd.DataFrame([outputs])

Q&A 결과


📌 텍스트 요약

summarizer = pipeline("summarization", token=access_token)
outputs = summarizer(text, max_length=56, clean_up_tokenization_spaces=True)
print(outputs[0]['summary_text'])

텍스트 요약 결과


📌 텍스트 번역

translator = pipeline("translation_en_to_de",
                      model="Helsinki-NLP/opus-mt-en-de", token=access_token)
outputs = translator(text, clean_up_tokenization_spaces=True, min_length=100)
print(outputs[0]['translation_text'])

텍스트 번역 결과 (영 > 독)

translator2 = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", token=access_token)
print(translator2("오늘의 날씨가 참 좋습니다")[0]['translation_text'])

텍스트 번역 결과 (한 > 영)


📌 텍스트 생성

generator = pipeline("text-generation", token=access_token)
response = "Dear Bumblebee, I am sorry to hear that your order was mixed up."
prompt = text + "\n\nCustomer service response:\n" + response
outputs = generator(prompt, max_length=200)
print(outputs[0]['generated_text'])

텍스트 생성 결과

저작자표시 비영리 변경금지 (새창열림)
  1. ⚙️ Transformers - NLP
  2. 📌 기본 세팅
  3. 📌 텍스트 분류
  4. 📌 텍스트 객체 추출
  5. 📌 텍스트 기반 Q&A
  6. 📌 텍스트 요약
  7. 📌 텍스트 번역
  8. 📌 텍스트 생성
'ASAC 빅데이터 분석가 4기/Deep Learning' 카테고리의 다른 글
  • [63일차] ASAC 빅데이터 분석가 4기(DL-10)
  • [56일차] ASAC 빅데이터 분석가 4기(DL-8)
  • [55일차] ASAC 빅데이터 분석가 4기(DL-7)
  • [54일차] ASAC 빅데이터 분석가 4기(DL-6)
zzzini
zzzini
종착지는 어디인지 모르지만
zzzini
나의 표류일지
zzzini
전체
오늘
어제
  • 분류 전체보기 (307)
    • ASAC 빅데이터 분석가 4기 (44)
      • Python기초 (6)
      • SQL (3)
      • Matplotlib & Seaborn (2)
      • Data Handling (6)
      • Web Crawling (3)
      • Machine Learning (9)
      • Deep Learning (10)
      • 데이터 분석 (1)
      • 기타 (2)
      • 수학 (2)
    • 코딩 테스트 준비 (168)
      • 5정한 (132)
      • 카카오 (14)
      • PCCP & PCCE (3)
      • 프로그래머스 (19)
    • 자격증 (35)
      • AWS CLF-C02 (18)
      • AWS SAA-C03 (1)
      • Tableau Desktop Specialist (5)
      • Tableau Certified Data Anal.. (11)
    • 독서 (17)
    • Tech (23)
      • Tableau (10)
      • AI (4)
      • Flask (1)
      • Node.js (2)
      • Cloud Computing (2)
      • Git & GitHub (1)
      • Notion API (1)
      • Linux (2)
    • Projects (2)
    • 알고리즘 공부 (6)
    • 🎵 (11)

블로그 메뉴

  • 글 쓰기
  • 홈
  • 방명록

공지사항

hELLO · Designed By 정상우.v4.2.1
zzzini
[60일차] ASAC 빅데이터 분석가 4기(DL-9)
상단으로

티스토리툴바

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.