布尔模型和向量空间模型的问题解决
布尔模型:
它是一种基于集合论和布尔代数的简单检索模型。查询被设计为具有精确语义的布尔表达式。检索策略基于二元决策准则。布尔模型认为索引词在文档中存在或不存在。
问题解决:
考虑 5 个文档,其中包含 6 个术语的词汇表
- 文档 1 = 'term1 term3'
- 文档 2 = '术语 2 术语 4 术语 6'
- 文档 3 = 'term1 term2 term3 term4 term5'
- 文档 4 = 'term1 term3 term6'
- 文档 5 = 'term3 term4'
我们在布尔模型中的文档
term 1 | term 2 | term 3 | term 4 | term 5 | term 6 | |
document 1 | 1 | 0 | 1 | 0 | 0 | 0 |
document 2 | 0 | 1 | 0 | 1 | 0 | 1 |
document 3 | 1 | 1 | 1 | 1 | 1 | 0 |
document 4 | 1 | 0 | 1 | 0 | 0 | 1 |
document 5 | 0 | 0 | 1 | 1 | 0 | 0 |
考虑查询
查找包含 term1和term3而不是term2 的文档
term1 ∧ term3 ∧ ¬ term2
term1 | ¬term 2 | term 3 | term 4 | term 5 | term 6 | |
document 1 | 1 | 1 | 1 | 0 | 0 | 0 |
document 2 | 0 | 0 | 0 | 1 | 0 | 1 |
document 3 | 1 | 0 | 1 | 1 | 1 | 0 |
document 4 | 1 | 1 | 1 | 0 | 0 | 1 |
document 5 | 0 | 1 | 1 | 1 | 0 | 0 |
- 文档 1 : 1 ∧ 1∧ 1 = 1
- 文档 2:0 ∧ 0 ∧ 0 = 0
- 文档 3:1 ∧ 1 ∧ 0 = 0
- 文件 4:1 ∧ 1 ∧ 1 = 1
- 文档 5:0 ∧ 1 ∧ 1 = 0
基于上述计算document1和document4与给定查询相关
矢量模型:
执行操作的方法和计算所需的公式在第 1 部分的先前文档中提供。请考虑以下文档集合。
- document1 = '一二'
- document2 = '三二四'
- document3 ='一二三'
- document4 ='一二'
使用的公式
有些词条在文档中出现三次、两次,有时只出现一次。文档总数 N=4。因此,术语的 IDF 值为:
one --> log2(4/3) = 0.4147
two --> log2(4/4) = 0
three --> log2(4/2) = 1
four -->log2(4/1) = 2
布尔模型中的表示
one | two | three | four | |
document1 | 1 | 1 | 0 | 0 |
document2 | 0 | 1 | 1 | 1 |
document3 | 1 | 1 | 1 | 0 |
document4 | 1 | 1 | 0 | 0 |
词频计算
one --> 3/4 = 0.75
two --> 4/4 = 1
three --> 2/4 = 0.5
four --> 1/4 = 0.25
权重计算 (tf * idf)
weight(one) --> 0.75 * 0.4147 = 0.3110
weight(two) --> 1 * 0 = 0
weight(three) --> 0.5 * 1 = 0.5
weight(four) --> 0.25 * 2 = 0.5
用权重表示向量模型
one | two | three | four | |
document1 | 0.3110 | 0 | 0 | 0 |
document2 | 0 | 0 | 0.5 | 0.5 |
document3 | 0.3110 | 0 | 0.5 | 0 |
document4 | 0.3110 | 0 | 0 | 0 |
QUERY: 包含“一三三”的文件
计算查询词的权重(词频)
- 重量(一)–> 1/3 = 0.333
- 重量(三)-> 2/3 = 0.667
向量表示
- 文档
- 询问
相似度计算:
文档的排名,(对于为两个不同的项目分配相同排名的情况,我们按照统计中的方法进行排名)
document1 | 2nd |
document2 | 4th |
document3 | 1st |
document4 | 2nd |
由于文档 3之间的相似度大于其他文档之间的相似度,因此第 3 个文档与查询更相关。