파트 2: 데이터셋 탐색
이제 데이터셋의 몇 가지 속성을 살펴보겠습니다. 특히 모든 문장의 평균 길이(단어 수)와 영어 데이터셋의 어휘 크기를 구해 볼 거예요.
이 연습 문제에서는 영어 문장 리스트가 담긴 영어 데이터셋 en_text가 제공됩니다. 또한 <list>.append()와는 다른 변형인 Python 리스트 관련 함수 <list>.extend()를 사용합니다. 예시로 차이를 이해해 볼게요. a=[1,2,3], b=[4,5]라고 할 때, a.append(b)의 결과는 [1,2,3,[4,5]]가 되지만, a.extend(b)의 결과는 [1,2,3,4,5]가 됩니다.
이 연습은 강의의 일부입니다
Keras로 배우는 Machine Translation
연습 안내
en_text를 순회하면서split()함수와len()함수를 사용해 각 문장의 길이를 계산하세요.numpy를 사용해 문장 길이의 평균을 계산하세요.- for 루프 본문에서 문장을 토크나이즈한 뒤 발견한 모든 단어를 리스트
all_words에 추가해 채우세요. - 리스트
all_words를set객체로 변환하고, 그 길이(크기)를 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Compute length of sentences
sent_lengths = [len(____.____(____)) for en_sent in ____]
# Compute the mean of sentences lengths
mean_length = np.____(____)
print('(English) Mean sentence length: ', mean_length)
all_words = []
for sent in en_text:
# Populate all_words with all the words in sentences
all_words.____(____.____(____))
# Compute the length of the set containing all_words
vocab_size = len(____(____))
print("(English) Vocabulary size: ", vocab_size)