Weitere ähnliche Inhalte
Mehr von Shunsuke Kozawa (8)
Kürzlich hochgeladen (11)
Elasticsearchを用いたはてなブックマークのトピック生成
- 11. はてなブックマークのインデックス構造(一部)
11
“mapping”: {
“entry”: {
“_id” : { “path”: “id” },
“properties”: {
“id”: { “type”: “integer” },
“url”: { “type”: “string” },
“title”: { “type”: “string” },
“content”: { “type”: “string” },
“created”: { “type”: “date”, “format”: “date_time_no_mills” }
}
}
}
- 13. Significant Terms Aggregation
"aggregations": {
"sample": {
"buckets": [
{ "key": "シャリル", "doc_count": 55,
"score": 2.502, "bg_count": 400 },
{ "key": "エブド", "doc_count": 39,
"score": 2.278, "bg_count": 221 },
{ "key": "スイスフラン", "doc_count": 57,
"score": 1.802, "bg_count": 596 },
{ "key": "ニュース", "doc_count": 1966,
"score": 1.606, "bg_count": 732518 },
{ "key": "ようじ", "doc_count": 48,
"score": 1.511, "bg_count": 504 },
]
} }
{
“aggs”: {
“sample”: {
“significant_terms” : {
“field”: “title”,
“size”: 5
}
}
}
}
Request Response
2015年1月13日 ~
2015年1月20日 13
- 14. Significant Terms Aggregation
"aggregations": {
"sample": {
"buckets": [
{ "key": "シャリル", "doc_count": 55,
"score": 2.502, "bg_count": 400 },
{ "key": "エブド", "doc_count": 39,
"score": 2.278, "bg_count": 221 },
{ "key": "スイスフラン", "doc_count": 57,
"score": 1.802, "bg_count": 596 },
{ "key": "ニュース", "doc_count": 1966,
"score": 1.606, "bg_count": 732518 },
{ "key": "ようじ", "doc_count": 48,
"score": 1.511, "bg_count": 504 },
]
} }
{
“aggs”: {
“sample”: {
“significant_terms” : {
“field”: “title”,
“size”: 5
}
}
}
}
Request Response
2015年1月13日 ~
2015年1月20日
key: キーワード
doc_count: 指定範囲でのキーワードの頻度
score: キーワードのスコア
bg_count: 文書全体でのキーワードの頻度
14
- 16. JLH
全体と指定範囲の出現割合を利用
JLH = 絶対割合変化 × 相対割合変化
絶対割合変化 = 指定範囲での出現割合 - 全体での出現割合
相対割合変化 = 指定範囲での出現割合 / 全体での出現割合
例:1年(全体)で30,000文書、直近1日(指定範囲)で100文書の文書集合利用
「スイスフラン」という単語が全体で100、指定範囲で10回出現した場合
絶対割合変化 = 10/100 - 100/30000 = 29/300
相対割合変化 = 10/100 / 100/30000 = 30
JLH = 29/300 * 30 = 2.9
16
- 18. Significant Terms Aggregation
"aggregations": {
"sample": {
"buckets": [
{ "key": "シャリル", "doc_count": 55,
"score": 2.502, "bg_count": 400 },
{ "key": "エブド", "doc_count": 39,
"score": 2.278, "bg_count": 221 },
{ "key": "スイスフラン", "doc_count": 57,
"score": 1.802, "bg_count": 596 },
{ "key": "ニュース", "doc_count": 1966,
"score": 1.606, "bg_count": 732518 },
{ "key": "ようじ", "doc_count": 48,
"score": 1.511, "bg_count": 504 },
]
} }
{
“aggs”: {
“sample”: {
“significant_terms” : {
“field”: “title”,
“size”: 5
}
}
}
}
Request Response
2015年1月13日 ~
2015年1月20日 18
- 19. {
“query”: {
“filtered”: { “filter”: { “bool”: { “must”: [
{ “range”: { “created”: {
“from”: “2015-01-13T00:00:00+09:00”,
“to”: “2015-01-20T00:00:00+09:00”
} } }
] } } }
},
“aggs”: { “sample”: {
“significant_terms” : { “field”: “title”, “size”: 5, “jlh”: {} },
“aggs”: { “sample2”: {
“significant_terms”: { “field”: “title”, “size”: 5, “jlh”: {} }
} }
} }
}
Request
2015年1月13日 ~ 2015年1月20日
significant_termsを2層で利用
19
- 20. "aggregations": { "sample": { "buckets": [
{
"key": "シャルリ", "score": 2.502,
"sample2": { "buckets": [ { "key": "シャルリ", "score": 129926.04 },
{ "key": "エブド", "score": 99737.62 }, { "key": "赦す", "score": 5522.22 },
{ "key": "ムハンマド", "score": 4729.32 }, { "key": "風刺", "score": 4172.57 }
] }
}, …, {
"key": "スイスフラン", "score": 1.802,
"sample2": { "buckets": [ { "key": "スイスフラン", "score": 89385.22 },
{ "key": "急騰", "score": 1992.90 }, { "key": "上限", "score": 1391.56 },
{ "key": "損失", "score": 1118.69 }, { "key": "暴騰", "score": 766.13 }
] }
}, …, {
"key": "ようじ", "score": 1.511,
"sample2": { "buckets": [ { "key": "ようじ", "score": 80424.75 },
{ "key": "つま", "score": 26207.62 }, { "key": "混入", "score": 4192.10 },
{ "key": "スナック菓子", "score": 2759.62 }, { "key": "手配", "score": 2128.30 }
] }
}
] } }
Response
20
- 21. "aggregations": { "sample": { "buckets": [
{
"key": "シャルリ", "score": 2.502,
"sample2": { "buckets": [ { "key": "シャルリ", "score": 129926.04 },
{ "key": "エブド", "score": 99737.62 }, { "key": "赦す", "score": 5522.22 },
{ "key": "ムハンマド", "score": 4729.32 }, { "key": "風刺", "score": 4172.57 }
] }
}, …, {
"key": "スイスフラン", "score": 1.802,
"sample2": { "buckets": [ { "key": "スイスフラン", "score": 89385.22 },
{ "key": "急騰", "score": 1992.90 }, { "key": "上限", "score": 1391.56 },
{ "key": "損失", "score": 1118.69 }, { "key": "暴騰", "score": 766.13 }
] }
}, …, {
"key": "ようじ", "score": 1.511,
"sample2": { "buckets": [ { "key": "ようじ", "score": 80424.75 },
{ "key": "つま", "score": 26207.62 }, { "key": "混入", "score": 4192.10 },
{ "key": "スナック菓子", "score": 2759.62 }, { "key": "手配", "score": 2128.30 }
] }
}
] } }
Response
トピックキーワード
21
- 25. トピックキーワード誤生成への対策
● 記事タイトルによくでてくるキーワードは除く
● 範囲を指定せずにSignificant Terms Aggragation
25
"aggregations": { "stop_words": {
"buckets": [
{ "key": "2", "score": 0.388, ... },
{ "key": "ニュース", "score": 0.326, … },
{ "key": "1", "score": 0.323, … },
{ "key": "3", "score": 0.240, ... },
{ "key": "com", "score": 0.234, … },
{ "key": "アンテナ", "score": 0.222, … },
{ "key": "twitter", "score": 0.219, ... },
{ "key": "動画", "score": 0.218, … },
{ "key": "まとめ", "score": 0.202, … },
{ "key": "online", "score": 0.190, ... }
]
} }
“aggs”: {
“stop_words”: {
“significant_terms” : {
“field”: “title”,
“size”: 10
}
}
}
Request Response
期間指定なし
- 28. 記事スコア
「シャルリ」「エブド」を含む記事の場合
記事スコア = 0.94
( 129926+99737 / 129926+99737+5522+4729+4172 )
28
"buckets": [
{ "key": "シャルリ", "score": 129926.04 }, { "key": "エブド", "score": 99737.62 },
{ "key": "赦す", "score": 5522.22 }, { "key": "ムハンマド", "score": 4729.32 },
{ "key": "風刺", "score": 4172.57 }
]
記事スコア =
記事に含まれるトピックキーワードのスコアの和
トピックキーワードのスコアの和
トピックにどの程度関連する記事か
- 30. 30
“function_score”: {
“query”: { “bool”: {
“should”: [ … ], “minimum_should_match”: 1,
} },
“functions”: [ { “script_score”: {
“params”: {
“field”: “title”,
“words”: [ "シャルリ", "エブド", "赦す", "ムハンマド", "風刺" ],
“scores”: [ 129926.04, 99737.62, 5522.23, 4729.32, 4172.57 ]
},
“lang”: “groovy”,
“script”: “def score=0;for(i in 0..4) { if (_index[field][words[i]].tf() > 0) { score +=
scores[i]}; scores;”
} } ],
“min_score”: 195270
}
- 31. 31
“function_score”: {
“query”: { “bool”: {
“should”: [ … ], “minimum_should_match”: 1,
} },
“functions”: [ { “script_score”: {
“params”: {
“field”: “title”,
“words”: [ "シャルリ", "エブド", "赦す", "ムハンマド", "風刺" ],
“scores”: [ 129926.04, 99737.62, 5522.23, 4729.32, 4172.57 ]
},
“lang”: “groovy”,
“script”: “def score=0;for(i in 0..4) { if (_index[field][words[i]].tf() > 0) { score +=
scores[i]}; scores;”
} } ],
“min_score”: 195270
}
シャルリ OR エブド OR 赦す OR ムハンマド OR 風刺
トピックキーワードのスコアの和を計算
記事スコアが0.8(195270)以上