
192
2
부
빌딩 블록
이제 문서를 벡터로 바꾸는 방법을 알았으니 다음 장에서는 기존 머신러닝 작업에서 해당 벡터
를 사용하는 방법을 살펴보자.
6.3
연습 문제
TF
.
IDF
값을 계산했으니 이제 검색 기능을 구축해보자. 먼저 쿼리를 처리하는 함수가 필요하다.
def process_query(query, pipeline):
data = spark.createDataFrame([(query,)], ['text'])
return pipeline.transform(data).first()['normalized']
다음으로 필터셋을 가져오는 함수가 필요하다.
def get_filter_set(processed_query):
filter_set = set()
# find all the documents that contain any of the terms
return filter_set
다음으로 문서의 점수를 계산하는 함수가 필요하다.
def get_score(index, terms):
return # return a single score
결과를 표시하는 기능도 필요하다.
def display(index, score, terms):
hits = [term for term in terms if term in vocabulary and tfidf[index][inv_