Author
others
View
1
Download
0
Embed Size (px)
Introduction to Information Retrieval
Introduction to
Information Retrieval
Python dictionary 대신 DB로 구현
Evaluation 포맷 출력 및 이를 이용한 성능 측정
Jo Ik Chan
Introduction to Information Retrieval
순서
Stemming을 하고, 정렬을 한다.
tf를 추출한다.
Posting list를 생성한다.
생성된 텍스트 파일들로
Posting list DB 생성
Df DB 생성
Tf DB 생성
DB를 이용하여 score 계산 후 txt 파일로 추출
생성된 score 파일을 이용하여 Evaluation 포맷 출력 및 이를 이용한 성능 측정
Ch. 1
Introduction to Information Retrieval
AP88.TXT를 사용한 복습
Introduction to Information Retrieval
stemmer를 이용한 AP88.txt stemming
잘 만들어 졌나 확인해 봅시다.
유의 할 점은 파일이 너무
크기 때문에 그냥 열어보면
메모리 문제로 컴퓨터가 뻗을
수도 있습니다.
Introduction to Information Retrieval
tf와 posting list 만들기
Introduction to Information Retrieval
딕셔너리를 DB로 바꾸기
Introduction to Information Retrieval
딕셔너리를 DB로 바꿔 보기
anydbm Project에서 요구하는 DB사용을 만족하기 위해서 사용하는 모듈.
여기서 의미하는 DB는 sql문을 사용하여 테이블을 생성하고 데이터를 취득하고 하는 DB가 아닌 Disk Based Dictionaries, 즉 파이썬의 기본 자료형인 딕셔너리처럼 키와 값을 사용해 데이터를 저장하고 불러올 수 있는 방식
주의할 점은 키와 값으로는 항상 문자열만을 사용
anydbm 사용하기
Sec. 2.1
>>> import anydbm
>>> db = anydbm.open(‘testdb’, ‘c’)
Option flag: ‘r’ : Read Only ‘w’ : Read, Write
‘c’ : DB파일이 존재 하지 않으면 새로 생성
‘n’ : 항상 새로운 DB파일 생성
Introduction to Information Retrieval
딕셔너리를 DB로 바꿔 보기
anydbm DBM File Operations
Sec. 2.1
Introduction to Information Retrieval
딕셔너리를 DB로 바꿔 보기
anydbm 예제
Sec. 2.1
>>> import anydbm
>>> file=anydbm.open(‘movie’, ‘c’)
>>> file[‘Batman’]=‘Pow!’
>>> file.keys()
[‘Batman’]
>>> file[‘Batman’]
‘Pow!’
>>> who = [‘Robin’, ‘Cat-woman’, ‘Joker’]
>>> what = [‘Bang!’, ‘Splat!’, ‘Wham!’]
>>> for i in range(len(who)):
… file[who[i]]=what[i]
…
>>> file.keys()
[‘Joker’, ‘Robin’, ‘Cat-woman’, ‘Batman’]
>>> len(file), file.has_key(‘Robin’), file[‘Joker’]
(4, 1, ‘Wham!’)
>>> file.close()
Introduction to Information Retrieval
딕셔너리를 DB로 바꿔 보기
지난번 과제에서 posting_list_dic, df_dic, tf_dic 을 만들어서 score를 구해 보았습니다.
Sec. 2.1
Introduction to Information Retrieval
딕셔너리를 DB로 바꿔 보기
이번에는 posting_list_dic, df_dic, tf_dic 을 db로 바꾸는 것에 대해서 배워 보겠습니다.
Sec. 2.1
이것만 import하면 됩니다.
make_db.py로
저장
실행되고 있는지 확인
하고 싶으면
주석으로 되있는
print문을 주석해제하고
찍어 보시면 되지만
그만큼 느려집니다.
*db생성에 5분정도 소요
Introduction to Information Retrieval
딕셔너리를 DB로 바꿔 보기
db파일은 바이너리로 저장되기 때문에 그냥 파일을 텍스트에디터로 열었을 경우 깨져서 보이게 됩니다.
Sec. 2.1
Introduction to Information Retrieval
딕셔너리를 DB로 바꿔 보기
tf_dic도 tf_db로 변환 하시기 바랍니다. 코드는 공개하지 않을 것입니다. 과제로 한 tf_dic 만드는 코드와 posting_list_db, df_db를 만드는 코드를 적절히 사용하면 충분히 하실 수 있습니다.
위와 같은 형식으로 생성하시면 됩니다.
Sec. 2.1
Introduction to Information Retrieval
SCORE파일 생성하기
Introduction to Information Retrieval
score파일 생성하기
과제에서 주어진 질의와 문서 개수에 대해서 score를 계산하는 방법을 배웠습니다.
Sec. 2.1
Introduction to Information Retrieval
score파일 생성하기
이번시간에는 topics.202-250라는 정해진 질문을 받아 들여서 계산하고 결과를 파일에 저장하는 것을 해보겠습니다.
Sec. 2.1
Introduction to Information Retrieval
score파일 생성하기
Sec. 2.1
Introduction to Information Retrieval
score파일 생성하기
Sec. 2.1
Introduction to Information Retrieval
score파일 생성하기
Sec. 2.1
이부분은 자신의 이름을 적어주세요.
ex) Jo_Ik_Chan (뛰어쓰기 하지마세요)
Introduction to Information Retrieval
score파일 생성하기
Sec. 2.1
수행되는 모습입니다.
Introduction to Information Retrieval
score파일 생성하기
결과 파일을 열어보면 이와 같이 들어가 있어야 합니다.
Sec. 2.1
“질문 번호” “Q질문번호-1” “문서이름” “랭킹” “결과값” “본인이름”
Introduction to Information Retrieval
성능 측정
Introduction to Information Retrieval
성능 측정
지금까지 해왔다면 결과물들이 아래와 같이 있어야 합니다.
Sec. 2.2.1
Introduction to Information Retrieval
성능 측정
성능 측정을 위해서는 perl이 깔려 있어야 합니다.
http://www.perl.org/get.html#win32
이 곳으로 들어가서 빨간색 박스 안의 것을 받고 설치합니다.
Sec. 2.2.1
http://www.perl.org/get.html
Introduction to Information Retrieval
성능 측정
설치 후 성능 측정을 위한 trec_eval.pl이 있는 디렉토리로 이동 후 cmd창을 열어서
아래와 같이 입력했을 때 이와 같이 나오면 됩니다.
동일 디렉토리에 qrels로 시작하는 파일과, score를 구한 값들로 만든 AP88_result.txt를 넣은 후 아래와 같이 입력합니다.
AP88_eval.txt파일을 열면 이와 같이 나타납니다.
Sec. 2.2.1
Introduction to Information Retrieval
AP88_EVAL.TXT 를 만들어서 일요일 밤 12시까지 보내시기 바랍니다.
메일 주소 메일 제목 [IR]학번_이름_AP88_EVAL 파일 제목 학번_이름_EVAL.TXT