토큰 분류

Python으로 배우는 Natural Language Processing (NLP)

Fouad Trad

Machine Learning Engineer

텍스트 vs. 토큰 분류

텍스트 분류

  • 문장 전체 또는 문장 쌍을 분류합니다

이전 영상에서 본 텍스트 분류와 QNLI 작업을 보여주는 이미지.

Python으로 배우는 Natural Language Processing (NLP)

텍스트 vs. 토큰 분류

텍스트 분류

  • 문장 전체 또는 문장 쌍을 분류합니다

이전 영상에서 본 텍스트 분류와 QNLI 작업을 보여주는 이미지.

토큰 분류

  • 문장 내 토큰에 레이블을 지정합니다

문장을 단어별로 나누고 각기 다른 색으로 다른 클래스를 나타내는 이미지.

  • 개체명 인식(NER)
  • 품사(PoS) 태깅
Python으로 배우는 Natural Language Processing (NLP)

개체명 인식(NER)

  • 이름, 위치, 조직, 날짜 등 개체를 식별합니다

문장 "Apple opened a new office in Toronto in March 2023"의 NER 분석 이미지로, Apple은 조직, Toronto는 위치, March 2023은 날짜로 인식됨.

  • 활용처:
    • 정보 검색
    • 질의응답
Python으로 배우는 Natural Language Processing (NLP)

코드로 보는 NER

from transformers import pipeline

ner_pipeline = pipeline(task="ner",
model="dslim/bert-base-NER",
grouped_entities=True)
ner_results = ner_pipeline("Zara Venn established NovaCore Dynamics in London.")
print(ner_results)
[{'entity_group': 'PER', 'score': np.float32(0.99840075), 'word': 'Zara Venn', 'start': 0, 'end': 9}, 
 {'entity_group': 'ORG', 'score': np.float32(0.99875560), 'word': 'NovaCore Dynamics', 'start': 21, 'end': 38}, 
 {'entity_group': 'LOC', 'score': np.float32(0.99960726), 'word': 'London', 'start': 42, 'end': 48}]
Python으로 배우는 Natural Language Processing (NLP)

품사(Part of Speech, PoS) 태깅

  • 각 단어에 문법적 역할(명사, 동사, 형용사)을 지정합니다

문장 "The quick fox jumps over the lazy dog"의 품사 태그를 보여주는 이미지. 여기서 "the"는 한정사, "quick"과 "lazy"는 형용사, "fox"와 "dogs"는 명사, "jumps"는 동사, "over"는 전치사입니다.

  • 활용처:
    • 구문 분석
    • 문법 교정
    • 텍스트 생성
Python으로 배우는 Natural Language Processing (NLP)

코드로 보는 PoS 태깅

pos_pipeline = pipeline(task="token-classification",

model="vblagoje/bert-english-uncased-finetuned-pos",
grouped_entities=True)
pos_results = pos_pipeline("Zara Venn established NovaCore Dynamics in London.") print(pos_results)
[{'entity_group': 'PROPN', 'score': np.float32(0.9982983), 'word': 'zara venn', 'start': 0, 'end': 9},  
 {'entity_group': 'VERB', 'score': np.float32(0.99940944), 'word': 'established', 'start': 10, 'end': 21},  
 {'entity_group': 'PROPN', 'score': np.float32(0.99455726), 'word': 'novacore dynamics', 'start': 22, 'end': 39},  
 {'entity_group': 'ADP', 'score': np.float32(0.99935526), 'word': 'in', 'start': 40, 'end': 42},  
 {'entity_group': 'PROPN', 'score': np.float32(0.99847955), 'word': 'london', 'start': 43, 'end': 49}]
Python으로 배우는 Natural Language Processing (NLP)

Ayo berlatih!

Python으로 배우는 Natural Language Processing (NLP)

Preparing Video For Download...