Text retrieval

Inverted Indexes

  • A data structure that given a term provides access to the list of documents that contain the term (inverted means we treat the “word” as the key and documents are associated to this word)
  • Retrieval engine uses the inverted index to score documents that contain the query terms based on some ranking model

  • Posting: a tuple of (document id, payload) associated with a term

    • Document ID
      • Assumed to be a unique integer from 1 to n, where n is the total number of documents
    • Payload
      • Could be empty for simple Boolean retrieval
      • Could include term frequency (tf), the number of times the term occur in the document
  • GOAL:
    Given a query, retrieval involves fetching posting lists associated with query terms and traversing the postings to compute the result set.

    • Retrieval:
      1. Boolean Retrieval: Apply union (OR) or intersection (AND) of posting lists to check whether two documents consists of the same key (word)
      2. General Retrieval: Ranking of the document scores on the word / Returning top K documents

Baseline Implementation

  • Construction: construct an inverted index given a document collection

    • Mapper Inputs:
      1. Document IDs (keys)
      2. Actual document content (values)
    • Mapper Duties:
      1. Analyze each document and extract useful terms
      2. Compute term frequencies
      3. Emit
    • Reducer:

      1. Aggregates all observed postings for each term
      2. Construct the posting list

    • Notice: The reducer first buffers all postings (line 5) and then performs an in-memory sort before writing the postings to disk, so we should assume the reducer has sufficient memory to hold all postings associated with the same term (in order to sort them).

Revised Implementation

Instead of emitting (term t, posting <docid, f>), Emit (tuple <t, docid>, f) (Value-to-key conversion).
Caution: a customized partitioner is necessary to ensure that all tuples with the same term are shuffled to the same reducer.

Retrieval

Response time needs to be very small for the retrieval phase.

  • MapReduce is designed for large batch operations, and is a poor solution for retrieval as many random seeks will be introduced and many round-trips in distributed file systems.

  • Overcome:

    1. Distributed Retrieval and partition indexes
      • Document partitioning
        Entire collection is partitioned into smaller sub-collections
      • Term partitioning
        Each server handles a subset of terms for the entire collection

Graph Algorithms

    • V represents the set of vertices (nodes)
    • E represents the set of edges (links)
    • Both vertices and edges may contain additional information
  • Challenging: Algorithms running on a single machine and putting the entire graph in memory are not scalable

  • Key questions:

    • How do you represent graph data in MapReduce?
    • How do you traverse a graph in MapReduce?
  • Graph Representations:

    1. Adjacency matrix

      • Advantages:

        • Easy to manipulate with linear algebra
        • Easy algorithmic implementation
      • Disadvantage:

        • Large memory space, especially for sparse graphs (Many zeroes in the matrix)
    2. Adjacency list

      • Advantages:

        • Much more compact representation
        • Easy to compute over out-links
      • Disadvantage:

        • Much more difficult to compute over in-links
    • However, the shuffle and sort mechanism in MapReduce provides an easy way to group edges by destination nodes, thus allowing us to compute over incoming edges in the reducerHowever, the shuffle and sort mechanism in MapReduce provides an easy way to group edges by destination nodes, thus allowing us to compute over incoming edges in the reducer.

Dijkstra’s Algorithm

  • Dijkstra’s algorithm is designed as a sequential algorithm
  • Priority queue that maintains a globally sorted list of nodes by current distance, which is not possible in MapReduce, as it doesn’t provide a mechanism for exchanging global data

Parallel BFS

  • Intuition:

    • Define b is reachable from a if b is on the adjacency list of a, the starting point DistanceTo(s) = 0
    • For all nodes p reachable from s
      • DistanceTo(p) = 1
    • For all nodes n reachable from some other set of nodes M
      • DistanceTo(n) = 1 + min(DistanceTo(m), m in M)
  • Implementation

    • Data Representation:

      • Key: node n
      • Value: d (distance from start) and AdjacencyList (list of nodes reachable from n)
    • Mapper:

      • For every m in adjacency list: EMIT(m, d + 1)
    • Reducer:

      • Select minimum distance path for each reachable node
      • Additional bookkeeping needed to keep track of actual path
    • Iterations:

      • Each iteration corresponds to a MapReduce job
  • Convergence: (Stopping Criterion)

    • Iterate the algorithm until all node distances are found (no inf)
    • Maintain a counter inside the MapReduce program to count how many node distances are found
    • Require a non-MapReduce driver program to submit a MapReduce job to iterate the algorithm

Page Rank

Page rank is a measurement of web page quality, used by Google’s search algorithm. The idea is to rank the webpages by popularity which defined as the number of link that going from the other pages.

In this case, we want to compute the popularity of page X, which means how often is going to visit page X.

  • Definition
    • $C(t)$: the out-degree of t
    • $\alpha$: the probability of random jump
    • $N$: the total number of nodes in the graph
  • Implementation

    • Initialization:

      • Every node share the average mass ($\frac{1}{|G|}$)

    • Mapper Phase:
      • For each node, computes how much PageRank mass is emitted as value (N.PageRank / |N.AdjacencyList|)
    • Shuffle and Sort Phase
      • Group values passed along the graph edges by destination nodes
    • Reduce phase:

      • PageRank mass contributions from all incoming edges are summed to arrive at the updated PageRank value for each node

  • Complete PageRank

    • Additional complexities:

      1. dangling nodes (Add the average missing mass back to every node)
      2. random jump factor $\alpha \neq 0$ (assign the average mass according to the factor $\alpha\frac{1}{|G|}$)
    • Solution

      • $\alpha$: the probability of random jump ($\alpha \neq 0$)
      • $|G|$: the number of nodes in the graph
      • $m$: the missing PageRank mass (dangling nodes)
  • Convergence: (Stopping Criterion)

    • Iterate until PageRank values don’t change
    • Iterate until PageRank rankings don’t change
    • Fixed number of iterations

Spark

  • Motivations

    • For the MapReduce iterations:

      • The communication within the iteration is the reducer would write the output to HDFS and the mapper would read the data from HDFS, which could be quite expensive
    • Store the data in memory

    • Challenges: fault-tolerant and efficient

  • Resilient Distributed Datasets (RDDs)

    • RDD: a read-only, partitioned collection of records
      Can only be built through coarse-grained deterministic transformations (map, filter, join)