A Formal Grammar For Toki Pona: Zach Tomaszewski ICS661 11 Dec 2012
A Formal Grammar For Toki Pona: Zach Tomaszewski ICS661 11 Dec 2012
Zach Tomaszewski
ICS661
11 Dec 2012
1) Introduction
Toki pona is a simple constructed language. Although it is an artificial language with a very
limited and closed vocabulary, toki pona still exhibits many of the features of a natural human
language. In this project, I developed a machine-readable formal grammar for toki pona and
then used a CKY parser to recognize valid and invalid toki pona sentences.
Toki Pona. Toki pona is a constructed language--or "conlang"--invented by Sonja Elen Kisa.
It is inspired by Taoism and the Sapir-Whorf hypothesis. Specifically, Kisa proposes that toki
pona encourages its speakers to think simply and to focus on basic reality rather than
abstract or euphemistic concepts [1].
Toki pona has been fairly successful for a conlang, gaining interested speakers outside of the
normal conlang community. Kisa has largely abandoned the project. This has left the main
tokipona.org website in a state of disrepair. However, a scattered community continues to
play with the language elsewhere. This community presence is mostly scattered over various
blogs and personal sites, community groups and forums, wikis, and a few YouTube videos.
The best learning resource is a tutorial [2] by jan Pije (Bryant Knight), an early fluent toki pona
speaker. Although a fair amount of language-tinkering has been proposed, most of the
community adheres to the original words and rules laid out by Kisa.
Toki pona has a 14-letter alphabet. Letters are always lowercase except for the first letter of a
proper name. Toki pona contains about 120 words, depending on how you count them. A
small number of words were dropped during the development of the language. One word has
two accepted spellings (ale and ali). Five words were added near the end of Kisa's
involvement, and they have not been widely adopted by the community. One of those five
words, pu, has no known definition.
Sentences are given in subject-verb-object order. A special marker word, li, marks the
separation between the subject and verb, though li is dropped when the subject is simply mi
("I") or sina ("you"). Another separator, e, marks the transition between verb and object. Toki
pona has no tense, gender, or number, though each of these can be explicitly specified with
an appropriate adjective or conditional preface to the sentence if necessary. Modifiers,
whether adjectives or adverbs, come after the words they modify.
Most words have a broad conceptual range. For example, as an adjective, suli can mean
"big", "fat", "tall", or "important". Similarly, pona means "good", "simple", or "pure" as an
adjective or "fix", "improve", or "simplify" as a verb. Not all words are this general, however.
oko ("eye") is used only as a noun. "Looking" as a verb and "visual" as a modifier is covered
by a different word, lukin.
Most, but not all, of the words can be used as either noun, verb, or modifier depending on
their placement in the sentence. For example, moku can mean "food" as a noun, "edible" as
a modifier, or "eat" as a verb. Occasionally, it can be difficult to tell which role a word is filling.
For example, in the sentence
mi moku.
moku is most likely a verb, which gives this sentence the meaning "I eat". However, if we
read moku as a predicate adjective or predicate nominative, this sentence could also be
parsed as "I am edible" or "I am food". This combination of grammatical vagueness with the
wide conceptual range of most words can make toki pona highly ambiguous at times. While
the greater context often gives clues to help disambiguate, it can often be harder to read or
understand toki pona than it is to write or speak it.
Because of the limited vocabulary, descriptive phrases are very common. Many of these
have become fairly standardized. Some examples include:
I have personally been dabbling with toki pona on and off for a couple years. At this point, I
am basically conversant but not fluent.
Formal Grammars. A formal grammar is a precise description of all possible strings (or
sentences) of a particular language. Formal grammars can be specified in machine-readable
form in order to construct parsers and generators. Parsers recognize whether a string of
symbols is a valid instance of the language, and generators produce valid strings that are in
the language.
One example parsing algorithm is the Cocke-Younger-Kasami (CYK or CKY) algorithm. The
CKY algorithm starts with the tokens of the input sentence. Using an efficient dynamic
programming approach, the parser works bottom-up through the rules of the grammar to see
if it can reach the highest-level start symbol in the grammar. If this start symbol is reached,
then the input sentence is a valid string in the language. The CYK algorithm only works with
a particular class of grammars--context-free grammars (CFGs)--and the rules of the grammar
used must be in Chomsky Normal Formal (CNF). In CNF, each production rule in the
grammar must produce either two non-terminals or a single terminal. Conveniently, any CFG
can be converted into an equivalent Chomsky Normal Form.
Project Goal. The goal of this project was to develop a formal context-free grammar that
describes all valid toki pona sentences. A CYK parser is then used to recognize whether a
given string is a valid toki pona sentence. The parse produced--and there may be more than
one possible parse or reading of a valid sentence--also shows the internal grammatical
structure of the sentence.
This parser could provide useful feedback for toki pona learners to check their sentence
productions. It could also aid reading by explicitly showing the different possible structures of
a valid sentence, thus making any ambiguity explicitly clear. It is also an important first step--
syntactic parsing--that could be used as a foundation for more advanced semantic
processing, such as machine translation.
2) Description
Previous Work. This is not the first project to specify a formal grammar for toki pona. The
Wikipedia article for toki pona has gone through at least 2 major iterations trying to concisely
describe the language rules. The first attempt [3] was so simple that it lacked even some of
the basic rules such as dropping li when the subject is only mi or sina. The current form [4] is
longer, though it is not in a precise formal grammar format.
jan Kipo, a significant member of the toki pona community, sketched out a more formal
grammar [5]. Matthew Martin then converted this grammar to a machine-readible form for
use with the AGFL parser [6].
For the parser used in this project, I had previously developed two relevant programs as part
of earlier assignment work. The first program converts any CFG into CNF. The second is a
CKY parser that shows all possible parses of a given sentence based on a given CNF
grammar. Both programs are written in Python 3. The source code is available online, as
described in Appendix C.
Methodology. I first collected a corpus of 100 valid toki pona sentences. For this, I used the
toki-pona-to-English problems given in jan Pije's tutorial. I also added a poem from the official
toki pona website to bring the number of sentences up to 100. This corpus is provided in
Appendix B. I also wrote approximately 20 invalid sentences that mirrored common mistakes
made by toki pona novices.
For ease of parsing, each sentence was placed on its own line and all punctuation except
commas was removed. A space was added before every comma in order to make it its own
token. All proper names--easily recognized by their initial capital letter--where replaced with a
single 'Name' token.
I then developed my own toki pona grammar. For the lexicon, I assigned words to noun, verb,
modifier, or preposition according Kisa's descriptions. I largely worked independently on the
higher levels of the grammar, although I did refer occasionally to the current Wikipedia
descriptions.
I ran the corpus of valid sentences through the parser, examined the parses, and tweaked the
grammar accordingly. This required a few hours of work. The resulting grammar is given in
Appendix A.
Converting this context-free grammar to Chomsky Normal Form produced 3907 rules. This
high number is partly due to a small bug in the CNF program that occasionally produces
duplicate production rules for the form ZZ1 → A B and ZZ2 → A B. This does not affect the
correctness of the resulting grammar or parses; it is simply somewhat inefficient. This was
not fixed due to time constraints.
An example parse of the sentence jan utala li seli ala seli e tomo ("Did the soldier(s) burn the
building?") is:
My grammar failed on a single sentence: tawa pona. This is an unusual interjection phrase
meaning "good journey", "bon voyage", or "goodbye". It could easily be handled by the
addition of a specific rule for it. The general form of a modified noun by itself is not normally a
valid sentence structure, however.
In addition to recognizing more of the valid sentences, my grammar also produced fewer
duplicate or alternate parses overall, even given the CNF-converter's inefficiency mentioned
above.
First of all, humans apparently do not think in formal grammars. Despite recently learning the
rules of toki pona grammar--often phrased casually in the form of "do this, except in this
case"--it proved rather challenging to convert this knowledge into a CFG format.
Regarding toki pona, a number of words that are classified as nouns and not modifier are still
frequently used in a modifier-like way. For example, ilo means "tool" and suno means "sun"
or "light". Although suno is not technically not a modifier, the construction ilo suno ("light tool",
meaning flashlight or lamp) is still a valid construction.
To handle this, I added a rule that any noun can be modified by another noun. This produces
many duplicate parses, since for any word that can be either a noun or modifier produces
both possible interpretations. A future extension to this project could use probability to favor
any noun-modifier constructions over noun-noun constructions.
As the grammar stands now, not all modifying phrases are correctly placed. For example, the
imperative sentence o pana e moku tawa mi means "(you) give food to me". The phrase
tawa mi ("to me") most accurately modifies pana ("give") as an adverb, not moku ("food") as
an adjective. The grammar currently only produces the second, less-correct parse.
The grammar does not encode full recursion in all cases. For example, it handles only up to
two direct objects, as in o pana e moku e telo, meaning "give me food and water". It only
allows for a single modal--such as ken or wile--to modify a verb. For example, it will accept
mi wile tawa ("I want to go") and mi ken wile ("I am able to go"), but it will not accept the valid
mi wile ken tawa ("I want to be able to go"). Sentences with more than a single modal are
rare though, and more than two would produce a sentence of questionable validity.
Toki pona breaks certain complex or compound relationships into multiple related simple
sentences. For example, "I want you to give me food" would be translated as mi wile e ni:
sina pana e moku tawa mi ("I want this: you give food to me"). Although tightly bound
semantically, these two sentences are handled separately by the current grammar.
Toki pona also has an odd idiom for asking yes-or-no questions. For example, sina moku ala
moku = "you eat not eat" = "Are you eating?" The correct response would then be either
moku ("yes") or moku ala ("no"). The grammar is currently too permissive with this question
form, accepting any V ala V form, even if these the two V's are different verb tokens. This
could easily be corrected with an extra rule for very possible V ala V form, though this
would noticeable increase the size of the grammar. Also the answer format of only a single
verb (possibly modified by ala) would normally be an invalid sentence except in this context.
The grammar allows this form regardless of context.
These last few deficiencies highlight the main limitation of this project: It handles only the
syntactic rules, without considering either semantics (meaning) or pragmatics (context). I
particularly noticed this when parsing "invalid" sentences that were actually accepted as valid.
For example, a common beginner mistake is to forget to include the e marker between the
verb and direct object. Rather than mi wile e telo ("I want water"), a beginner may say mi wile
telo. Most listeners would recognize the beginner's intention and correct their syntax.
However, without considering semantics, this mi wile telo formation is technically correct,
meaning either "I want/desire wetly" or "I am wet desire".
4) Conclusion
The essential goals of this project were achieved by constructing a context-free formal
grammar for toki pona. In an empirical evaluation using a CKY parser, this grammar was
shown to be an improvement over existing tools.
However, future work remains to be done. The grammar has a few known minor deficiencies.
Further evaluation should be done on both valid and invalid sentences to flush out any other
limitations or errors that have gone unnoticed. Also, given that so many of toki pona's words
can serve as any part of speech, using a top-down, rather than bottom-up, parser would likely
be more efficient.
Once these syntactic processing tools are stable and well-tested, they could then be used as
the foundation for more interesting translation work at the semantic and pragmatic levels.
Works Cited
V -> anpa | ante | awen | ijo | ike | jaki | jan | jo | kalama | kama | ken
| kepeken | kule | lape | lawa | lete | lili | lon | lukin | moku | moli | musi
| mute | nasa |olin | open | pakala | pali | pana | pilin | pimeja | pini | poka
| pona | seli | sin | sitelen | sona | suli | suwi | tawa | telo | toki | tomo | tu
| unpa | utala | wan | wawa | weka | wile
Mod -> ala | ale | ali | ante | awen | ijo | ike | insa | jaki | jan | jelo
| kalama | kama | kin | kiwen | kule | kute | kulupu | laso | lape | lawa | lete
| lili | loje | lukin | mama | meli | mi | mije | moku | moli | monsi | mun | musi
| mute | nasa | ni | olin | ona | pakala | pali | pimeja | pini | poka | pona
| sama | seli | seme | sewi | sike | sin | sina | suli | suwi | taso | tawa | telo
| toki | tomo | tu | unpa | uta | walo | wan | wawa | weka | wike
Name -> jan 'Name' | ma 'Name' | ma tomo 'Name' | toki 'Name' | soweli 'Name'