tf-idf
情報検索の分野において、tf–idf (または、 TF*IDF、TFIDF、TF–IDF、Tf–idf)は、term frequency–inverse document frequencyの略であり、コーパスや収集された文書群において、ある単語がいかに重要なのかを反映させることを意図した統計量(数値)である[1] 。また、tf-idfは情報検索や、テキストマイニング、ユーザーモデリング (英語版)における重み係数 (英語版)にもよく用いられる。ある単語のtf-idfの値は文書内におけるその単語の出現回数に比例して増加し、また、その単語を含むコーパス内の文書数によってその増加が相殺される。この性質は、一般にいくつかの単語はより出現しやすいという事実をうまく調整することに役立っている。今日、tf-idfはもっとも有名な語の重みづけ(term-weighting)手法である。2015年に行われた研究では、電子図書館におけるテキストベースのレコメンダシステムのうち83%がtf-idfを利用していたことがわかった[2] 。
tf-idfの重み付け手法を変形したものは、ユーザーのクエリ(検索ワード)から文書の適合性を得点化し、順位づけする際の中心的なツールとして、よく検索エンジンで用いられている。tf-idfは、自動要約や文書分類といった様々な分野において、ストップワード (英語版)によるフィルタリングを行うことでうまく動作できる。
最もシンプルな順位付け関数(ranking function) (英語版)の一つは、クエリに含まれる語ごとのtf-idfの和を計算することで実装される。たくさんのより洗練された順位付け関数はこのシンプルなモデルの変形となっている。
動機
[編集 ]Term frequency (単語頻度)
[編集 ]英語文書の集合を扱っていると仮定し、それらを"the brown cow"というクエリにより関連する順に並べたいとする。問題に取り掛かる上で、シンプルな方法は、"the"、"brown"、"cow"の3つの単語のすべてを含まない文書を除くことであるが、これではたくさん文書がまだ残ってしまう。さらにそれらを区別するために、もしかすると各文書で各単語が何度出現しているかを数えるかもしれない。ある文書内にある単語が何回出現したかという数をその単語のterm frequencyと呼ぶ。しかし、文書の長さにばらつきがある場合、調整が必要となることが多い(詳細は定義を参照)。最初の語の重み付け手法はHans Peter Luhn (英語版)(1957)により、その内容は以下のようにまとめられうる[3] 。
文書内の単語の重みは、その出現頻度に単純に比例する。
Inverse document frequency (逆文書頻度)
[編集 ]"the"という語が非常に普遍であるために、より意味のある単語である"brown"や"cow"に十分な重みを与えず、term frequencyは、"the"という語をより高頻度に含む文書を誤って強調してしまう傾向がある。"the"という語は、普遍的ではない"brown"や"cow"という語とは異なり、文書や単語がクエリに関連している・関連していないと区別するためのキーワードとしてよいものではない。それゆえに、文書集合において非常に出現頻度の高い語の重みを減らし、珍しい語の重みを増加させるため、inverse document frequencyが用いられている。
Karen Spärck Jones (英語版)(1972) はInverse Document Frequency (idf) と呼ばれる単語の特異性の統計的解釈を考案し、その考えは単語の重み付けの基礎概念となっている[4] 。
単語の特異性は、その単語が出現した文書数の逆関数によって定量化できる。
定義
[編集 ]- tf-idfは2つの統計量、term frequency (tf)と、inverse document frequency (idf) の積である。双方の統計量には、厳密な値を決定するために様々な手法が存在している。
- 式は、文書やWebページにおけるキーワードやフレーズの重要性を定義することを目的とする。
重み付け手法 | tf 重み |
---|---|
binary
(2値) |
{\displaystyle {0,1}} |
raw count
(出現頻度をそのまま使用) |
{\displaystyle f_{t,d}} |
term frequency
(標準的な単語頻度) |
{\displaystyle f_{t,d}{\Bigg /}{\sum _{t'\in d}{f_{t',d}}}} |
log normalization
(対数による正規化) |
{\displaystyle \log(1+f_{t,d})} |
double normalization 0.5
(二重0.5正規化) |
{\displaystyle 0.5+0.5\cdot {\frac {f_{t,d}}{\max _{\{t'\in d\}}{f_{t',d}}}}} |
double normalization K
(二重K正規化) |
{\displaystyle K+(1-K){\frac {f_{t,d}}{\max _{\{t'\in d\}}{f_{t',d}}}}} |
Term frequency (単語頻度)
[編集 ]term frequency (tf) は文書dの中での、語tの相対度数である。{\displaystyle \mathrm {tf} (t,d)={\frac {f_{t,d}}{\sum _{t'\in d}{f_{t',d}}}}},
ft,dは文書に含まれるその語の出現頻度(raw count)である。すなわち、語tが文書dに何回出現したかを意味する。単純には、分母には文書dに含まれる単語数を用いる(この場合、同じ単語が複数出現しても区別して数える)。tf(t,d)の定義は他にも様々なものがある[5] :128。
- ブール代数に基づく「頻度」(binary): tがdに存在すれば、 tf(t,d) = 1、 それ以外の場合はtf(t,d) = 0;
- 出現頻度をそのまま用いる(raw count): tf(t,d) = ft,d;
- 文書の長さを調整するもの(term frequency, 上式と同じ): tf(t,d) = ft,d ÷ (dに含まれる単語数);
- 対数スケールの頻度(log normalization): tf(t,d) = log (1 + ft,d)[6] ;
- 長い文書に偏ることを防ぐために、拡張された頻度。例えば、ある語の出現回数が、文書内で最も出現頻度が高い語の出現回数で除算されるようにされているものなど。
- {\displaystyle \mathrm {tf} (t,d)=0.5+0.5\cdot {\frac {f_{t,d}}{\max\{f_{t',d}:t'\in d\}}}} (double normalization 0.5)
Inverse document frequency (逆文書頻度)
[編集 ]重み付け手法 | idf 重み ({\displaystyle n_{t}=|\{d\in D:t\in d\}|}) |
---|---|
idfを使用しない | 1 |
inverse document frequency
(標準的なidf) |
{\displaystyle \log {\frac {N}{n_{t}}}=-\log {\frac {n_{t}}{N}}} |
inverse document frequency smooth
(+1をしてスムージングを行うidf) |
{\displaystyle \log \left({\frac {N}{1+n_{t}}}\right)+1} |
inverse document frequency max
(最大値を取るidf) |
{\displaystyle \log \left({\frac {\max _{\{t'\in d\}}n_{t'}}{1+n_{t}}}\right)} |
probabilistic inverse document frequency
(確率論的idf) |
{\displaystyle \log {\frac {N-n_{t}}{n_{t}}}} |
inverse document frequency (idf) はその単語がどのくらい情報を提供するのかという指標である。すなわち、ある単語が、すべての文書の中で普遍的なのか珍しいのかということである。idfは、その単語の文書頻度の逆数を対数スケールにしたものである。(文書の総数をその単語を含む文書の数で除算し、その商の対数を取ったものとして得られる。)
- {\displaystyle \mathrm {idf} (t,D)=\log {\frac {N}{|\{d\in D:t\in d\}|}}}
この時、
- {\displaystyle N}: コーパスに含まれる文書の総数 {\displaystyle N={|D|}}
- {\displaystyle |\{d\in D:t\in d\}|} : 単語{\displaystyle t}が出現する文書の数 (すなわち、 {\displaystyle \mathrm {tf} (t,d)\neq 0}でなくてはならない)。 もしその語がコーパスに存在しない場合、これはゼロ除算を招く。それゆえに、分母を{\displaystyle 1+|\{d\in D:t\in d\}|}と調整するのが一般的である。
Term frequency–inverse document frequency (tf-idf)
[編集 ]ここで、tf-idfは次のように計算される。
- {\displaystyle \mathrm {tfidf} (t,d,D)=\mathrm {tf} (t,d)\cdot \mathrm {idf} (t,D)}
tf-idfの重みが高くなるのは、(与えられた文書内で)その単語の単語頻度(term frequency, tf)が高く、かつ、文書集合全体においてその単語の文書頻度(document frequency, df)が低い場合である。それゆえに、重みは普遍的な語をフィルタする傾向がある。idfの対数内の分数は常に1以上となるため、idf(とtf-idf)の値は常に0以上になる。単語がより多くの文書に現れる場合、対数の中の分数は1に近づき、それゆえにidfとtf-idfは0に近づく。
重み付け手法 | 文書における利用 | クエリにおける利用 |
---|---|---|
1 | {\displaystyle f_{t,d}\cdot \log {\frac {N}{n_{t}}}} | {\displaystyle \left(0.5+0.5{\frac {f_{t,q}}{\max _{t}f_{t,q}}}\right)\cdot \log {\frac {N}{n_{t}}}} |
2 | {\displaystyle \log(1+f_{t,d})} | {\displaystyle \log \left(1+{\frac {N}{n_{t}}}\right)} |
3 | {\displaystyle (1+\log f_{t,d})\cdot \log {\frac {N}{n_{t}}}} | {\displaystyle (1+\log f_{t,q})\cdot \log {\frac {N}{n_{t}}}} |
idfの正当化
[編集 ]idfは1972年のKaren Spärck Jones (英語版)の論文によって「単語の特異性」として導入された。idfはヒューリスティクスでうまくいくとされてきたにもかかわらず、その論理的な基礎は少なくとも30年以上悩みの種となっており、多くの研究者が情報理論的な正当化を試み続けている[7] 。
Spärck Jonesは自身の説明の中で、ジップの法則を別にして、十分な理論を提供していない[7] 。与えられた文書dが語tを含む確率を、相対文書頻度として推定することによって、idfを確率論的基盤に置こうとする試みが行われてきている[8] 。
{\displaystyle P(t|D)={\frac {|\{d\in D:t\in d\}|}{N}},}
idfを次のように定義すると、
- {\displaystyle {\begin{aligned}\mathrm {idf} &=-\log P(t|D)\\&=\log {\frac {1}{P(t|D)}}\\&=\log {\frac {N}{|\{d\in D:t\in d\}|}}\end{aligned}}}
つまり、逆文書頻度は対数を取った「逆」相対文書頻度となる。
また、この確率論的解釈は自己情報量と同じ形を取る。しかし、そのような情報理論的概念を情報検索の問題に応用すると、必要な確率分布に適切な確率空間を定義する際、文書だけでなく、クエリや単語を考慮する必要があるため、問題が生ずる[7] 。
情報理論との関係
[編集 ]term frequency (tf) とinverse document frequency (idf) の両者は情報理論の観点から定式化されうる。この考えは、なぜそれらの積が文書の結合情報量の観点から意味があるのかを理解するのに役立つ。分布{\displaystyle p(d,t)}に関する特徴的な仮定を以下の示す。
- {\displaystyle p(d|t)={\frac {1}{|\{d\in D:t\in d\}|}}}
この仮定とその意味は、Aizawaによれば、「ヒューリスティックなtf-idfの使われ方を表している。」という[9] 。
特定の語{\displaystyle t}を含む事象を条件として、コーパス{\displaystyle D}の文書を「ランダムで選択」する条件付きエントロピー (英語版)は以下のように示される(全文書は等しい確率で選択されると仮定する)。
- {\displaystyle H({\cal {D}}|{\cal {T}}=t)=-\sum _{d}p_{d|t}\log p_{d|t}=-\log {\frac {1}{|\{d\in D:t\in d\}|}}=\log {\frac {|\{d\in D:t\in d\}|}{|D|}}+\log |D|=-\mathrm {idf} (t)+\log |D|}
表記に関して、{\displaystyle {\cal {D}}}と{\displaystyle {\cal {T}}}は「ランダムな変数」であり、文書や単語がそれぞれ選ばれることに相当する。ここで、相互情報量は以下のように表される。
- {\displaystyle M({\cal {T}};{\cal {D}})=H({\cal {D}})-H({\cal {D}}|{\cal {T}})=\sum _{t}p_{t}\cdot (H({\cal {D}})-H({\cal {D}}|W=t))=\sum _{t}p_{t}\cdot \mathrm {idf} (t)}
最後のステップは{\displaystyle p_{t}}を展開することであり、文書の(ランダムな)選択に関して、条件と無関係に単語を選択する確率であるから、
- {\displaystyle M({\cal {T}};{\cal {D}})=\sum _{t,d}p_{t|d}\cdot p_{d}\cdot \mathrm {idf} (t)=\sum _{t,d}\mathrm {tf} (t,d)\cdot {\frac {1}{|D|}}\cdot \mathrm {idf} (t)={\frac {1}{|D|}}\sum _{t,d}\mathrm {tf} (t,d)\cdot \mathrm {idf} (t).}
この式は、すべての有効な単語と文書のtf-idfの和は、文書と単語の同時確率分布の特異性のすべてを考慮した、文書と単語の間の相互情報量に立ち戻ることを表している[9] 。それゆえに、それぞれのtf-idfは、ある単語と文書のペアに付け足された、「情報のかけら(bit of information)」を意味している。
tf–idfの例
[編集 ]2つの文書からのみ構成されるコーパスの単語カウント表(右に示す)を扱うと仮定する。
語 | 語のカウント |
---|---|
this | 1 |
is | 1 |
another | 2 |
example | 3 |
語 | 語のカウント |
---|---|
this | 1 |
is | 1 |
a | 2 |
sample | 1 |
語"this"のtf-idfは以下のように計算される。
出現頻度をそのままtfとして用いる場合、tfはそれぞれの文書の"this"の頻度と同じになる。標準的な文書長を調整するtfでは、各文書において単語"this"は1度現れるが、文書2はより多くの単語を含むため、相対頻度は小さくなる。
- {\displaystyle \mathrm {tf} ({\mathsf {''this''}},d_{1})={\frac {1}{5}}=0.2}
- {\displaystyle \mathrm {tf} ({\mathsf {''this''}},d_{2})={\frac {1}{7}}\approx 0.14}
idfはコーパス毎の定数であり、"this"という単語を含む文書の比率から成り立っている。この事例では、2つの文書からなるコーパスを扱い、それらはすべて"this"という語を含んでいる。
- {\displaystyle \mathrm {idf} ({\mathsf {''this''}},D)=\log \left({\frac {2}{2}}\right)=0}
つまり、"this"という語のtf-idfはゼロである。これはこの単語がすべての文書に現れることから、その単語が有益でないでないこと示唆している。
- {\displaystyle \mathrm {tfidf} ({\mathsf {''this''}},d_{1},D)=0.2\times 0=0}
- {\displaystyle \mathrm {tfidf} ({\mathsf {''this''}},d_{2},D)=0.14\times 0=0}
"example"という語はより興味深く――3度現れるが、文書2にしか現れない。
- {\displaystyle \mathrm {tf} ({\mathsf {''example''}},d_{1})={\frac {0}{5}}=0}
- {\displaystyle \mathrm {tf} ({\mathsf {''example''}},d_{2})={\frac {3}{7}}\approx 0.429}
- {\displaystyle \mathrm {idf} ({\mathsf {''example''}},D)=\log \left({\frac {2}{1}}\right)=0.301}
最終的には,
- {\displaystyle \mathrm {tfidf} ({\mathsf {''example''}},d_{1},D)=\mathrm {tf} ({\mathsf {''example''}},d_{1})\times \mathrm {idf} ({\mathsf {''example''}},D)=0\times 0.301=0}
- {\displaystyle \mathrm {tfidf} ({\mathsf {''example''}},d_{2},D)=\mathrm {tf} ({\mathsf {''example''}},d_{2})\times \mathrm {idf} ({\mathsf {''example''}},D)=0.429\times 0.301\approx 0.129}
(対数は常用対数を用いている。)
単語以外への応用
[編集 ]tf-idfの背後にある考えは、単語以外の存在にも応用される。1998年にはidfのコンセプトが引用分析に応用された[10] 。筆者は「もし非常に珍しい引用が2つの文書によって共有されたならば、その引用された文書はたくさんの文書によって引用されている文書よりもより高く重み付けされるべきである。」と主張した。加えて、動画や内における物体マッチングを行うための「visual words (英語版)」や[11] 全文検索にも[12] tf-idfは応用されている。しかし、tf-idfのコンセプトは、すべての手法において、単純な(idf成分を除いた)tfのみの手法よりも効果的であるという証明はされていない。tf-idfを引用分析に応用する際には、研究者はidf重みをもたない単純な引用回数重みを超える精度向上を確認することができなかった[13] 。
tf-idfの派生
[編集 ]多数の単語重み付け手法はtf-idfからの派生である。そのうちの一つはTF-PDF (term frequency * proportional document frequency) である[14] 。TF-PDFは2001年にメディアにおける新たなトピックを特定するという文脈で導入された。PDF成分は異なるドメインの中でどのくらいの頻度である単語が出現したかの差を測定する。他の派生にはTF-IDuFがある。TF-IDuFでは[15] 、idfは文書コーパスに基づき計算されず、検索または推薦される。例えば、idfはユーザの個人的な文書コレクションに基づいて計算される。その著者らはTF-IDuFはtf-idfと等しく効果的であるが、例えば、ユーザーモデリング (英語版)システムにおいて、外部の文書コーパスにアクセスできない時などに、応用可能であると報告している。
関連項目
[編集 ]参考文献
[編集 ]- ^ Rajaraman, A.; Ullman, J.D. (2011). "Data Mining". Mining of Massive Datasets. pp. 1–17. doi:10.1017/CBO9781139058452.002. ISBN 978-1-139-05845-2 . http://i.stanford.edu/~ullman/mmds/ch1.pdf
- ^ Breitinger, Corinna; Gipp, Bela; Langer, Stefan (2015年07月26日). "Research-paper recommender systems: a literature survey" (英語). International Journal on Digital Libraries 17 (4): 305–338. doi:10.1007/s00799-015-0156-0. ISSN 1432-5012 . http://nbn-resolving.de/urn:nbn:de:bsz:352-0-311312 .
- ^ Luhn, Hans Peter (1957). "A Statistical Approach to Mechanized Encoding and Searching of Literary Information". IBM Journal of Research and Development 1 (4): 309–317. doi:10.1147/rd.14.0309 . https://web.stanford.edu/class/linguist289/luhn57.pdf 2 March 2015閲覧. "There is also the probability that the more frequently a notion and combination of notions occur, the more importance the author attaches to them as reflecting the essence of his overall idea."
- ^ Spärck Jones, K. (1972). "A Statistical Interpretation of Term Specificity and Its Application in Retrieval". Journal of Documentation 28: 11–21. doi:10.1108/eb026526.
- ^ Manning, C.D.; Raghavan, P.; Schutze, H. (2008). "Scoring, term weighting, and the vector space model". Introduction to Information Retrieval. pp. 100. doi:10.1017/CBO9780511809071.007. ISBN 978-0-511-80907-1 . http://nlp.stanford.edu/IR-book/pdf/06vect.pdf
- ^ "TFIDF statistics | SAX-VSM". 2022年3月29日閲覧。
- ^ a b c Robertson, S. (2004). "Understanding inverse document frequency: On theoretical arguments for IDF". Journal of Documentation 60 (5): 503–520. doi:10.1108/00220410410560582.
- ^ See also Probability estimates in practice in Introduction to Information Retrieval.
- ^ a b Aizawa, Akiko (2003). "An information-theoretic perspective of tf–idf measures" (英語). Information Processing and Management 39 (1): 45–65. doi:10.1016/S0306-4573(02)00021-3.
- ^ Bollacker, Kurt D.; Lawrence, Steve; Giles, C. Lee (1998年01月01日). CiteSeer: An Autonomous Web Agent for Automatic Retrieval and Identification of Interesting Publications. AGENTS '98. 116–123. doi:10.1145/280765.280786. ISBN 978-0-89791-983-8 . https://www.semanticscholar.org/paper/b23a5a62b7cb5278ceb5a6cc021c28a92041d792
- ^ Sivic, Josef; Zisserman, Andrew (2003年01月01日). Video Google: A Text Retrieval Approach to Object Matching in Videos. ICCV '03. 1470–. doi:10.1109/ICCV.2003.1238663. ISBN 978-0-7695-1950-0 . http://dl.acm.org/citation.cfm?id=946247.946751
- ^ Seki, Yohei. "Sentence Extraction by tf/idf and Position Weighting from Newspaper Articles". National Institute of Informatics. 2022年3月29日閲覧。
- ^ Beel, Joeran; Breitinger, Corinna (2017). "Evaluating the CC-IDF citation-weighting scheme – How effectively can 'Inverse Document Frequency' (IDF) be applied to references?". Proceedings of the 12th IConference. http://beel.org/publications/2017%20iConference%20--%20Evaluating%20the%20CC-IDF%20citation-weighting%20scheme%20--%20preprint.pdf .
- ^ Khoo Khyou Bun; Bun, Khoo Khyou; Ishizuka, M. (2001) (英語). Emerging Topic Tracking System. 2. doi:10.1109/wecwis.2001.933900. ISBN 978-0-7695-1224-2
- ^ Langer, Stefan; Gipp, Bela (2017). "TF-IDuF: A Novel Term-Weighting Scheme for User Modeling based on Users' Personal Document Collections". IConference. https://www.gipp.com/wp-content/papercite-data/pdf/beel17.pdf .
- Salton, G; McGill, M. J. (1986). Introduction to modern information retrieval. McGraw-Hill. ISBN 978-0-07-054484-0 . https://archive.org/details/introductiontomo00salt
- Salton, G.; Fox, E. A.; Wu, H. (1983). "Extended Boolean information retrieval". Communications of the ACM 26 (11): 1022–1036. doi:10.1145/182.358466. hdl:1813/6351 .
- Salton, G.; Buckley, C. (1988). "Term-weighting approaches in automatic text retrieval". Information Processing & Management 24 (5): 513–523. doi:10.1016/0306-4573(88)90021-0. hdl:1813/6721 . https://ecommons.cornell.edu/bitstream/1813/6721/1/87-881.pdf .
- Wu, H. C.; Luk, R.W.P.; Wong, K.F.; Kwok, K.L. (2008). "Interpreting TF-IDF term weights as making relevance decisions". ACM Transactions on Information Systems 26 (3): 1. doi:10.1145/1361684.1361686. hdl:10397/10130 . https://www.semanticscholar.org/paper/f6bbbf2cc785cf96019dcd9c41ab1801aad962dd .
外部リンクと推薦図書
[編集 ]- Gensimはベクトル空間モデルとtf-idf重み付けを含むPythonのライブラリである。
- Anatomy of a search engine
- tf–idf and related definitions (Luceneで使われている)
- TfidfTransformer scikit-learnのtf-idf実装。
- Text to Matrix Generator (TMG) MATLABツールボックスはテキストマイニング(TM)の様々なタスク向けに利用できる。特に i) 索引作成 ii) 情報検索 iii) 次元削減 iv) クラスタリング v) 分類 タスクである。索引作成の段階はユーザに任せられており、tf-idfを含めたローカル、あるいはグローバルの重み付け手法を適用する必要がある。
- Term-frequency explained term-frequencyの説明