단어 빈도 분석
축하합니다! 여러분은 이제 PyBooks 팀의 일원이 되었어요. PyBooks는 도서 추천 시스템을 개발 중이며, 추천 품질을 높이기 위해 텍스트에서 패턴과 추세를 찾고자 합니다.
먼저, 주어진 텍스트에서 단어의 빈도를 파악하고 드문 단어를 제거해 보세요.
참고로, 실제 현업 데이터셋은 이 예시보다 훨씬 큰 경우가 많습니다.
이 연습은 강의의 일부입니다
PyTorch로 배우는 텍스트 딥러닝
연습 안내
torchtext에서get_tokenizer를,nltk라이브러리에서FreqDist를 임포트하세요.- 영어용 토크나이저를 초기화하고 주어진
text를 토큰화하세요. tokens의 빈도 분포를 계산하고, 리스트 컴프리헨션으로 희귀 단어를 제거하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Import the necessary functions
from torchtext.data.utils import ____
from nltk.probability import ____
text = "In the city of Dataville, a data analyst named Alex explores hidden insights within vast data. With determination, Alex uncovers patterns, cleanses the data, and unlocks innovation. Join this adventure to unleash the power of data-driven decisions."
# Initialize the tokenizer and tokenize the text
tokenizer = ____("basic_english")
tokens = tokenizer(____)
threshold = 1
# Remove rare words and print common tokens
freq_dist = ____(____)
common_tokens = [token for token in tokens if ____[token] > ____]
print(common_tokens)