PV211: Introduction to Information Retrieval https://www.fi.muni.cz/~sojka/PV211 MR 2: The term vocabulary and postings lists Handout version Petr Sojka, Hinrich Schütze et al Faculty of Informatics, Masaryk University, Brno Center for Information and Language Processing, University of Munich 2023-02-22 (compiled on 2023-02-15 08:37:49) Sojka, MR Group: PV211: The term vocabulary and postings lists 1/62 Recap Documents Terms Skip pointers Phrase queries O Recap Q Documents 0 Te rms General + Non-English • English Q Skip pointers O Ph rase queries Sojka, MR Group: PV211: The term vocabulary and postings lists 2/62 Recap Documents Terms Skip pointers Phrase queries For each term t, we store a list of all documents that contain t. Brutus —> 1 2 4 11 31 45 173 174 Caesar —> 1 2 4 5 6 16 57 132 . . . Calpurnia —> 2 31 54 101 V-v-' dictionary postings Sojka, MR Group: PV211: The term vocabulary and postings lists 4/62 Recap Documents Terms Skip pointers Phrase queries Information need: Information on the legal theories involved in preventing the disclosure of trade secrets by employees formerly employed by a competing company Query: "trade secret" /s disclos! /s prevent /s employe! Information need: Requirements for disabled people to be able to access a workplace Query: disab! /p access! /s work-site work-place (employment /3 place) Information need: Cases about a host's responsibility for drunk guests Query: host! /p (responsib! liab!) /p (intoxicat! drunk!) /p guest Sojka, MR Group: PV211: The term vocabulary and postings lists 5/62 Recap Documents Terms Skip pointers Phrase queries • On Google, the default interpretation of a query [1/1/1 1/1/2 ...wn] is wí AND 1/1/2 AND ... AND wn 9 Cases where you get hits that do not contain one of the w,\ 9 anchor text © page contains variant of w-, (morphology, spelling correction, synonym) o long queries (n large) • boolean expression generates very few hits • Simple Boolean vs. Ranking of result set • Simple Boolean retrieval returns matching documents in no particular order. • Google (and most well designed Boolean engines) rank the result set - they rank good hits (according to some estimator of relevance) higher than bad hits. Sojka, MR Group: PV211: The term vocabulary and postings lists 6/62 Recap Documents Terms Skip pointers Phrase queries 9 Understanding of the basic unit of classical information retrieval systems: words and documents: What is a document, what is a term? • Tokenization: how to get from raw text to words (or tokens) • More complex indexes: skip pointers and phrases Sojka, MR Group: PV211: The term vocabulary and postings lists 7/62 Recap Documents Terms Skip pointers Phrase queries in inver O Collect the documents to be indexed. O Tokenize the text. O Do linguistic preprocessing of tokens. O Index the documents that each term occurs in Sojka, MR Group: PV211: The term vocabulary and postings lists 9/62 Recap Documents Terms Skip pointers Phrase queries • Last lecture: Simple Boolean retrieval system o Our assumptions were: • We know what a document is. o We can "machine-read" each document. • This can be complex in reality: "God is in the details." (Mies van der Rohe) Sojka, MR Group: PV211: The term vocabulary and postings lists 10 / 62 Recap Documents Terms Skip pointers Phrase queries • We need to deal with format and language of each document. • What format is it in? pdf, word, excel, html, etc. • What language is it in? • What character set is in use? 9 Each of these is a classification problem, which we will study later in this course (MR 13). • Alternative: use heuristics Sojka, MR Group: PV211: The term vocabulary and postings lists 11 / 62 Recap Documents Terms Skip pointers Phrase queries rm nguag mpii • A single index usually contains terms of several languages. o Sometimes a document or its components contain multiple languages/formats. • French email with Spanish pdf attachment • What is the document unit for indexing? • A file? • An email? o An email with 5 attachments? • A group of files (ppt or latex in HTML)? 9 Upshot: Answering the question "what is a document?" is not trivial and requires some design decisions. o Also: XML Sojka, MR Group: PV211: The term vocabulary and postings lists 12 / 62 Recap Documents Terms Skip pointers Phrase queries • Word - A delimited string of characters as it appears in the text. • Term - A "normalized" word (case, morphology, spelling, etc.); an equivalence class of words. • Token - An instance of a word or term occurring in a document. 9 Type - The same as term in most cases: an equivalence class of tokens. More informally: what we consider same in the index, e.g. abstraction of a line in the incidence matrix. Sojka, MR Group: PV211: The term vocabulary and postings lists 15 / 62 Need to "normalize" words in indexed text as well as query terms into the same form. • Example: We want to match U.S.A. and USA 9 We most commonly implicitly define equivalence classes of terms. • Alternatively: do asymmetric expansion o window —>» window, windows o windows —>» Windows, windows Windows (no expansion) o More powerful, but less efficient • Why don't you want to put window, Window, windows, and Windows in the same equivalence class? Sojka, MR Group: PV211: The term vocabulary and postings lists 16 / 62 Recap Documents Terms Skip pointers Phrase queries rmanz r languag • Normalization and language detection interact. • PETER WILL NICHT MIT. MIT = mit o He got his PhD from MIT ^ MIT ^ mit Sojka, MR Group: PV211: The term vocabulary and postings lists 17 / 62 Recap Documents Terms Skip pointers Phrase queries • Input: Friends, Romans, countrymen So let it be with Caesar • Output: friend roman countryman so • Each token is a candidate for a postings entry. • What are valid tokens to emit? Sojka, MR Group: PV211: The term vocabulary and postings lists 18 / 62 Recap Documents Terms Skip pointers Phrase queries In June, the dog likes to chase the cat in the barn. - How many word tokens? How many word types? Why tokenization is difficult - even in English. Tokenize: Mr. O'Neill thinks that the boys' stories about Chile's capital aren't amusing. Sojka, MR Group: PV211: The term vocabulary and postings lists 19 / 62 Recap Documents Terms Skip pointers Phrase queries r iw 9 Hewlett-Packard • State-of-the-art • co-education • the hold-him-back-and-drag-him-away maneuver • data base • San Francisco 9 Los Angeles-based company • cheap San Francisco-Los Angeles fares o York University vs. New York University Sojka, MR Group: PV211: The term vocabulary and postings lists 20 / 62 Recap Documents Terms Skip pointers Phrase queries • 22/02/22 • 2022-02-22 o Feb 22, 2022 • B-52 • 100.2.86.144 • (800) 234-2333 • 800.234.2333 • Older IR systems may not index numbers ... » ... but generally it's a useful feature. o Google example (1+1) Sojka, MR Group: PV211: The term vocabulary and postings lists 21 / 62 Recap Documents Terms Skip pointers Phrase queries Chinese: No whitespace 90, w&^&mmm-±mmnm&r 18 Bo itMi^TfiW^ Sojka, MR Group: PV211: The term vocabulary and postings lists 22 / 62 Recap Documents Terms Skip pointers Phrase queries g in ese The two characters can be treated as one word meaning 'monk' or as a sequence of two words meaning 'and' and 'still'. Sojka, MR Group: PV211: The term vocabulary and postings lists 23 / 62 Recap Documents Terms Skip pointers Phrase queries • Compounds in Dutch, German, Swedish, Czech (cistokapsonosoplena) o Computerlinguistik —>► Computer + Linguistik o Lebensversicherungsgesellschaftsangestellter • —>► leben + Versicherung + gesellschaft + angestellter • Inuit: tusaatsiarunnanngittualuujunga (I can't hear very well.) • Many other languages with segmentation difficulties: Finnish, Urdu, ... Sojka, MR Group: PV211: The term vocabulary and postings lists 24 / 62 5MOTTA I NA I ^-V^—gli: Lt, & B SfKItt £ # 5 o # r *@ ^ ©ifr # t a: 3 $1 & 2 & n * i-Q 4 different "alphabets": Chinese characters, hiragana syllabary for inflectional endings and function words, katakana syllabary for transcription of foreign words and other uses, and latin. No spaces (as in Chinese). End user can express query entirely in hiragana! Sojka, MR Group: PV211: The term vocabulary and postings lists 25 / 62 Recap Documents Terms Skip pointers Phrase queries un b ä t i k /kitäbun/ 'a book' Sojka, MR Group: PV211: The term vocabulary and postings lists 26 / 62 Recap Documents Terms Skip pointers Phrase queries ^jill j^VI c> Uc 132 ^ 1962 ^ jjIJhJI c^ttLyjl <--> <--> <— START 'Algeria achieved its independence in 1962 after 132 years of French occupation.' Bidirectionality is not a problem if text is coded in Unicode. Sojka, MR Group: PV211: The term vocabulary and postings lists 27 / 62 Recap Documents Terms Skip pointers Phrase queries n • Accents: resume vs. resume (simple omission of accent) o Umlauts: Universität vs. Universitaet (substitution with special letter sequence "ae") • Most important criterion: How are users likely to write their queries for these words? • Even in languages that standardly have accents, users often do not type them. (Polish?) Sojka, MR Group: PV211: The term vocabulary and postings lists 28 / 62 Recap Documents Terms Skip pointers Phrase queries • Reduce all letters to lower case o Even though case can be semantically meaningful • capitalized words in mid-sentence o MIT vs. mit 9 Fed vs. fed • ... 9 It's often best to lowercase everything since users will use lowercase regardless of correct capitalization. Sojka, MR Group: PV211: The term vocabulary and postings lists 30 / 62 Recap Documents Terms Skip pointers Phrase queries P W( • stop words = extremely common words which would appear to be of little value in helping to select documents matching a user need • Examples: a, an, and, are, as, at, be, by, for, from, has, he, in, is, it, its, of, on, that, the, to, was, were, will, with • Stop word elimination used to be standard in older IR systems. • But you need stop words for phrase queries, e.g. "King of Denmark". • Most web search engines index stop words. Sojka, MR Group: PV211: The term vocabulary and postings lists 31 / 62 • Soundex: MR 3 (phonetic equivalence, Muller = Mueller) • Thesauri: MR 9 (semantic equivalence, car = automobile) Sojka, MR Group: PV211: The term vocabulary and postings lists 32 / 62 Recap Documents Terms Skip pointers Phrase queries • Reduce inflectional/variant forms to base form • Example: am, are, is —± be 9 Example: car, cars, car's, cars' —± car • Example: the boy's cars are different colors —± the boy car be different color 9 Lemmatization implies doing "proper" reduction to dictionary headword form (the lemma). • Inflectional morphology (cutting ^ cut) vs. derivational morphology (destruction —>► destroy) Sojka, MR Group: PV211: The term vocabulary and postings lists 33 / 62 • Definition of stemming: Crude heuristic process that chops off the ends of words in the hope of achieving what "principled" lemmatization attempts to do with a lot of linguistic knowledge. o Language dependent o Often inflectional and derivational • Example for derivational: automate, automatic, automation all reduce to automat Sojka, MR Group: PV211: The term vocabulary and postings lists 34 / 62 Recap Documents Terms Skip pointers Phrase queries ner aigori • Most common algorithm for stemming English • Results suggest that it is at least as good as other stemming options o Conventions + 5 phases of reductions • Phases are applied sequentially • Each phase consists of a set of commands. • Sample command: Delete final ement if what remains is longer than 1 character • replacement —>► replac • cement —>» cement o Sample convention: Of the rules in a compound command, select the one that applies to the longest suffix. Sojka, MR Group: PV211: The term vocabulary and postings lists 35 / 62 Recap Documents Terms Skip pointers Phrase queries w ruies Rule SSES I ES SS S —^ —^ —^ —^ ss ss Example caresses —>► caress ponies —>► poni caress —>► caress cats —>► cat Sojka, MR Group: PV211: The term vocabulary and postings lists 36 / 62 Recap Documents Terms Skip pointers Phrase queries mmer imp, Sample text: Such an analysis can reveal features that are not easily visible from the variations in the individual genes and can lead to a picture of expression that is more biologically transparent and accessible to interpretation Porter stemmer: such an analysi can reveal featur that ar not easili visibl from the variat in the individu gene and can lead to a pictur of express that is more biolog transpar and access to interpret Lovins stemmer: such an analys can reve featur that ar not eas vis from th vari in th individu gen and can lead to a pictur of expres that is mor biolog transpar and acces to interpres Paice stemmer: such an analys can rev feat that are not easy vis from the vary in the individ gen and can lead to a pict of express that is mor biolog transp and access to interpret Sojka, MR Group: PV211: The term vocabulary and postings lists 37 / 62 Recap Documents Terms Skip pointers Phrase queries Bimming improv* In general, stemming increases effectiveness for some queries, and decreases effectiveness for others. o Queries where stemming is likely to help: [tartan sweaters], [sightseeing tour san francisco] • (equivalence classes: {sweater,sweaters}, {tour,tours}) • Porter Stemmer equivalence class oper contains all of operate operating operates operation operative operatives operational. o Queries where stemming hurts: [operational AND research], [operating AND system], [operative AND dentistry] Sojka, MR Group: PV211: The term vocabulary and postings lists 38 / 62 Recap Documents Terms Skip pointers Phrase queries Exercise: What does Goo 'gl le do? o Stop words • Normalization • Tokenization • Lowercasing • Stemming • Non-latin alphabets • Umlauts • Compounds • Numbers Sojka, MR Group: PV211: The term vocabulary and postings lists 39 / 62 Recap Documents Terms Skip pointers Phrase queries 1 eca asic intersection aigontr im Brutus Calpurnia Intersection 1 ->■ 2 ->■ 4 ->■ 11 ->• 31 ->• 45 ->■ 173 ->■ 174 2 -> 31 ->■ 54 ->■ 101 31 a Linear in the length of the postings lists, a Can we do better? Sojka, MR Group: PV211: The term vocabulary and postings lists 41 / 62 Recap Documents Terms Skip pointers Phrase queries 51*60>71 Sojka, MR Group: PV211: The term vocabulary and postings lists 44 / 62 Recap Documents Terms Skip pointers Phrase queries I intersecting witn SKip pointers IntersectWithSkips(pi, p2) 1 answer «— ( ) 2 while pi ^ nil and p2 ^ nil 3 do if doclD(pi) = doclD(p2) 4 then Add (answer, doclD(pi)) 5 pi <— next(pi) 6 P2 «— next(p2) 7 else if doclD(p1) < doclD(p2) 8 then if hasSkip(pi) and (doclD(skip(pi)) < doclD(p2)) 9 then while hasSkip(pi) and (doclD(skip(pi)) < doclD(p2)) 10 do pi «— skip(pi) 11 else pi ^— next(pi) 12 else if hasSkip(p2) and (doclD(skip(p2)) < doclD(pi)) 13 then while hasSkip(p2) and (doclD(skip(p2)) < doclD(pi)) 14 do P2 «— skip(p2) 15 else p2 «— next(p2) 16 return answer Sojka, MR Group: PV211: The term vocabulary and postings lists 45 / 62 Recap Documents Terms Skip pointers Phrase queries • we p • Tradeoff: number of items skipped vs. frequency skip can be taken • More skips: Each skip pointer skips only a few items, but we can frequently use it. 9 Fewer skips: Each skip pointer skips many items, but we can not use it very often. Sojka, MR Group: PV211: The term vocabulary and postings lists 46 / 62 Recap Documents Terms Skip pointers Phrase queries • we p • Simple heuristic: for postings list of length P, use \J~P evenly-spaced skip pointers. • This ignores the distribution of query terms. • Easy if the index is static; harder in a dynamic environment because of updates. • How much do skip pointers help? • They used to help a lot. o With today's fast CPUs, they don't help that much anymore. Sojka, MR Group: PV211: The term vocabulary and postings lists 47 / 62 Recap Documents Terms Skip pointers Phrase queries o We want to answer a query such as [Masaryk university] - as a phrase. 9 Thus The president Tomas Garrigue Masaryk never went to Stanford university should not be a match. • The concept of phrase query has proven easily understood by users. o About 10% of web queries are phrase queries. • Consequence for inverted index: it no longer suffices to store doclDs in postings lists. • Two ways of extending the inverted index: • biword index • positional index 9 Any ideas? Sojka, MR Group: PV211: The term vocabulary and postings lists 49 / 62 o Index every consecutive pair of terms in the text as a phrase. • For example, Friends, Romans, Countrymen would generate two biwords: "friends romans" and "romans countrymen" 9 Each of these biwords is now a vocabulary term. • Two-word phrases can now easily be answered. Sojka, MR Group: PV211: The term vocabulary and postings lists 50 / 62 • A long phrase like "masaryk university brno" can be represented as the Boolean query "masaryk university" AND "university brno" • We need to do post-filtering of hits to identify subset that actually contains the 3-word phrase. Sojka, MR Group: PV211: The term vocabulary and postings lists 51 / 62 Recap Documents Terms Skip pointers Phrase queries Iwora inaex a Why are biword indexes rarely used? • False positives, as noted above Index blowup due to very large term vocabulary Sojka, MR Group: PV211: The term vocabulary and postings lists 52 / 62 Recap Documents Terms Skip pointers Phrase queries o Positional indexes are a more efficient alternative to biword indexes. • Postings lists in a nonpositional index: each posting is just a docID • Postings lists in a positional index: each posting is a docID and a list of positions Sojka, MR Group: PV211: The term vocabulary and postings lists 53 / 62 Recap Documents Terms Skip pointers Phrase queries inaex Query: "tO\ be^ or^ noU tos bee to, 993427: 1: (7, 18, 33, 72, 86, 231); 2: (1, 17, 74, 222, 255); 4: (8, 16, 190, 429, 433); 5: (363, 367); 7: (13, 23, 191); ... be, 178239 4 5 17, 25); 17, 191, 291, 430, 434); 14, 19, 101); ... Document 4 is a match! Sojka, MR Group: PV211: The term vocabulary and postings lists 54 / 62 Recap Documents Terms Skip pointers Phrase queries Shown below is a portion of a positional index in the format: term: docl: (positionl, position2, ...); doc2: (positionl, position2, . ..); etc. angels; 2; {36,174,252,651); 4: (12,22,102,432); 7: (17); fools; 2: (1,17,74,222); 4: (8,78,108,458); 7: (3,13,23,193); fear; 2: (87,704,722,901); 4: (13,43,113,433); 7: (18,328,528); in; 2; (3,37,76,444,851); 4: (10,20,110,470,500); 7: (5,15,25,195); rush; 2; (2,66,194,321,702); 4: (9,69,149,429,569); 7: (4,14,404); to; 2; (47,86,234,999); 4: (14,24,774,944); 7: (19,319,599,709); tread; 2; (57,94,333); 4: (15,35,155); 7: (20,320); where; 2; (67,124,393,1001); 4: (11,41,101,421,431); 7: (16,36,736); Which document(s) if any match each of the following two queries, where each expression within quotes is a phrase query?: "fools rush in", "fools rush in" AND "angels fear to tread" Sojka, MR Group: PV211: The term vocabulary and postings lists 55 / 62 Recap Documents Terms Skip pointers Phrase queries • We just saw how to use a positional index for phrase searches. • We can also use it for proximity search. • For example: employment /4 place 9 Find all documents that contain employment and place within 4 words of each other. • Employment agencies that place healthcare workers are seeing growth is a hit. 9 Employment agencies that have learned to adapt now place healthcare workers is not a hit. Sojka, MR Group: PV211: The term vocabulary and postings lists 56 / 62 Recap Documents Terms Skip pointers Phrase queries • Use the positional index • Simplest algorithm: look at cross-product of positions of (i) employment in document and (ii) place in document • Very inefficient for frequent words, especially stop words Note that we want to return the actual matching positions, not just a list of documents. 9 This is important for dynamic summaries, etc. Sojka, MR Group: PV211: The term vocabulary and postings lists 57 / 62 Recap Documents Terms Skip pointers Phrase queries ■ roximny inter answer while pi 7^ nil and P2 7^ nil do if doclDipx) = doclD{p2) then /«- ( ) ppi ^— positions(pi) PP2 ^— positions(p2) while ppi 7^ nil do while pp2 7^ nil do if |pos(ppi) - pos(pp2)\ < k then Add(/, pos(pp2)) else if pos(pp2) > pos(ppi) then break pp2 <- next(pp2) while / 7^ () and |/[0] - pos(ppi)| > k do Delete(/[0]) for each ps e / do Add (answer, (doclD(pi), pos(ppi), ps)) ppi «- next(ppi) pi «- next(pi) p2 «- next(p2) else if doclD(pi) < doclD(p2) then pi «— next(pi) else P2 ^— next(p2) return answer Sojka, MR Group: PV211: The term vocabulary and postings lists 58 / 62 Recap Documents Terms Skip pointers Phrase queries Biword indexes and positional indexes can be profitably combined. • Many biwords are extremely frequent: Michael Jackson, Britney Spears, etc. • For these biwords, increased speed compared to positional postings intersection is substantial. o Combination scheme: Include frequent biwords as vocabulary terms in the index. Do all other phrases by positional intersection. • Williams et al. (2004) evaluate a more sophisticated mixed indexing scheme. Faster than a positional index, at a cost of 26% more space for index. Sojka, MR Group: PV211: The term vocabulary and postings lists 59 / 62 Recap Documents Terms Skip pointers Phrase queries monai qu o For web search engines, positional queries are much more expensive than regular Boolean queries. o Let's look at the example of phrase queries. • Why are they more expensive than regular Boolean queries? • Can you demonstrate on Google that phrase queries are more expensive than Boolean queries? Sojka, MR Group: PV211: The term vocabulary and postings lists 60 / 62 Recap Documents Terms Skip pointers Phrase queries 9 Understanding of the basic unit of classical information retrieval systems: words and documents: What is a document, what is a term? • Tokenization: how to get from raw text to words (or tokens) • More complex indexes: skip pointers and phrases Sojka, MR Group: PV211: The term vocabulary and postings lists 61 / 62 • Chapter 2 of MR • Resources at https://www.fi.muni.cz/~sojka/PV211/ and http://cislmu.org, materials in MU IS and Fl MU library 9 NLP IR boolean search system example: Sketch Engine: https://ske.fi.muni.cz 9 Google query language and preprocessing Sojka, MR Group: PV211: The term vocabulary and postings lists 62 / 62