Algorithm Search⌘K

Algorithmintro

Penn Treebank tokenization

Also called PTB tokenizer.

Rule-based English word tokenization by regular expressions that splits off punctuation and clitics such as n't and 's, as in the Penn Treebank.

Time
O(n) worst
Space
O(n) extra
Where
n = the number of characters of the input line
Properties
deterministicexactofflineiterative
Origin
Robert MacIntyre, Mitchell P. Marcus, Beatrice Santorini, Mary Ann Marcinkiewicz, 1995

Penn Treebank tokenization splits one English sentence into word tokens by an ordered list of regular expression substitutions, the convention used by the Penn Treebank. It separates punctuation, splits clitics such as n't, 's and 're from their words ("can't" becomes "ca" and "n't", "John's" becomes "John" and "'s"), and writes double quotes as an open quote `` and a close quote ''. It is one rule set for the tokenization problem, which has no single right answer: the problem page compares it with other conventions and with subword tokenization. The original tool is a sed script by Robert MacIntyre, and it expects one sentence per line, so it must run after sentence boundary detection.

In plain words

The program reads one sentence and puts spaces into it, then cuts it at the spaces. The rules run one after another, and each rule works on the whole sentence.

First it marks quotes that open a quotation. Then it puts spaces around commas, colons, dollar signs, brackets, question marks and the like, and before the period at the end of the sentence. Then it marks the remaining quotes as closing quotes. Last, it cuts off short endings such as "n't", "'s" and "'ll", and splits a few joined words such as "cannot" and "gonna" into two parts.

The order matters. A later rule sees the spaces that earlier rules added, and some rules need them.

The problem

The input is one line xx of English text that holds one sentence. The output is a list of tokens, the fields of xx after the substitutions, split at runs of white space. The convention says what a token is, so the specification is the rule list itself. The tokens are not given with character offsets, because the open and close quotes replace the double quote character.

The algorithm

Each line applies one group of rules of the sed script to the whole string, from left to right, and replaces every non-overlapping match.

  1. PTB-TOKENIZE(x) ▷ x is one sentence on one line, |x| = n
  2. 1replace a " at the start of x by `` and a space
  3. 2replace each " after a space or one of ( [ { < by a space, ``, and a space
  4. 3put spaces around each ... and around each of , ; : @ # $ % &
  5. 4split the period at the end of x from the character before it, unless that is a period; closing ) ] } > " ' may follow it
  6. 5put spaces around each ? and !, each bracket ( ) [ ] { } < >, and each --
  7. 6add one space at the start and one at the end of x
  8. 7replace each remaining " by a space, '', and a space
  9. 8split off a single ' after a word, and 's 'm 'd 'll 're 've n't (and 'S 'M 'D 'LL 'RE 'VE N'T) before a space
  10. 9split cannot, d'ye, gimme, gonna, gotta, lemme, more'n, 'tis, 'twas and wanna into two tokens
  11. 10return the fields of x between runs of spaces

Line L4 is the only rule for periods. It splits off the last period only, so "Mr." and "3.50" inside the sentence stay whole. Line L6 gives every word a space after it, which the clitic rules of line L8 need, because each of them matches the clitic and the space after it. Lines L2 and L7 decide between an open and a close quote by position only: a double quote at the start or after a space or an opening bracket opens a quotation, and every other one closes it. In the implementation, each line is a list of compiled patterns, and the sed replacement & (the whole match) becomes \g<0>.

Example

Take xx = He said, "I can't pay $3.50 for John's book." The table shows the string after each line that changes it. Runs of spaces are shown as they are.

after string
L1 unchanged, because xx does not start with a double quote
L2 He said, `` I can't pay $3.50 for John's book."
L3 He said , `` I can't pay $ 3.50 for John's book."
L4 He said , `` I can't pay $ 3.50 for John's book ."
L5 unchanged
L6 the same with one more space at each end
L7 He said , `` I can't pay $ 3.50 for John's book . ''
L8 He said , `` I ca n't pay $ 3.50 for John 's book . ''
L9 unchanged

Line L10 gives 16 tokens: He, said, ,, ``, I, ca, n't, pay, $, 3.50, for, John, 's, book, ., ''. The period of 3.50 stays inside its token, because line L4 looks only at the end of the line. In line L4 the period is followed by a double quote, which the closing-mark part of the pattern allows. In line L8 the rule for n't matches "n't " in "can't ", so the word becomes "ca n't"; the rule for 's matches "'s " in "John's ".

Three more cases from the tests: "Mr. Smith gonna stay." gives Mr., Smith, gon, na, stay, .; "'Tis cannot." gives 'T, is, can, not, .; and "It's the students' book." gives It, 's, the, students, ', book, ..

Correctness

A convention has no external truth to check, so the proof in proofs/correctness.md shows three things. First, each line of the pseudocode applies the same substitutions as the sed script in the same order, so the function computes the tokens of the script. Second, every rule writes back the characters it matched, in order, and only adds spaces, except that double quotes become open or close quotes and line L4 drops trailing white space. So the tokens, joined and with the quote tokens written back as double quotes, give the input without its white space. Third, each of the 18 characters ,;:@#$%&?!()[]{}<> ends up as a token by itself, because no rule removes a space next to it. The tests also compare the implementation with the sed script itself on 500 random lines, when a sed program is present.

Proof: The Penn Treebank rules only insert spaces and rewrite double quotes, and they isolate each punctuation markfull

A rule set has no "right answer" to prove against: the Penn Treebank convention is defined by its rules. What can be proved is that the procedure applies the rules of the sed script, and that its output has the properties that the convention promises. Let xx be one line with no line break. A space below is the character U+0020 or a tab. For a string yy, let σ(y)\sigma(y) be yy with all spaces removed. Let SS be the set of the 18 characters in ,;:@#$%&?!()[]{}<>. The open quote token is `` (two backquotes) and the close quote token is '' (two apostrophes).

Lemma 1 (the translation). Each line of the pseudocode applies the same substitutions as the matching lines of the sed script, in the same order, so the Python function returns the token list of the script.

Proof. The sed script uses basic regular expressions in the form s=pattern=replacement=g. Line L1 is the first rule, which replaces a double quote at the start by the open quote and a space. Line L2 is \([ ([{<]\)", which is the Python pattern ([ (\[{<])" with the group \1. Line L3 is the rule for ... and the rule for the class [,;:@#$%&], where the sed replacement & (the whole match) is \g<0> in Python. Line L4 is the final period rule \([^.]\)\([.]\)\([])}>"']*\)[ <tab>]*$. A bracket expression that starts with ] holds that character, so the Python class is [\])}>"']. Line L5 is [?!], then [][(){}<>] (a class that holds both square brackets), then --. Line L6 is s=$= = and s=^= =. Line L7 replaces each remaining double quote by a space, the close quote and a space. Line L8 is the rule for a closing single quote, the rule for 's, 'm and 'd in both cases, and the eight rules for 'll, 're, 've, n't, 'LL, 'RE, 'VE and N'T. Line L9 is the ten rules for cannot, d'ye, gimme, gonna, gotta, lemme, more'n, 'tis, 'twas and wanna. The last two sed rules squeeze runs of spaces and delete leading spaces; splitting at runs of white space in line L10 gives the same list of fields. Python re.sub replaces the leftmost non-overlapping matches from left to right, which is the meaning of the g flag in sed. Without a line break in the input, ^ and $ mean the two ends of the string in both. □\square

Lemma 2 (only spaces are added). Let y0=xy_0 = x, and let yty_t be the string after the tt-th substitution. Then σ(yt)\sigma(y_t) is σ(x)\sigma(x) with some of its double quotes replaced, each by the open quote or by the close quote, and after line L7 every double quote of xx is replaced.

Proof. By induction on tt. Inspect each replacement. Every rule writes back the characters it matched, in the same order, with spaces added, except in three cases. Lines L1 and L2 write the open quote in place of a matched double quote. Line L7 writes the close quote in place of each remaining double quote. The final period rule of line L4 drops the spaces and tabs that it matched at the end of the line, which does not change σ\sigma. The rules of line L9 add one space inside the matched word, for example "can not" for "cannot" and "'T is" for "'Tis". After line L7 no double quote is left. □\square

Lemma 3 (punctuation stands alone). Each character of SS in xx ends up as a token of length 1.

Proof. Line L3 puts a space on both sides of each of the eight characters of ,;:@#$%&, and line L5 does the same for ?, ! and the eight brackets. A rule that removes spaces would be needed to join such a character to a neighbour. The only rule that removes spaces is the final period rule of line L4, and it removes only spaces at the end of the line that follow a period or one of the closing marks )]}>"'. None of these is one of the eight characters of line L3, and the brackets get their spaces from line L5, which runs later. So in the final string each character of SS has a space or an end of the string on both sides, and line L10 makes it a token. □\square

Lemma 4 (clitics). If the string before line L8 has a word that ends in n't, 's, 'm, 'd, 'll, 're or 've (in lower case, or in the upper case forms of the script) and is followed by a space, then the clitic is a separate token at the end.

Proof. Line L6 makes sure that the last word of the string is followed by a space. The rule for the clitic matches it at the end of the word, because the pattern needs the space after it, and the replacement puts a space in front of it. By Lemma 2, no later rule removes a space. □\square

Theorem. PTB-TOKENIZE(x)(x) stops after a fixed number of passes over the string, and returns the tokens of the sed script of MacIntyre for the line xx. If xx contains neither two backquotes nor two apostrophes in a row, then the concatenation of the tokens, with each open and close quote token written as a double quote, is σ(x)\sigma(x), and each character of SS is a token by itself.

Proof. There are 29 substitutions and two padding steps, each a single left to right pass, so the procedure stops. The first claim is Lemma 1. Line L10 splits the final string yy at runs of spaces, so the concatenation of the tokens is σ(y)\sigma(y). By Lemma 2, σ(y)\sigma(y) is σ(x)\sigma(x) with each double quote replaced by an open or a close quote. By the hypothesis on xx, a token is an open or a close quote only if it came from a double quote, so writing these tokens back as double quotes gives σ(x)\sigma(x). The last claim is Lemma 3. ■\blacksquare

Remark. The theorem does not say that the tokens are linguistically right. The script splits off only a period at the end of the line. So "it. You" stays "it." and "You" when the input holds two sentences, and a final abbreviation loses its period: "the U.S." gives "U.S" and ".". These follow from line L4. They are part of the convention, not errors in the proof.

Complexity

  • Time. Each of the 29 substitutions is one left to right pass of a regular expression with a bounded pattern, so it takes O(m)O(m) time on a string of length mm. A rule at most triples the length of the string, and the number of rules is fixed, so the total time is O(n)O(n) for an input of nn characters. In practice the string grows by a few spaces per token.
  • Space. O(n)O(n) for the current string and the token list.

Properties

  • Only spaces are added. Apart from the quote marks, the tokens spell the input exactly, so a detokenizer can undo most of the changes.
  • Position decides the quote type. A double quote right after a word, as in said", always closes, and one after a space always opens.
  • One sentence at a time. A period inside the line is never split off, so the input must already be split into sentences.
  • Case-sensitive clitic rules. The script lists the lower case and the all upper case forms, so "WON'T" gives WO and N'T, but a mixed form such as "Won'T" is not split.
  • No offsets. The output has no character offsets, because quotes are rewritten.

Variants and improvements

  • Bracket symbols. The treebank files write brackets as -LRB-, -RRB-, -LSB-, -RSB-, -LCB- and -RCB-. The sed script has these rules as comments, for use with a tagger, and the NLTK port has the option convert_parentheses.
  • The NLTK port. NLTK's TreebankWordTokenizer is a port of the script with a few extra rules, for example for more contractions and for the separation of single quotes. Its output differs from the script on some inputs, so say which one you use.
  • Lexer-based tokenizers. The Stanford PTBTokenizer is a finite-state lexer that follows the same conventions on running text with several sentences, and it handles abbreviations with a word list. A lexer reads the text once with the maximal munch rule, instead of many passes.
  • Other conventions. The Moses tokenizer for machine translation, the Unicode word boundary rules and the pre-tokenizers of subword models use other conventions. Penn Treebank tokens are the input of most English treebank parsers and taggers trained on the WSJ section.

When to use it

Use it when you train or evaluate on Penn Treebank data, or on any English corpus that follows its conventions, because a parser or part-of-speech tagger trained on these tokens expects "ca n't" and not "can't". Measurements such as parsing F1 or perplexity are comparable only between systems that use the same tokens. For other languages, for text with many sentences per line, or for a neural model with its own vocabulary, use a tokenizer made for that case.

Pitfalls

  • Several sentences on one line. Line L4 splits only the last period of the line. "I like it. You do too." gives it. with the period attached. Run sentence boundary detection first.
  • A final abbreviation. Line L4 cannot tell an abbreviation from the end of a sentence, so "met in the U.S." gives U.S and a period. The treebank solves this case in the data, not with this rule.
  • Rules out of order. If line L6 runs after line L8, the last word of the line has no space after it, and a clitic such as 's at the end of the line is not split. Keep the order of the script.
  • A wrong open quote. Line L2 opens a quotation only after a space or an opening bracket. In "x="y"", the first quote after "=" is taken as a close quote by line L7. Fix the input or accept the convention.
  • Non-ASCII text. The rules know only ASCII quotes, dashes and ellipses. Curly quotes, the Unicode ellipsis and long dashes pass through unchanged unless you map them first.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

penn_treebank_tokenization.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/penn-treebank-tokenization/. The authors are listed in prov/BK6WGY.jsonl.

"""Penn Treebank word tokenization, after the sed script of Robert MacIntyre (1995).

The input is one sentence on one line. The rules run in a fixed order, each on
the whole string, as in the sed script; then the string is split at spaces.
Double quotes become `` (open) and '' (close). Clitics such as 's, 're and
n't become separate tokens, so "can't" gives "ca" and "n't". Only a period at
the end of the line is split off; a period inside the sentence stays with
its word, as in "Mr." or "3.5". Brackets are kept as they are; the treebank
files later wrote them as -LRB-, -RRB- and so on, which this file does not do.
"""

import re
from typing import List, Tuple

Rule = Tuple["re.Pattern[str]", str]


def _rules(pairs: List[Tuple[str, str]]) -> List[Rule]:
    return [(re.compile(p), r) for p, r in pairs]


OPEN_QUOTES = _rules([
    (r'^"', r"`` "),
    (r'([ (\[{<])"', r"\1 `` "),
])
PUNCT = _rules([
    (r"\.\.\.", r" ... "),
    (r"[,;:@#$%&]", r" \g<0> "),
])
FINAL_PERIOD = _rules([
    (r"""([^.])(\.)([\])}>"']*)[ \t]*$""", r"\1 \2\3 "),
])
BRACKETS = _rules([
    (r"[?!]", r" \g<0> "),
    (r"[\]\[(){}<>]", r" \g<0> "),
    (r"--", r" -- "),
])
CLOSE_QUOTES = _rules([
    (r'"', r" '' "),
])
CLITICS = _rules([
    (r"([^'])' ", r"\1 ' "),
    (r"'([sSmMdD]) ", r" '\1 "),
    (r"'ll ", r" 'll "),
    (r"'re ", r" 're "),
    (r"'ve ", r" 've "),
    (r"n't ", r" n't "),
    (r"'LL ", r" 'LL "),
    (r"'RE ", r" 'RE "),
    (r"'VE ", r" 'VE "),
    (r"N'T ", r" N'T "),
])
SPECIAL_WORDS = _rules([
    (r" ([Cc])annot ", r" \1an not "),
    (r" ([Dd])'ye ", r" \1' ye "),
    (r" ([Gg])imme ", r" \1im me "),
    (r" ([Gg])onna ", r" \1on na "),
    (r" ([Gg])otta ", r" \1ot ta "),
    (r" ([Ll])emme ", r" \1em me "),
    (r" ([Mm])ore'n ", r" \1ore 'n "),
    (r" '([Tt])is ", r" '\1 is "),
    (r" '([Tt])was ", r" '\1 was "),
    (r" ([Ww])anna ", r" \1an na "),
])


def _apply(rules: List[Rule], x: str) -> str:
    for pattern, repl in rules:
        x = pattern.sub(repl, x)
    return x


def ptb_stages(x: str) -> List[str]:
    """Return the string after each line L1 to L9 of the pseudocode, in order.

    Precondition: x is one sentence with no line break. Cost: O(len(x)) for
    each of the 29 substitutions, so O(len(x)) in all, because no rule makes
    the string more than a constant factor longer.
    """
    if "\n" in x or "\r" in x:
        raise ValueError("one sentence per line: the input has a line break")
    out = []
    x = _apply(OPEN_QUOTES[:1], x)  # @line L1
    out.append(x)
    x = _apply(OPEN_QUOTES[1:], x)  # @line L2
    out.append(x)
    x = _apply(PUNCT, x)  # @line L3
    out.append(x)
    x = _apply(FINAL_PERIOD, x)  # @line L4
    out.append(x)
    x = _apply(BRACKETS, x)  # @line L5
    out.append(x)
    x = " " + x + " "  # @line L6
    out.append(x)
    x = _apply(CLOSE_QUOTES, x)  # @line L7
    out.append(x)
    x = _apply(CLITICS, x)  # @line L8
    out.append(x)
    x = _apply(SPECIAL_WORDS, x)  # @line L9
    out.append(x)
    return out


def ptb_tokenize(x: str) -> List[str]:
    """Split one English sentence into Penn Treebank tokens.

    Precondition: x is one sentence with no line break. Cost: O(len(x)).
    """
    return ptb_stages(x)[-1].split()  # @line L10
test_penn_treebank_tokenization.py 137 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/penn-treebank-tokenization/. The authors are listed in prov/BK6WGY.jsonl.

import random
import re
import shutil
import subprocess

import pytest

from penn_treebank_tokenization import ptb_stages, ptb_tokenize

# The substitutions of the tokenizer.sed script of Robert MacIntyre, in order.
SED_SCRIPT = [
    's=^"=`` =g',
    's=\\([ ([{<]\\)"=\\1 `` =g',
    "s=\\.\\.\\.= ... =g",
    "s=[,;:@#$%&]= & =g",
    "s=\\([^.]\\)\\([.]\\)\\([])}>\"']*\\)[ \t]*$=\\1 \\2\\3 =g",
    "s=[?!]= & =g",
    "s=[][(){}<>]= & =g",
    "s=--= -- =g",
    "s=$= =",
    "s=^= =",
    "s=\"= '' =g",
    "s=\\([^']\\)' =\\1 ' =g",
    "s='\\([sSmMdD]\\) = '\\1 =g",
    "s='ll = 'll =g",
    "s='re = 're =g",
    "s='ve = 've =g",
    "s=n't = n't =g",
    "s='LL = 'LL =g",
    "s='RE = 'RE =g",
    "s='VE = 'VE =g",
    "s=N'T = N'T =g",
    "s= \\([Cc]\\)annot = \\1an not =g",
    "s= \\([Dd]\\)'ye = \\1' ye =g",
    "s= \\([Gg]\\)imme = \\1im me =g",
    "s= \\([Gg]\\)onna = \\1on na =g",
    "s= \\([Gg]\\)otta = \\1ot ta =g",
    "s= \\([Ll]\\)emme = \\1em me =g",
    "s= \\([Mm]\\)ore'n = \\1ore 'n =g",
    "s= '\\([Tt]\\)is = '\\1 is =g",
    "s= '\\([Tt]\\)was = '\\1 was =g",
    "s= \\([Ww]\\)anna = \\1an na =g",
    "s=  *= =g",
    "s=^ *==g",
]

PIECES = [
    "the", "John", "can", "n't", "'s", "'re", "'ll", "'ve", "'d", "'M", "cannot", "Gonna", "wanna",
    "gotta", "lemme", "gimme", "'tis", "'Twas", "more'n", "d'ye", "don't", "I'm", "WON'T", "WE'LL",
    "Mr.", "3.5", "U.S.", "a.b", "x", ".", "...", "?", "!", ",", ";", ":", "@", "#", "$", "%", "&",
    "(", ")", "[", "]", "{", "}", "<", ">", "--", '"', "'",
]


def random_line(rng):
    k = rng.randint(0, 10)
    return "".join(rng.choice(PIECES) + rng.choice(["", " ", " ", "\t"]) for _ in range(k))


def test_page_example():
    x = 'He said, "I can\'t pay $3.50 for John\'s book."'
    assert ptb_tokenize(x) == [
        "He", "said", ",", "``", "I", "ca", "n't", "pay", "$", "3.50", "for", "John", "'s", "book", ".", "''",
    ]
    stages = ptb_stages(x)
    assert len(stages) == 9
    assert stages[3].endswith('book ." ')
    assert stages[6].endswith("book . ''   ")


def test_clitics_and_special_words():
    assert ptb_tokenize("They're late, aren't they?") == ["They", "'re", "late", ",", "are", "n't", "they", "?"]
    assert ptb_tokenize("I'm sure we'll go, I'd say.") == ["I", "'m", "sure", "we", "'ll", "go", ",", "I", "'d", "say", "."]
    assert ptb_tokenize("WE'VE WON'T") == ["WE", "'VE", "WO", "N'T"]
    assert ptb_tokenize("Mr. Smith gonna stay.") == ["Mr.", "Smith", "gon", "na", "stay", "."]
    assert ptb_tokenize("'Tis cannot.") == ["'T", "is", "can", "not", "."]
    assert ptb_tokenize("I wanna, gotta, lemme gimme") == [
        "I", "wan", "na", ",", "got", "ta", ",", "lem", "me", "gim", "me",
    ]
    assert ptb_tokenize("It's the students' book.") == ["It", "'s", "the", "students", "'", "book", "."]


def test_quotes_brackets_and_dots():
    assert ptb_tokenize('"Hi," she said.') == ["``", "Hi", ",", "''", "she", "said", "."]
    assert ptb_tokenize("They're (I think) late...") == ["They", "'re", "(", "I", "think", ")", "late", "..."]
    assert ptb_tokenize("a--b [c] {d} <e>") == ["a", "--", "b", "[", "c", "]", "{", "d", "}", "<", "e", ">"]
    assert ptb_tokenize("He came (late).") == ["He", "came", "(", "late", ")", "."]
    assert ptb_tokenize("U.S. officials met in the U.S.") == ["U.S.", "officials", "met", "in", "the", "U.S", "."]


def test_only_the_final_period_is_split():
    assert ptb_tokenize("I like it. You do too.") == ["I", "like", "it.", "You", "do", "too", "."]


def test_edge_cases():
    assert ptb_tokenize("") == []
    assert ptb_tokenize("   ") == []
    assert ptb_tokenize(".") == ["."]
    assert ptb_tokenize("word") == ["word"]
    with pytest.raises(ValueError):
        ptb_tokenize("two\nlines")


def test_random_invariants():
    rng = random.Random(1993)
    single = set(",;:@#$%&?!()[]{}<>")
    done = 0
    while done < 500:
        x = random_line(rng)
        if "''" in x:
            continue
        done += 1
        toks = ptb_tokenize(x)
        assert all(t and not re.search(r"\s", t) for t in toks)
        assert all(len(t) == 1 for t in toks if single & set(t))
        # Only spaces are added, and only double quotes change, into `` or ''.
        joined = "".join('"' if t in ("``", "''") else t for t in toks)
        assert joined == re.sub(r"\s", "", x)
        assert toks.count("``") + toks.count("''") == x.count('"')


@pytest.mark.skipif(shutil.which("sed") is None, reason="no sed program")
def test_random_against_the_sed_script():
    rng = random.Random(1995)
    lines = [random_line(rng) for _ in range(500)]
    args = ["sed"]
    for rule in SED_SCRIPT:
        args += ["-e", rule]
    res = subprocess.run(args, input="\n".join(lines) + "\n", capture_output=True, text=True,
                         env={"LC_ALL": "C"}, timeout=60)
    assert res.returncode == 0
    out = res.stdout.split("\n")
    for x, y in zip(lines, out):
        assert ptb_tokenize(x) == y.split()

History

The Penn Treebank project at the University of Pennsylvania annotated over 4.5 million words of American English with part-of-speech tags, and a part of it with skeletal parses (Marcus, Santorini and Marcinkiewicz 1993). Its token conventions, with separate clitics and the `` and '' quotes, became the standard input of English taggers and parsers trained on the Wall Street Journal section. Robert MacIntyre wrote the sed script that applies the conventions to new text in late 1995. Later tools, such as the NLTK port and the Stanford PTBTokenizer, keep the conventions and change the implementation.

References

  1. Mitchell P. Marcus, Beatrice Santorini and Mary Ann Marcinkiewicz, Building a large annotated corpus of English, the Penn Treebank, Computational Linguistics 19(2), 1993, pages 313 to 330 (the corpus, its part-of-speech tag set and its annotation process)
  2. Robert MacIntyre, tokenizer.sed, the Penn Treebank tokenizer, University of Pennsylvania, 1995 (copy in the TurboParser repository), the whole script, 33 substitutions in order, with the header comments on one sentence per line
  3. NLTK documentation, module nltk.tokenize.treebank (TreebankWordTokenizer), the class TreebankWordTokenizer, a port of the sed script with extra rules and the option convert_parentheses

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example