Elamur Research

Faster and Smaller N-Gram Language Models

Paper · 2011 · Adam Pauls and Dan Klein

Summary

A translation program can spend much of its time asking how likely a word is to follow the words already in a candidate translation. An n-gram is a sequence of consecutive words, and an n-gram language model answers these questions using probabilities associated with such sequences. The sequences and their values can fill a large part of the computer’s memory. The program also needs to retrieve them quickly because it repeatedly scores partial translations while searching for a complete one. The paper studies how to lower the cost of storing and querying the same information.

The authors start by giving each stored sequence a compact name. They represent a sequence by its final word and the location of its prefix in a shorter-sequence array. They then arrange the entries so that the final word can be inferred from where an entry is stored. Their most compact implementation goes further by recording differences between nearby entries and encoding common small numbers in fewer bits. Each compressed block starts with a full key, so a search can jump to the block it needs and reconstruct entries from there.

The experiments use a WMT 2010 probability model and the Google Web1T collection of counts. On WMT 2010, the authors’ HASH implementation occupies 7.5G, compared with 26.6G for the hash-based SRILM baseline. With caching, the full decoding times on the 2008 News test set are 943±16s and 938±11s respectively. On Web1T, COMPRESSED keeps the full collection of counts in 10.2G, with a reported average of 23 bits per n-gram. The lossy baseline in that comparison takes 10.5G at the reported setting.

The paper also changes how a decoder asks for scores. A cache remembers the finished score for a query, including any work needed when the requested sequence is missing. It improves lookup times for SRILM as well as for the authors’ implementations. A second technique returns an identifier for the trailing context along with the score. The decoder can carry that identifier into a query for the next word instead of locating the overlapping context again. The experiments show where these choices pay off. Compression saves the most memory but makes an uncached query slower, while the benefit of caching depends on how frequently a decoder can reuse a completed lookup.

Deep dive: Faster and Smaller N-Gram Language Models

Faster and Smaller N-Gram Language Models explains how compact storage and reuse of lookup results cut the memory and time needed to score text. · about 34 minutes to read

The problem and its context

Why translation puts pressure on both memory and lookup time

In statistical machine translation, the decoder searches through candidate translations and uses a target-language probability model to help score them. It can call the probability scorer many times before settling on a translation. A partial translation has a history of preceding words. When the decoder extends or combines partial translations, it needs scores for word sequences that have just become adjacent, including sequences that cross the boundary between the pieces being joined. This makes language scoring part of the search itself. Even a modest cost for retrieving a score can recur throughout the work of decoding a sentence.

The paper describes systems in which decoding a single sentence can generate hundreds of thousands of queries. It also cites Large Language Models in Machine Translation to illustrate the scale of the records that translation systems can use. The largest examples it discusses can reach several hundred billion n-grams. Those observations put separate demands on the same data structure. The total number of sequences governs how much space the structure needs. The decoder’s scoring workload governs how often it accesses that structure, including how frequently it revisits particular entries.

The authors frame the task as a mapping from a word sequence to a value. A collection of observed frequencies maps a sequence to its count. A probability model used during decoding can associate a sequence with a probability and a back-off weight. Back-off lets the scorer use a shorter history when the desired sequence lacks a direct entry. It can require additional lookups, since the scorer may need a weight from one entry and a probability from another. The queries issued by a decoder can therefore be more expensive than their appearance suggests. Asking for one score may entail consulting several records.

A general map offers the right interface, but its representation may spend too much space on the bookkeeping around the data. A typical key can repeat words already stored in other keys. A pointer can take more space than the identifier actually needed to refer to another entry. Values can repeat across many keys. Each cost is easy to overlook when examining an individual record, but it recurs across the collection. The paper treats those recurring costs as design choices and examines which can be removed while preserving access to every stored entry.

What tries and earlier compression already offered

A trie is a tree that shares the beginning of sequences. In an ordinary forward word trie, the path for “the cat ran” and the path for “the cat slept” use the same nodes through “the cat,” then split on the final word. Each node can carry a value for the sequence represented by the path to it. Sharing paths saves duplication of the words in a prefix and lets the table describe a longer sequence in terms of a shorter one. The paper identifies tries or related structures in several toolkits, including SRILM, IRSTLM and MIT LM.

The physical representation of a trie makes a difference. The authors describe an SRILM node with a 32-bit word identifier, a 64-bit pointer to its children’s list and a 32-bit floating-point value. That record alone takes 16 bytes. The children’s list adds storage beyond the node record. A pointer of this kind can identify a location in memory, although the trie only needs a way to find other entries in its own structure. The paper also points out that the straightforward object-based implementation in Java would add another 64 bits of overhead to such a record. For the authors, space therefore depends on both the abstract tree and the way it is laid out in memory.

Whittaker and Raj had described a trie implemented as arrays. In that layout, a node can refer to a contiguous group of children by an offset into an array. An offset identifies an entry in a known collection and can use a narrower field than a general memory pointer. Hsu and Glass described a related design in which an entry refers to its parent. This turns a sequence into its last word and a reference to its beginning. The paper builds from that parent-based convention and asks how much of each key can be inferred from the arrangement of the table or encoded from neighboring keys.

Earlier work had also compressed language data through techniques that accept errors, or through representations whose more compact records can cost more to retrieve. The paper treats those choices as meaningful points of comparison. A lossy structure can admit a key that should be absent or represent a stored value approximately, depending on its design. Lossless storage preserves the records it receives. It still leaves a practical question about how much decoding or scanning a query needs before it can retrieve one of them. The authors’ compression design addresses that question by putting boundaries into the compressed data so lookup can resume from known keys.

The usual orientation of a trie gives another example of how the decoder’s needs can shape the representation. A first-word-and-rest encoding makes suffixes easy to reach, which is convenient when back-off discards the first word. A last-word-and-prefix encoding makes it easy to attach a word to a context that already has an identifier. The authors examine this second orientation because a decoder often works through overlapping windows of target words. Whether a context is principally useful as a fallback within one query or as a starting point for the next query affects which operations are worth making cheap.

The method, step by step

Separate the word sequence from its value

The method begins with a vocabulary. Each word gets an integer identifier, and the unigram array is arranged so the identifier also serves as the word’s offset. A unigram is a sequence consisting of one word. The longer sequences are divided by order, where order is the number of words in the sequence. A bigram belongs to the next array, a trigram to the array after that, and the pattern continues through the largest order being stored. With a separate array at each order, a reference from a longer sequence to its prefix has an unambiguous destination.

Take “the cat ran,” one of the paper’s examples. The system can identify “the” directly from its word identifier. It can then find “the cat” by pairing the identifier for “cat” with the location for “the.” Once it knows the location of “the cat,” it can identify “the cat ran” by pairing that location with “ran.” The same location for “the cat” serves as the prefix of “the cat slept.” At the trigram level, each entry only needs to identify the last word and say which bigram came before it.

Building and querying the context-encoded representation

The steps in order.

Building and querying the context-encoded representationStep 1: Assign identifiers to vocabulary words1. Assign identifiers to vocabulary wordsStep 2: Encode repeated values by rank2. Encode repeated values by rankStep 3: Locate prefixes in the preceding order3. Locate prefixes in the preceding orderStep 4: Group keys by their final word4. Group keys by their final wordStep 5: Choose sorted, hashed, or compressed storage5. Choose sorted, hashed, or compressed storageStep 6: Retrieve the value or resolve back-off6. Retrieve the value or resolve back-offStep 7: Reuse cached scores or returned contexts7. Reuse cached scores or returned contexts

The value attached to a key can be compressed independently of the key. The authors enumerate the distinct values and store an identifier called a rank in each entry. A separate array translates ranks back into the original values. The rank is an array index. Its role is to let many entries point to the same value. The ordering of the values can be chosen to help compression later.

Web1T illustrates why this is useful. Its largest observed count is about 95 billion, which the paper says would need 37 bits if stored directly. The collection has about 770,000 distinct counts, so a rank can be represented in 20 bits. The array of original values takes about 3MB. The paper reports that this saves 17 bits per n-gram and reduces the storage for the count values from around 16GB to about 9GB. The same idea works with probabilities and back-off weights. In the WMT 2010 experiment, a rank identifies a probability and its associated back-off weight together.

The paper denotes the per-value width by v. For Web1T, the relevant fixed-width rank field has v equal to 20 bits. When the authors discuss WMT 2010, they include the per-entry share of the separate value array in their estimate of v. This distinction matters when reading the storage accounts. The rank field is part of every key’s record, while the original numbers are stored once per distinct value. The complete representation has to pay both costs.

Give a context an address that other entries can use

The paper writes the key of a longer sequence as a pair.

(wₙ, c(w₁ⁿ⁻¹))

Here n is the order of the sequence and wᵢ is the word at position i. The notation w₁ⁿ⁻¹ means the sequence from position one through the position before the last word. The function c gives the offset of its argument in the array for that sequence’s order. Thus wₙ supplies the last word and c(w₁ⁿ⁻¹) supplies the address of the prefix. The parentheses and comma denote an ordered pair. Together the components identify the sequence whose value is being stored or requested.

A context offset is useful because the array is a shared point of reference. Different sequences can point to the same prefix without repeating its words. An offset also lets the implementation describe a location in terms of array entries, independently of where the array happens to sit in computer memory. In the paper’s initial encoding, the word and the context offset are packed into a single 64-bit integer. The final word occupies 24 bits and the offset has room for 40 bits. The subsequent representations use tighter fields once the authors change the arrangement of the records.

Finding the key for a query given as a word list is distinct from looking up a key that has already been formed. In the sorted version, the scorer starts with the first word’s identifier and builds up the addresses as it goes. It finds the bigram to discover the address needed to form the trigram key. In turn, the trigram address can become the prefix of a longer query. Once the caller already has the relevant context offset, the scorer can look up the final pair directly in the appropriate order. This difference sets up the later change to the decoder interface.

Use a sorted array or a hash table to find the key

In SORTED, the authors store the entries at each order in key order. A binary search repeatedly narrows the range of possible positions by comparing the requested key with the entry at a midpoint. Given a complete encoded key, this requires one binary search in the array for that order. Given a word list, the search for each successive prefix supplies the offset for the following search. The paper describes lookup as linear in sequence length and logarithmic in the number of stored n-grams. The original fixed-width layout uses 64 bits for the key and v bits for its value rank. For Web1T, the authors report 10.5 bytes per n-gram, or about 37GB, for that layout.

HASH keeps the array addresses available by using an open-addressed hash table. The entries live in the table’s own array. A hash function chooses a starting position and, if an occupied slot contains a different key, linear probing checks successive slots. Each stored entry therefore has an array offset that can serve as a context reference. To insert a longer sequence, the implementation finds its prefix incrementally from the word identifiers so the new entry can record the right address.

Lookup in the hash table can use equality checks on the candidate key. If the query is supplied as words, the system can compare the final word and follow the stored context references to compare the remainder. If the query is already context-encoded, the system can compare the encoded components directly. The paper describes lookup as linear in the length of the sequence and constant with respect to the number of n-grams. Keeping enough slots empty is part of making that practical. The authors use about 40% extra space in their experiments to limit collisions and probing. With explicit 64-bit keys, the Web1T estimate is 15 bytes per n-gram, or about 53 GB.

The open-addressed layout offers a different combination of properties from the sorted array. It uses slack space to keep queries fast, and the authors describe it as supporting efficient insertion and deletion. They connect this property to earlier work on adapting a language model to a stream. The experiments in this paper mainly concern retrieval from populated structures. The insertion procedure still matters to the design because any context reference recorded in a longer sequence must identify the right slot at the preceding order.

Let a range stand for the last word

Writing the final word in every key is redundant once the entries are grouped by that word. In the sorted array, all entries with the same last word are already neighbors. An auxiliary array records the beginning and end of each word’s range at each order. Within that range, an entry only needs the context offset to distinguish it from other sequences with the same last word. The last word itself is available from the range being searched.

Consider the two trigrams “the cat ran” and “the dog ran.” Both belong to the range for “ran.” The prefix addresses distinguish them, since “the cat” and “the dog” have separate bigram entries. Conversely, “the cat slept” can refer to the same prefix as “the cat ran” but belongs to the range for “slept.” Consequently, the representation can use prefixes in more than one final-word group without storing any full word list at the trigram order.

HASH uses the same idea by assigning a contiguous portion of its array to each final word. The hash function distributes entries within the appropriate portion. The sorted version gets a lookup benefit as well as a storage benefit. For a given final word it can begin its binary search at that word’s range, which is narrower than the array for the entire order. The auxiliary range information is indexed by words and orders, while the saving applies to the much larger set of longer sequences. The authors describe the auxiliary cost as follows.

2n

Here n is the number of orders accounted for by the range arrays, and 2 counts a beginning and an end offset for a word’s range at each order. The expression gives the number of range offsets per word. It describes auxiliary storage for navigation, separate from the context offsets kept with the main entries.

On Web1T, a context offset can fit in 32 bits. Moving the final word into the ranges therefore lets the main key field use 32 bits in place of the initial 64 bits. The paper gives 6.5 bytes per n-gram for SORTED and 9.1 bytes per n-gram for HASH in this layout, or about 23GB and 32GB respectively. The rest of the paper uses the implicit-word design where appropriate. The compressed design also exploits the grouping by word, but it represents the keys through differences and stores a full key at the beginning of each block.

Compress differences and frequent ranks

The next change uses the numerical order of neighboring keys. Within a run of entries for the same final word, the context offsets are sorted. Nearby entries frequently have offsets close to one another. Once the decoder for the compressed representation knows the previous offset, a small difference can be enough to reconstruct the next one. For 5-grams the paper reports a median difference of about 50, with 90% of the offset differences smaller than 10,000. Those measurements motivate a code that gives small numbers short representations.

Value ranks can be arranged to take advantage of the same kind of code. Rank encoding already eliminates repeated storage of the original numerical values. For variable-length encoding, the authors also order the original values by how frequently they occur across entries. A often used value receives a low rank, so the code can spend few bits on it wherever it appears. The frequency used to rank a value is the number of entries that carry that value. It is distinct from the count stored as a value in a corpus such as Web1T. A low count can occur as the value of many different sequences.

The authors choose variable-length block coding. Its radix is determined by a parameter.

r = 2ᵏ

The symbol r is the base in which a number will be written. The parameter k is the number of bits allocated to each digit in that base. The base 2 in the power refers to binary representation. The equals sign specifies how to set the radix from k. This choice makes every base-r digit fit in a field of k bits.

To encode an integer m, the implementation first finds how many base-r digits it needs. Let d denote that digit count. The code announces the length by writing the following number of zero bits before a single one bit.

d − 1

Here d is the number of digits that will follow, 1 is the quantity subtracted to obtain the zero count, and the minus sign denotes subtraction. The terminating one tells the reader where the length prefix ends. The reader can then consume the announced number of digits, each using k bits. The payload supplies the digits of m, the integer being represented. In the authors’ example, with k set to 2, the decimal number 7 becomes 010111. The first part announces the digit count, and the remainder gives the digits in the chosen radix.

The choice of k controls how much the code spends on each digit and how many digits a number needs. Different sequences of integers can have different distributions, so the scheme permits different settings for ranks and differences. In the figure that illustrates the encoding, word differences use k set to 1, while context differences and ranks use k set to 2. The reported compressed Web1T configuration uses k set to 6 for offset differences and 5 for value ranks. The figure illustrates the format, and the reported settings specify the experiment.

Make the compressed stream searchable

A single stream of differences would hide exactly the information a binary search needs. An arbitrary bit position could be inside a code. Even at the start of a code, the meaning of a difference depends on the key that precedes it. One way to recover an entry would be to start at the beginning and reconstruct the earlier keys in order. For an array meant to serve frequent random lookups, that would make the saving in storage expensive to use.

The authors divide the sorted data into blocks of 128 bytes. Every block begins with an explicit 64-bit key, the key for its first entry. The header also stores three values: a 32-bit offset locating that entry in the uncompressed array, the block’s compressed data length in bits, and a variable-length encoding of the first entry’s rank. The rest of the block holds as many subsequent entries as fit. When the writer begins another block, it writes a new full key and starts the process again.

The uncompressed offset preserves the logical address of a sequence after its physical location has changed. A context reference from a higher-order key refers to the entry by its array offset, even though there may no longer be fixed-width records at that order. The block’s first logical offset provides a starting point for recovering other positions as entries are read. The compressed bit count identifies the useful data in the block. Together these fields connect the address space used by the trie with the storage format used by the compressed array.

For entries after the header key, the encoding treats word differences and context differences as separate fields. If the entire block has the same final word, a bit in the header says that the word differences are absent. The full key already supplies that word. This makes word grouping useful even after the fixed-width context array has been replaced by a compressed stream. The benefit depends on the runs of entries that fall within a block, so the explicit header keeps the format usable when a block includes more than one final word.

A query first uses binary search over block headers. Their physical positions are known because each block is 128 bytes long. The header keys identify which block may hold the requested key. The implementation then reads that block in order, reconstructing keys and their values until it can resolve the query. The cost of starting at the beginning of a compressed stream is thus confined to a block. There is a tradeoff between the space occupied by restart information and the amount of sequential work after a restart. The reported COMPRESSED implementation uses this fixed-size arrangement as its operating point.

Keep completed scores in a direct-mapped cache

The authors look at what the decoder actually requests. In an exploratory trace, the Joshua decoder issued 31 million language queries on a 100 sentence test set, of which about 1 million were unique. That repetition creates a chance to reuse work. The cache stores the whole score returned to the caller. In particular, it can retain a score arrived at through back-off even when the original query has no matching entry in the main data structure.

The cache has a fixed array of key and value pairs. The paper specifies its size using the expression below.

2ᵇ − 1

Here b is an integer setting that also gives the hash width in bits, and the authors use 24 for it. The base 2 reflects the binary hash width. The subtraction of 1 is part of the paper’s stated size expression. A hash assigns every query key a single cache address.

The scorer computes the hash and checks the key at that address. If the stored key agrees with the request, it returns the cached score. If the slot is empty or holds a different key, the scorer obtains the score from the underlying structure and writes the new key and score to the slot. A collision can evict a previously cached result. The identity check ensures that a collision triggers a miss rather than returning the other key’s score.

This direct-mapped layout makes a hit cheap. It requires one hash evaluation, one read to obtain the stored key, and an equality comparison. In the underlying hash table, a lookup can need multiple reads and comparisons to resolve collisions. A score obtained through back-off can require more lookups still. The cache can avoid both kinds of work on a hit. By giving each key only one place to go, the authors also avoid putting a probing loop in front of a main table that may already probe for its own records.

Return the context the decoder will need next

Repetition is only one pattern. A decoder also scores consecutive windows that overlap, even when the full keys differ. The paper illustrates the effect with a context ending in “the cat” and an extension containing “fell down.” The sequence “the cat fell” is scored before “cat fell down.” The words “cat fell” are the suffix of the first query and the prefix of the second. Passing both queries as complete word lists makes the scorer recover that shared context when it receives the second query.

The authors augment the values so an entry can supply the offset of the suffix needed for the next query. In their notation, that suffix address is written as follows.

c(w₂ⁿ)

Here n is the order of the query, w₂ⁿ denotes its words from the second position through the last, and c returns the array offset for that sequence. Dropping the first word gives the context that remains when the scoring window advances. The example makes the direction of the transfer concrete. After scoring “the cat fell,” the interface can return the offset for “cat fell.” The decoder passes that offset with “down” to form the next key.

A partial translation for a scorer of order n can carry up to n − 1 words of history. In the paper’s back-off setup, the identifier returned for a context can designate a shorter suffix if the longer history is missing. The paper writes the address of the longest stored suffix of a history as follows.

c(ŵ₁ⁿ⁻¹)

The symbol ŵ₁ⁿ⁻¹ denotes the longest stored suffix of the candidate history w₁ⁿ⁻¹. The hat distinguishes the retained suffix from the original history. The superscript n − 1 identifies the extent of the candidate history before this shortening, and c gives the offset of the suffix actually retained. Through back-off, the scorer can compute the same continuation score from that suffix when the fuller context is absent.

That property gives the decoder a way to recognize equivalent scoring states. If distinct histories lead to the same retained context, subsequent language queries can start from the same identifier. The decoder can then represent those contexts by the same state. The paper credits earlier work for exploiting this equivalence explicitly. Here it follows from the return value of the scoring interface. The change has a space cost because the records need suffix offsets, and its measured effect on query time is reported separately from the ordinary HASH representation.

Populate the structures from probabilities or counts

On the probability side, the authors use the English portions of the French–English corpora made available for WMT 2010. The English training material contains about 2 billion tokens. They apply the accompanying tokenizer.perl script for tokenization, the step that divides text into the units the scorer treats as words. They then train a 5-gram Kneser-Ney model with SRILM. The resulting entries contain probabilities and back-off weights. The storage formats encode those entries and can be compared using a common trained probability model.

On the count side, Google Web1T already supplies word sequences and frequencies. It covers n-gram orders one through five, based on more than a trillion tokens of English text. The paper uses these entries without additional preprocessing. The work in this setting is to organize and encode the existing counts. It places pressure on the number of keys the implementation can hold and shows how often repeated counts behave under rank encoding. The authors implement their toolkit in Java and make it compatible with the standard ARPA file formats used for language data.

Experiments and results

Two datasets serve different measurements

The WMT 2010 probability model contains 676,875,055 n-grams across the orders used by the scorer. Its vocabulary has 4,366,395 unigrams, and the largest order contributes 269,614,330 5-grams. This is the model used for both storage comparisons and the timing tests. Its values are probability and back-off pairs, and the paper reports about 80 million distinct pairs. The estimated per-entry value cost is approximately 36 bits in the discussion of that dataset. This includes each entry’s rank and an amortized share of the distinct pairs, which hold two 32-bit floating-point numbers each.

The Web1T collection contains 3,795,790,711 n-grams, including 13,588,391 unigrams and 1,176,470,663 5-grams. The associated values are counts. The paper uses this setting to compare compression at the scale of the full collection. The two experiments consequently differ in the number of entries, vocabulary size and kind of value being stored. Bytes per n-gram summarize the cost of a particular representation on each dataset. The figure for one dataset cannot be read as a fixed field width that will apply to the other.

Memory for the WMT 2010 probability model

The comparison includes a hash-based and a sorted-array implementation from SRILM, called SRILM-H and SRILM-S. It also includes the Tightly-Packed Trie, or TPT, from earlier work by Germann and colleagues. The authors could use SRILM for their comparison. For TPT they relied on a published per-entry figure from a model of comparable size and projected the overall storage. Those conditions matter when reading the reported totals alongside the directly measured values.

Storage per n-gram on the WMT 2010 probability model

COMPRESSED has the lowest reported storage per entry, with TPT represented by a figure from a comparable model.

Storage per n-gram on the WMT 2010 probability modelSRILM-H: 42.2SRILM-H42.2SRILM-S: 33.5SRILM-S33.5HASH: 11.6HASH11.6SORTED: 8.5SORTED8.5TPT, published estimate: 7.5TPT, published estimate7.5COMPRESSED (this paper): 5.9COMPRESSED (this paper)5.9
The numbers
System or settingbytes per n-gram
SRILM-H42.2
SRILM-S33.5
HASH11.6
SORTED8.5
TPT, published estimate7.5
COMPRESSED (this paper)5.9

In total, HASH uses 7.5G on WMT 2010 and SRILM-H uses 26.6G. SORTED uses 5.5G, compared with 21.1G for SRILM-S. The authors describe their hash and sorted implementations as using about 25% of the storage of the respective SRILM variants. COMPRESSED occupies 3.7G, while the projection for TPT is 4.7G. The reported comparison places COMPRESSED ahead on storage, with the TPT projection carrying the uncertainty of transferring a published measurement to a different model.

The authors break down the storage of their own implementations. On WMT 2010, HASH uses 5.6 bytes per key and 6.0 bytes per value, and SORTED uses 4.0 bytes per key and 4.5 bytes per value. COMPRESSED uses 2.1 bytes per key and 3.8 bytes per value. This breakdown shows where the compressed representation saves space on this probability model. It reduces the representation of the keys and also reduces the cost of encoding the value ranks. The reported value costs still reflect the need to store the actual probability and back-off pairs for recovery.

Compression of the Web1T count collection

On Web1T, the authors compare COMPRESSED with gzip applied to the text count files and with the Tiered Minimal Perfect Hash method, abbreviated T-MPHR. Gzip gives a reference for the size of compressed text. The COMPRESSED measurement describes a searchable representation of the counts, and the comparison with gzip is a comparison of space. T-MPHR provides a different point of reference. Its compressed lookup representation can give false positives, and the amount of key information it stores affects that error rate.

Storage per n-gram on the Web1T count collection

COMPRESSED uses less space per entry than either reported baseline while preserving the stored counts.

Storage per n-gram on the Web1T count collectionGzip count files: 7.0Gzip count files7.0T-MPHR, lossy setting: 3.0T-MPHR, lossy setting3.0COMPRESSED (this paper): 2.9COMPRESSED (this paper)2.9
The numbers
System or settingbytes per n-gram
Gzip count files7.0
T-MPHR, lossy setting3.0
COMPRESSED (this paper)2.9

The reported totals are 24.7G for gzip, 10.5G for T-MPHR and 10.2G for COMPRESSED. The authors also give the compressed Web1T result as 23 bits per n-gram. In their storage breakdown, keys use 1.3 bytes per n-gram and values use 1.6 bytes per n-gram. The COMPRESSED result preserves the supplied sequences and counts. The reported T-MPHR result uses 12-bit hash codes for the keys, with a false positive rate of about 0.02%. Here a false positive means the representation can report a match for a key that should be absent. The authors note that accepting more errors can reduce T-MPHR’s space requirement, so the comparison concerns this particular setting.

Lookup time on a recorded decoder workload

To measure raw timing, the authors collect queries while Joshua uses the WMT 2010 probability model to decode the first 100 sentences in the French portion of the 2008 News test set. The trace contains about 30 million queries. They replay the requests in order and measure the time for language scoring in isolation, with and without the cache. The measurement excludes file input and output. Replaying the requests in order matters because it preserves the sequence of cache fills and revisits that the decoder produced.

The paper reports averages over 3 runs on the same machine. An Amazon EC2 instance of the High-Memory Quadruple Extra Large type runs the benchmark and has an Intel Xeon X5550 processor at 2.67GHz and 8 MB of cache. The SRILM comparison goes through the Java Native Interface, or JNI, to call SRILM from Java. This is part of the measured cost of using it from Joshua. The paper reports the timings with that cost included.

Uncached query latency on the WMT 2010 model with the 2008 News trace

HASH + SCROLL has the lowest mean latency, while COMPRESSED spends the most time serving an uncached query.

Uncached query latency on the WMT 2010 model with the 2008 News traceCOMPRESSED: 9264COMPRESSED9264SORTED: 1405SORTED1405HASH: 495HASH495SRILM-H: 428SRILM-H428HASH + SCROLL (this paper): 323HASH + SCROLL (this paper)323
The numbers
System or settingns per query
COMPRESSED9264
SORTED1405
HASH495
SRILM-H428
HASH + SCROLL (this paper)323

With the cache enabled, the reported times per query are 565±7ns for COMPRESSED, 243±4ns for SORTED and 179±6ns for HASH. SRILM-H takes 159±4ns, and HASH + SCROLL takes 139±6ns. For comparison, SRILM-H without the cache takes 428±5ns. The paper observes that cached COMPRESSED approaches the time of uncached SRILM-H on this trace. Under the same cached condition SRILM-H retains a substantial latency advantage over COMPRESSED. Looking at both comparisons clarifies how much credit belongs to the representation and how much belongs to the reuse of scores.

HASH + SCROLL has its own storage cost. Its reported size is 10.5G, while ordinary HASH occupies 7.5G. The extra storage holds suffix offsets with the values. The raw benchmark issues context-encoded requests in that configuration, so it measures the shorter lookup path that becomes available to a caller using the new interface. With no cache, the reported times are 323±5ns for HASH + SCROLL and 495±10ns for HASH. Under caching, the time ranking is the same, while the average time of each includes retrieval of scores already in the cache.

Time to finish decoding

The full decoding experiment includes every sentence in the 2008 News test set, 2051 in total. The authors modify Joshua so it can use their implementations during decoding and measure how long it takes to complete the test set. This measurement includes decoder work beyond the isolated scoring calls. The values are again averaged across 3 runs on the same machine.

Without caching, SRILM-H finishes in 1120±26s and HASH in 1146±8s. With caching, the times are 938±11s for SRILM-H and 943±16s for HASH. These measurements are the basis for the authors’ claim that HASH gives comparable overall decoding speed using about 25% of the memory. On the narrower per-query measurement both implementations can answer more quickly when cached. On the complete decoder run, their times are close under either cache condition.

COMPRESSED takes 9880±82s without caching and 1547±7s with it. The paper describes the full-decoding improvement for COMPRESSED as a factor of 6 and the reduction in time for the fastest configurations as about 20%. The compressed representation thus presents a different choice in the integrated run. Caching makes its low memory footprint usable at much lower latency on this workload, but it still takes longer to finish than the cached hash-based alternatives. The space figures and the decoding times together describe the operating points the paper actually evaluates.

What the ablations show

Which savings come from the layout

The comparisons include controlled changes to the representation and lookup procedure, alongside comparisons of complete implementations. The transition from explicit final words to word ranges isolates a particularly direct saving. The same word information is organized by range and stored outside the main array. The cost of keeping it there depends on the vocabulary and the number of orders. The saving is realized each time a main entry can omit the word field. The authors’ Web1T accounts show the effect for both SORTED and HASH, even though the two structures pay different costs for looking up an entry.

The sorted case also shows why compression and speed need attention at the level of individual changes. Giving each word a range shrinks the records and narrows the part of the array a query searches. Encoding the offsets as differences shrinks the records further, but it introduces the work of reconstructing entries from a block header. The raw timing comparison shows these complete designs at their measured operating points. It combines the cost of the encoding with the cost of the search strategy specified for that encoding. There is no separate timing figure in which only the difference code is varied while everything else stays fixed.

The authors compare several codes for the integer streams. They report that their variable-length block code performed better in their trials than Golomb coding and Elias gamma and delta coding. A zeta code, intended to suit certain power-law distributions, provided no gain in their tests and added complexity. Huffman coding performed slightly better on compression, but at a higher computational cost. The paper provides a qualitative account of these comparisons. It gives the chosen settings for COMPRESSED and a numerical description of the offset differences, while leaving the code-by-code sizes and timing costs unspecified.

That evidence explains the choice of a simple code with adjustable digit width. The nearby offsets and frequent low ranks give the encoder many small integers. A more elaborate code may save more bits, while the decoder has to recover these integers during a scan. The block format bounds the region involved in that scan. The paper reports results for blocks of 128 bytes, so the reader can evaluate the chosen configuration. It gives no numerical block-size sweep from which to infer an optimum.

What changes when the cache is switched on

The cache comparison holds the recorded query workload and the underlying implementation fixed while changing whether the completed score can be reused. This makes it possible to attribute the timing change to caching on that workload. COMPRESSED benefits strongly because its misses are expensive. An uncached query can involve decoding a compressed block, and a full back-off score may require more than one lookup. On a cache hit, the caller receives that score directly. The large change in COMPRESSED’s mean query time is consistent with a cache avoiding both sources of work.

HASH’s improvement shows that repeated queries matter even when retrieving an individual record is already relatively cheap. Its raw time changes from 495±10ns without caching to 179±6ns with caching. SRILM-H also benefits, so the result is not specific to the trie encoding. What the cache needs is a query that recurs and a scorer whose work can be bypassed when it does. This includes scores for missing full sequences when the back-off computation is reusable.

There is also a comparison with a cache based on linear probing. The authors report about 40% improvement for that cache, attributing much of the gain to reuse of completed back-off scores. They describe the direct-mapped cache as improving query speed by about 300% even for HASH. These are the paper’s descriptions of the speed changes. The raw query times give the corresponding latencies for the direct-mapped configuration. The two cache designs can both save work on a hit, but the direct-mapped cache has a shorter lookup path because it checks a single location.

The full decoder experiment shows the effect of that intervention on a broader workload. Faster query handling changes only part of the time a decoder needs to complete a run. This is visible for HASH and SRILM-H, where the authors report a smaller relative improvement in full decoding than in raw scoring. COMPRESSED starts from much longer uncached lookups and shows much more change in total decoding time. The experiment supports measuring both the operation being optimized and the process that calls it.

What changes when the decoder passes an offset

The HASH and HASH + SCROLL comparison asks whether an overlapping context is cheaper to identify if the caller carries its address forward. With caching disabled, HASH + SCROLL takes 323±5ns per query, compared with 495±10ns for HASH. The comparison changes both the format of the query and the data available in the entry. The extra suffix field makes it possible to reuse an address, and the decoder must actually send a context-encoded query to benefit. The result therefore measures the combination of storage and interface changes.

The authors also discuss trying a reversed trie, which makes suffixes accessible for ordinary back-off. They describe the gain from reversing the orientation and improving Back-off queries as modest. The paper’s reason for keeping the last-word orientation is the opportunity to carry the overlapping context from one query to the next. This focuses on work repeated across adjacent requests, whereas reversing the trie can reduce work inside a single request. The paper gives a timed comparison for the scrolling interface and a qualitative description of the reversed-trie trial.

The paper explains how the returned offset can also let a decoder identify equivalent language states. That is a property of the representation and the back-off rule. The timing comparison reports the cost of servicing context-encoded queries. It does not give a separate count of how many states the decoder merges or a full decoding time for HASH + SCROLL. The evidence for faster lookup and the argument for a smaller search state space consequently answer different questions.

Limitations

Limits the authors state

The authors qualify their SRILM timing comparison because it crosses an implementation boundary. Java calls into SRILM through JNI, which adds overhead. They report that calling SRILM natively made it about 200 ns/query faster. They also point out that their own implementation in Java has a cost compared with implementing it in C++. The main tables use the JNI-inclusive times because the experiment concerns what a decoder such as Joshua pays. Those figures establish the comparison for that integration. Native lookup costs could lead to a different ranking.

The paper flags a separate qualification for TPT. Because the implementation was unavailable for their direct test, the authors use a published storage figure from a model of similar size. Their projected total is explicitly rough. The comparison is informative about the scale of the reported storage requirements, but a head-to-head run on the same WMT 2010 records would be needed to establish the precise difference between the two compressed representations.

The T-MPHR comparison is conditional on the selected false positive setting. The authors state that the lossy scheme can use less space by accepting more errors. They also note that the earlier work reports additional value savings through quantization and that the same kind of quantization could be applied to their storage scheme. Consequently, the Web1T figures compare the options at the reported settings. They support the result that COMPRESSED preserves the full collection in less space than T-MPHR under that comparison, without establishing a bound for every lossy operating point.

The storage analysis assumes a 64-bit architecture. The authors explain that 32-bit address space is insufficient for the large examples they consider. They also say that an offset field can grow for corpora whose entries cannot be indexed using the width chosen for Web1T. For collections with wider context references or different distributions of ranks and offsets, the bit budget would need to be reevaluated. The examples show what fits at the observed dataset sizes and settings.

Limits visible in the experiments

The timing evidence comes from one decoder setup and hardware configuration. For the raw measurements, queries are replayed for the first 100 sentences in the 2008 French News test set, while the full decoding measurements cover all 2051 sentences in the same set. The order and recurrence of queries in Joshua are central to the choice of cache. A decoder that asks for a different set of sequences, revisits them at different intervals, or spends more of its time on other operations could see a different improvement. The paper does not compare those workload conditions or report a sweep of cache sizes.

The table of isolated timings measures lookup after the language data are available and leaves out file input and output. The full decoding results show the effect on the decoder in the reported experimental setup. The experiments do not provide a corresponding comparison of training time, construction time, or the time needed to load each representation from storage. The gzip result likewise supplies a space comparison on count files, with no corresponding timed random-lookup condition. Each metric describes a specific use of the representation.

The evidence for scrolling has a narrower scope than the evidence for caching. Raw context-encoded queries have measured timings, and the equivalence of back-off states has an explanation. The full decoding table reports COMPRESSED, SRILM-H and HASH. It supplies neither a full decoding time for HASH + SCROLL nor an isolated measure of the search reduction from state equivalence. A reader can account for the measured memory cost and raw query benefit of suffix offsets while leaving their integrated effect open.

The experiments are concerned with preserving scores and retrieving them economically. The paper reports space and time, with no translation quality score. Its lossless claim concerns recovering the keys and values encoded by the representation. It does not provide a test of whether fitting additional training data into the available memory improves translations. Web1T, for its part, is evaluated as a collection of sequences and counts. The decoder results use the WMT 2010 probability model, so they cannot be assigned to the compressed Web1T collection on the basis of its storage result.

Finally, the mean timings summarize the tested workload. An individual cache miss can still require a block scan or a series of back-off lookups. The paper does not report distributions for individual query times or attribute misses to particular patterns of keys and cache collisions. Its timings establish the average cost across the trace and the overall time to decode the test set. Those measurements leave the behavior of unusually expensive individual queries unresolved.

What came after

The citing works span lexical simplification, abbreviated text communication and a survey of hallucination in large language models. Their citations establish that the paper appears in those settings. The nature of each connection can be described only as far as the work’s title and citation establish it.

Simplifying Lexical Simplification: Do We Need Simplified Corpora? asks whether lexical simplification needs corpora of simplified text. That question concerns the material a system uses when working with simpler word choices. Pauls and Klein address a different part of a language system, the cost of storing and retrieving information about word sequences. The citation places their storage and lookup work in the context of lexical simplification. It leaves open which representation, if any, the later work puts to use and whether it measures a performance effect from that choice.

Accelerating Text Communication with Abbreviated Sentences concerns speeding up communication through abbreviated sentences. Here the context is communication rather than translation. The citation connects that application to an earlier study of efficient word-sequence scoring, but it does not specify whether the connection involves the compact tries, the cache, the scoring interface, or a more general reference to n-gram lookup.

Siren’s Song in the AI Ocean is a survey of hallucination in large language models. Its citation gives the paper a place in a later discussion with a different central question. Pauls and Klein measure the cost of retrieving stored information during decoding. The survey’s subject is hallucination, and the citation alone does not show that it applies any of the storage or retrieval techniques. The documented connection is bibliographic, with the paper’s contribution remaining the measured space and time costs of its n-gram representations.

Cite

Cite as Adam Pauls and Dan Klein. 2011. Faster and Smaller N-Gram Language Models. Proceedings of the 49th Annual Meeting of the Association for Computational Linguistics: Human Language Technologies.

The paper itself, not this page. BibTeX from the library's record of the work.

@inproceedings{pauls2011faster,
  title = {{Faster and Smaller N-Gram Language Models}},
  author = {Adam Pauls and Dan Klein},
  booktitle = {Proceedings of the 49th Annual Meeting of the Association for Computational Linguistics: Human Language Technologies},
  year = {2011},
  url = {https://aclanthology.org/P11-1027/}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/pauls-2011-faster-smaller-n-gram-language/