ご利用にはKandaSearchへの
ユーザー登録(無料)が必要です
最新バージョン: 1.3.1
開発者: RONDHUIT
ダウンロード数: 36
最終更新日: 2022-07-01
Copyright: RONDHUIT Co.,LTD
最新バージョン: 1.3.1
開発者: RONDHUIT
ダウンロード数: 36
最終更新日: 2022-07-01
Copyright: RONDHUIT Co.,LTD
Apache Solr ハンズオンセミナー「第5回 自然言語処理ツールを導入して検索性能を向上させる」のスライドです。
第5回 自然言語処理ツールを導入して検索性能を向上させる
Apache Solr ハンズオンセミナー
株式会社ロンウイット
関口宏司 @kojisays
2022年6月3日 | 初版 |
---|---|
2022年6月16日 | Transliteration の演習を追加 |
2022年6月18日 | Apache OpenNLP の固有表現抽出に関する記述の訂正と演習を追加 |
2022年6月29日 | 施設名辞書に関する記述を追記。一部誤字を修正 |
2022年7月1日 | 固有表現抽出モデルファイル名の誤りを修正 |
これから Apache Solr のいろいろな機能を使っていきます。本セミナーでは Apache Solr 環境を簡単に準備できる KandaSearch を通じて Apache Solr を使っていきます。
そのためには、 https://kandasearch.com/ にログイン後、プロジェクトを作成します。
(お試しになりたい方のみお試しください。このステップを飛ばしても以降の[演習]には差し支えございません)
作成したプロジェクト内に検索エンジンインスタンス、つまり Apache Solr を作成してみましょう。
1,1,2,3,5,8....
ic | 1 | 2 | 3 | 4 | 5 | 6 |
---|---|---|---|---|---|---|
x(i) | 1 | 1 | 2 | 3 | 5 | 8 |
モデル
x(i) = x(i - 1) + x(i - 2) (i > 2)
13,21,?
↓
モデル
x(i) = x(i - 1) + x(i - 2) (i > 2)
↓
34
extensions / data / livedoor / data / dokujo-tsushin / dokujo-tsushin-4778030.txt
「/ dokujo-tsushin /」 ← カテゴリー ← 教師ラベル
以下は特徴ベクトル
"id": "dokujo-tsushin-4778030.txt", ←ID string
"url": "http://news.livedoor.com/article/detail/4778030/", ←URL string
"category": "dokujo-tsushin",
"date": "2010-05-22T14:30:00Z", ←日付 date
"title": "友人代表のスピーチ、独女はどうこなしている?", ←title text_ja / text_2g
"body": [ ←本文 text_ja / text_2g
" もうすぐジューン・ブライドと呼ばれる6月。独女の中には自分の式はまだなのに呼ばれてばかり……という「お祝い貧乏」状態の人も多いのではないだろうか? さらに出席回数を重ねていくと、こんなお願いごとをされることも少なくない。",
"",
..........
" 主役はあくまで新郎新婦ながらも、いざとなると緊張し、内容もあれこれ考えて、こっそりリハーサル……そんな人知れず頑張るスピーチ担当独女たちにも幸あれ(高山惠)"
]
私はoXXXXを送った。⇒ order, offer
私はoXXXXを食べた。⇒ orange, onion
スコア=クエリと文書の関連度
e.g. score( q, d ) = cos( q, d )
値は単語の重要度(ここでは個数)
tf*idf などが使われることが多い。
positive | negative | |
---|---|---|
true | tp | tn |
false | fp | fn |
tn(true negative) fp(false potitive) tp(true psitive) fn(false negative)
result target
tn(true negative) fp(false potitive) tp(true psitive) fn(false negative)
result target
精度(適合率 Precision)=|tp| / (|tp| + |fp|) 再現率(recall)=|tp| / (|tp| + |fn|)
2022年6月1日 朝日新聞デジタル「『線状降水帯』予測情報、きょうから開始 精度向上へ集中観測も」 ・・・同庁が過去3年の事例で検証したところ、予測した地方で発生を的中できるのは4分の1程度。3回に2回は予測できず発生する。・・・
Q1. 前述のようなベン図で表現するとどうなるでしょうか。描いてみましょう。
Q2. 精度(Precision)と再現率(Recall)はそれぞれいくつになるでしょうか。(A2. 精度 P = 1/4 再現率 R = 1/3)
(1) 再現率を高める(検索漏れがないようにする)
(2a) 漸次的精度改善
(2b) ランキングチューニング
省略語
WWW, World Wide Web
WHO, World Health Organization
CEO, Chief Executive Officer
CTO, Chief Technology Officer
:
q=WHO → SynonymGraphFilter → expand query → 「I joined World Health Organization in 1995.」
外来語
internet, インターネット
interface, インターフェイス, インタフェース
computer, コンピューター
server, サーバー
:
q=サーバー → SynonymGraphFilter → expand query → 「I sold the server to buy foods.」
1.クロール
↓
2.カタカナ語とアルファベット語が近接するペアを抽出
↓
アルゴリズム, algorithm
↓
3."アルゴリズム"
↓
4.Transliteration
↓
"algorism"
↓
5.algorithm 編集距離を計算
↓
6.編集距離が閾値以内であれば最初に拾ったペアが互いに同じものであるとして類義語辞書に出力。
synonyms.txt
アルゴリズム, algoritm
KandaSearch のライブラリーにある Transliterator(翻字プログラム)をプロジェクトに追加し、ダウンロードして ZIP を解凍し、次のように実行してカタカナ語から英単語、英単語からカタカナ語を推定させてみましょう。
java -jar transliterator.jar アルゴリズム
algorism
# "-r" オプションで英単語⇒カタカナ語の推定
java -jar transliterator.jar -r algorithm
アルゴリズム
# 文字化けしてしまう場合は "-Dfile.encoding=UTF-8" を使います
java -Dfile.encoding=UTF-8 -jar transliterator.jar -r restaurant
レストオーラント
(1) 再現率を高める(検索漏れがないようにする)
(2a) 漸次的精度改善
Solrへのリクエスト:
GET http://solr/foo
?q=watch
&facet=on
&facet.field=gender
&facet.query=price:[1 TO 100]
&facet.query=price:[101 TO 200]
:
Solrへのリクエスト:
GET http://solr/foo
?q=watch
&facet=on
&facet.field=gender
&facet.query=price:[1 TO 100]
&facet.query=price:[101 TO 200]
:
&fq=gender:mens
↓
filter by Gender
x Men's
Solrへのリクエスト:
GET http://solr/foo
?q=watch
&facet=on
&facet.field=gender
&facet.query=price:[1 TO 100]
&facet.query=price:[101 TO 200]
:
&fq=gender:mens
&fq=price:[101 TO 200]
↓
filter by Gender
x Men's
↓
filter by Price
x $101-$200
id | product | price | gender |
---|---|---|---|
1 | CURREN New Men’s Date Stainless Steel Military Sport Quartz Wrist Watch | 52.00 | mens |
2 | Suiksilver The Gamer Watch | 132.99 | mens |
OR
[
{ “id”: 1,
“product”: “CURREN New Men’s Date Stainless Steel Military Sport Quartz Wrist Watch”,
“price”: 52.00,
“gender”: “mens” },
{ “id”: 2,
“product”: “Suiksilver The Gamer Watch”,
“price”: 132.99,
“gender”: “mens” }
]
id | body |
---|---|
1 | Rebekah Jones was the manager of the Geographic Information System team at Florida's Department of Health. |
2 | During what Commissioner Roger Goodell described as a two-hour meeting, the NFL made some changes in its approach to diversity, equity, and inclusion through an expansion of the Rooney Rule. |
[
{
“title”: “Florida Ousts Top COVID-19 Data Scientist”,
“body”: “Rebekah Jones was the manager of the Geographic Information System team at Florida's Department of Health.”,
“date”: “19/May/2020”
},
{
“title”: “NFL passes expansion of Rooney Rule”,
“body”: “During what Commissioner Roger Goodell described as a two-hour meeting, the NFL made some changes in its approach to diversity, equity, and inclusion through an expansion of the Rooney Rule.”,
“date”: “19/May/2020”
},
:
]
↓
文書分類 - model
↓
[
{
“title”: “Florida Ousts Top COVID-19 Data Scientist”,
“body”: “Rebekah Jones was the manager of the Geographic Information System team at Florida's Department of Health.”,
“category”: “science”,
“date”: “19/May/2020”
},
{
“title”: “NFL passes expansion of Rooney Rule”,
“body”: “During what Commissioner Roger Goodell described as a two-hour meeting, the NFL made some changes in its approach to diversity, equity, and inclusion through an expansion of the Rooney Rule.”,
“category”: “sports”,
“date”: “19/May/2020”
},
:
]
テキストから固有名詞を属性(固有名詞タイプ)付きで抽出するタスクを固有表現抽出(Named Entity Extraction; NEE)と呼びます。
location person title organization
東京都の小池百合子知事は25日記者会見し、「希望の党」を立ち上げ...
[
{
“title”: “Florida Ousts Top COVID-19 Data Scientist”,
“body”: “Rebekah Jones was the manager of the Geographic Information System team at Florida's Department of Health.”,
“date”: “19/May/2020”
},
{
“title”: “NFL passes expansion of Rooney Rule”,
“body”: “During what Commissioner Roger Goodell described as a two-hour meeting, the NFL made some changes in its approach to diversity, equity, and inclusion through an expansion of the Rooney Rule.”,
“date”: “19/May/2020”
},
:
]
↓
固有表現抽出 - model
↓
[
{
“title”: “Florida Ousts Top COVID-19 Data Scientist”,
“body”: “Rebekah Jones was the manager of the Geographic Information System team at Florida's Department of Health.”,
“person”: “Rebekah Jones”,
“title”: “manager”,
“org”: “Florida's Department of Health”,
“date”: “19/May/2020”
},
{
“title”: “NFL passes expansion of Rooney Rule”,
“body”: “During what Commissioner Roger Goodell described as a two-hour meeting, the NFL made some changes in its approach to diversity, equity, and inclusion through an expansion of the Rooney Rule.”,
“person”: “Roger Goodell”,
“title”: “Commissioner”,
“org”: “NFL”,
“date”: “19/May/2020”
},
:
]
(1) 再現率を高める(検索漏れがないようにする)
(2b) ランキングチューニング
result 50 100 500 1 2 3
target 50 100 500
result 1 2 3
target 1 2 3
文字正規化辞書、類義語ツール、外来語辞書、日本語文字表記揺れ対策
│ │
│ └→ ファセットと絞り込み検索、文書分類、固有表現抽出、言語判別
│
└→ クリックモデル、ハイパーパラメーター探索、ランキング学習
KandaSearch ライブラリにある Livedoor ニュースコーパスの config をインポートしてコレクション livedoornews を作成します。
コンフィグメニューで livedoornews の solrconfig.xml を「編集」で開き、次のコメント箇所を探して、コメントを外して有効化します。
<!-- uncomment when you index data for langid exercise
<requestHandler name="/update" class="solr.UpdateRequestHandler">
<lst name="defaults">
<str name="update.chain">langid</str>
</lst>
</requestHandler>
-->
本来はこのようなやりかたではなく、Appendixにある方法で update.chain=langid パラメーター付きでインデクシングします。
livedoornews コレクションをリロードします。
KandaSearch ライブラリにある演習用データセットを入手してローカルPCにダウンロードしてZIPファイルを解凍します。
解凍した中にある以下の演習用データ seminar5-langid.json を livedoornews コレクションにインデクシングします。
[
{"id": "en-1", "title": "This is an English text.", "body": "It is fine today."},
{"id": "de-1", "title": "Dies ist deutscher Text.", "body": "Es ist heute fein."},
{"id": "fr-1", "title": "C'est texte français.", "body": "C'est fin aujourd'hui."},
{"id": "ja-1", "title": "これは日本語のテキストです。", "body": "今日はいい天気です。"}
]
KandaSearch の検索、またはSolr Admin UIで全件検索し、各国言語の文書が正しく各国語用のフィールドに振り分けられていることを確認します。
<!-- depends on OpenNLP NER model
<updateRequestProcessorChain name="opennlp-ner">
<processor class="solr.OpenNLPExtractNamedEntitiesUpdateProcessorFactory">
<str name="modelFile">RONDHUIT-ja-ner-1.0.0.bin</str>
<str name="analyzerFieldType">opennlp-tokenization</str>
<str name="source">body</str>
<str name="dest">ner_{EntityType}</str>
</processor>
<processor class="solr.UniqFieldsUpdateProcessorFactory">
<str name="fieldRegex">ner_.*</str>
</processor>
<processor class="solr.RunUpdateProcessorFactory" />
<processor class="solr.LogUpdateProcessorFactory" />
</updateRequestProcessorChain>
-->
<requestHandler name="/update" class="solr.UpdateRequestHandler">
<lst name="defaults">
<str name="update.chain">langid</str>
</lst>
</requestHandler>
Apache OpenNLP の固有表現抽出は、機械学習モデルベースで動作するため、適切なモデルファイルが必要です。ここでは別の方法として、モデルファイルがなくても動作する、RCSSの「辞書ベースのNEE」機能を使う方法を紹介します。
<requestHandler name="/update" class="solr.UpdateRequestHandler">
<lst name="defaults">
<str name="update.chain">opennlp-ner</str>
</lst>
</requestHandler>
post -url https://<instance-name>.i.kandasearch.com/solr/langid/update seminar5-langid.xml -params "update.chain=langid"