Chapter 1 giới thiệu nền tảng của Information Retrieval (IR) và mối quan hệ giữa IR với Search Engine.
Các nội dung chính:
Information Retrieval liên quan đến:
Mục tiêu là tìm được thông tin phù hợp từ một kho thông tin dựa trên query của người dùng.
flowchart TD
U[User] -->|Query| IRS[Information Retrieval System]
IRS -->|Search / Retrieval| RI[Relevant Information]
Một nhiệm vụ quan trọng của Information Retrieval là so sánh một “piece of information” hoặc query với thông tin được lưu trong một kho dữ liệu để tìm ra câu trả lời phù hợp.
Search Engine là ứng dụng thực tế của các kỹ thuật Information Retrieval trên các tập hợp văn bản có quy mô lớn.
Các loại được đề cập:
| Information Retrieval (IR) | Search Engine |
|---|---|
| Lĩnh vực/kỹ thuật xử lý tìm kiếm thông tin | Ứng dụng các kỹ thuật IR |
| Tập trung vào organization, storage, searching, retrieval | Cung cấp hệ thống tìm kiếm thực tế |
| Có thể áp dụng trên nhiều loại dữ liệu | Thường phục vụ tập dữ liệu lớn |
| Nền tảng lý thuyết/kỹ thuật | Hệ thống ứng dụng |
Search Engineer thường có nền tảng Computer Science, đặc biệt liên quan đến Systems và Database.
Các nhiệm vụ chính:
Có thể hình dung lifecycle thực hành:
flowchart LR
A[Design] --> B[Implement]
B --> C[Index]
C --> D[Search]
D --> E[Evaluate]
E --> F[Tune / Optimize]
F --> G[Maintain]
flowchart TD
Q[Query]
A[Identify web pages containing query terms]
B[Compute score for each page]
C[Eliminate duplicate / redundant pages]
D[Generate summaries]
R[Search Results]
Q --> A
A --> B
B --> C
C --> D
D --> R
Ví dụ:
1
information retrieval search engine
Step 2 – Identify Pages: Hệ thống xác định các web page có chứa các term liên quan đến query.
Step 3 – Compute Score: Mỗi page được tính một score để xác định mức độ phù hợp.
1
relevance(document, query) -> score
Step 4 – Remove Duplicates: Các kết quả trùng hoặc dư thừa được loại bỏ.
Step 5 – Generate Summary: Hệ thống tạo summary cho các kết quả còn lại.
Ví dụ Python tối giản:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
documents = {
1: "Information retrieval is about searching information",
2: "Search engines use information retrieval techniques",
3: "Database systems store structured information",
4: "Web search engines process many queries"
}
query = "information retrieval"
terms = query.lower().split()
results = []
for doc_id, text in documents.items():
text_lower = text.lower()
score = sum(
1 for term in terms
if term in text_lower
)
if score > 0:
results.append((doc_id, score, text))
results.sort(key=lambda x: x[1], reverse=True)
for doc_id, score, text in results:
print(f"{score}: {text}")
Pipeline:
flowchart TD
Q[Query] --> T[Tokenize]
T --> M[Match terms]
M --> S[Calculate simple score]
S --> O[Sort]
O --> R[Return results]
Desktop Search Engine cung cấp:
Hệ thống cần awareness về:
Enterprise Search cung cấp:
Một use case được đề cập là hỗ trợ yêu cầu retention của:
Mục tiêu là phân phối hoặc lọc tài liệu dựa trên nhu cầu của người dùng.
Nhóm các document có nội dung tương tự.
1
2
3
4
5
6
7
Documents
|
+---- Politics
|
+---- Business
|
+---- Lifestyle
Gán document vào category đã xác định.
1
Article > Classification System >Business
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
text = "Information retrieval is an important area of computer science. Search engines apply information retrieval techniques. A search engine processes user queries. The system retrieves relevant documents."
sentences = [
s.strip()
for s in text.split(".")
if s.strip()
]
keywords = ["information", "search engine", "retrieves"]
scores = []
for sentence in sentences:
score = sum(
keyword in sentence.lower()
for keyword in keywords
)
scores.append((score, sentence))
scores.sort(reverse=True)
for score, sentence in scores[:2]:
print(sentence)
Đây là mô hình minh họa đơn giản cho ý tưởng chọn các sentence quan trọng.
Information Extraction nhằm:
Ví dụ:
1
"Google was founded by Larry Page and Sergey Brin."
Có thể biểu diễn:
1
2
3
4
5
6
7
8
9
Organization:
Google
Person:
Larry Page
Sergey Brin
Relationship:
founded_by
Pipeline:
1
Unstructured Text > Entity Detection > Relation Extraction > Structured Data
Topic Detection and Tracking nhằm:
1
2
3
4
5
6
7
8
9
News 1 ─┐
News 2 ─┼──> Event A
News 3 ─┤
News 4 ─┘
v
Track Event
v
News 5
News 6
Expert Search System nhằm xác định các thành viên trong một tổ chức có chuyên môn về một lĩnh vực cụ thể.
Question Answering System tích hợp thông tin từ nhiều nguồn để cung cấp câu trả lời ngắn gọn cho một câu hỏi cụ thể.
Chapter cũng liệt kê Multimedia Information Retrieval Systems.
Có thể hình dung:
| Term | Meaning | Example | Practice |
|---|---|---|---|
| Information Retrieval | Tìm kiếm và truy xuất thông tin | Search documents | Keyword search |
| Search Engine | Hệ thống ứng dụng kỹ thuật IR | Web search | Build mini search engine |
| Query | Truy vấn của người dùng | Query → Results | Query processing |
| Retrieval | Quá trình truy xuất thông tin | Retrieve relevant documents | Search pipeline |
| Relevance | Mức độ phù hợp giữa query và document | Relevant documents | Relevance scoring |
| Ranking | Sắp xếp kết quả theo score | Score documents | TF-IDF |
| Web Search | Tìm kiếm thông tin trên web | Query → Results | Search pipeline |
| Desktop Search | Tìm kiếm dữ liệu trên máy tính | Search local files | File index |
| Enterprise Search | Tìm kiếm tài liệu trong doanh nghiệp | Search company documents | Document repository |
| Clustering | Gom nhóm dữ liệu tương tự | Politics / Business / Lifestyle | K-Means |
| Categorization | Phân loại dữ liệu vào các nhóm | Assign article category | Text classification |
| Summarization | Tóm tắt nội dung | Long article → summary | Extractive summary |
| Information Extraction | Trích xuất thông tin có cấu trúc | Entity extraction | NER |
| Topic Detection | Phát hiện topic/event | Detect emerging topics | Topic classifier |
| Topic Tracking | Theo dõi topic/event | Follow news event | Topic classifier |
| Expert Search | Tìm chuyên gia phù hợp | Find domain expert | Profile ranking |
| Question Answering | Trả lời câu hỏi dựa trên thông tin truy xuất | Answer a question | Retrieval + answer |
| Multimedia Retrieval | Tìm kiếm dữ liệu multimedia | Search images/videos | Embedding-based search |
| Search Engineer | Kỹ sư phát triển/vận hành search system | Build search infrastructure | Indexing & ranking |
Mục tiêu: xây dựng search engine nhỏ cho tập document.
1
2
3
4
5
documents/
├── doc1.txt
├── doc2.txt
├── doc3.txt
└── ...
Ví dụ:
1
2
Information retrieval is the process of finding relevant information.
Search engines use information retrieval techniques.
1
2
Machine learning is widely used in modern artificial intelligence.
Search engines can use machine learning for ranking.
1
Information retrieval systems search documents and rank relevant results.
1
Database systems store and retrieve structured information.
1
2
3
4
5
6
documents/
v
doc1.txt
doc2.txt
doc3.txt
doc4.txt
Ví dụ:
“Information Retrieval is important” [“information”, “retrieval”, “is”, “important”]
Có thể thực hiện:
1
2
3
4
- Lowercase
- Tokenization
- Remove punctuation
- Stop-word removal
Ví dụ:
1
2
3
4
information > [doc1, doc3, doc4]
retrieval > [doc1, doc3]
search > [doc1, doc2, doc3]
machine > [doc2]
flowchart LR
T1[information] --> D1[doc1]
T1 --> D3[doc3]
T2[retrieval] --> D1
T2 --> D3
T3[search] --> D1
T3 --> D2[doc2]
T3 --> D3
Sinh viên cần thực hiện:
.txt files.Xây dựng chức năng tìm kiếm cơ bản dựa trên keyword matching.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import re
DOCUMENT_DIR = "documents"
def tokenize(text):
text = text.lower()
return re.findall(r"\b[a-z]+\b", text)
def load_documents():
documents = {}
for filename in os.listdir(DOCUMENT_DIR):
if filename.endswith(".txt"):
path = os.path.join(DOCUMENT_DIR, filename)
with open(path, "r", encoding="utf-8") as file:
documents[filename] = file.read()
return documents
def build_index(documents):
index = {}
for doc_id, text in documents.items():
terms = tokenize(text)
for term in terms:
if term not in index:
index[term] = set()
index[term].add(doc_id)
return index
def search(query, index):
terms = tokenize(query)
results = set()
for term in terms:
if term in index:
results.update(index[term])
return results
documents = load_documents()
index = build_index(documents)
query = input("Enter query: ")
results = search(query, index)
print("\nResults:")
for doc in results:
print("-", doc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from collections import Counter
def score_document(query, document):
query_terms = tokenize(query)
document_terms = tokenize(document)
frequencies = Counter(document_terms)
score = 0
for term in query_terms:
score += frequencies.get(term, 0)
return score
def ranked_search(query, documents, index):
candidates = search(query, index)
results = []
for doc_id in candidates:
score = score_document(
query,
documents[doc_id]
)
results.append({
"document": doc_id,
"score": score
})
results.sort(
key=lambda x: x["score"],
reverse=True
)
return results