Word Counter › Guides
Why do word counters disagree? One text counted four ways in seven languages
Paste the same essay into two word counters and you can get two different numbers. Neither tool is broken. "Word" has no single definition that software can apply, so each tool picks a rule, and the rules part ways at hyphens, apostrophes, web addresses and, most of all, in languages that do not put spaces between words. We ran one document through four common rules to see how far apart they land.
Short answer: For our English text the four rules were less than 0.4% apart: 1,747 to 1,753 words. For French they spread from 1,946 to 2,143, a 10% gap caused by apostrophes and accented letters. For Japanese, Chinese and Thai, counting by spaces is meaningless: it found 92 "words" in a Japanese text where the browser's own word segmenter found 2,171. If a limit matters, find out which tool will check it and count with that one.
The four rules
- Split on spaces. Every run of characters between spaces or line breaks is one word. This is the simplest rule, and it is the one our word counter uses.
- The browser's word segmenter. Browsers ship a function,
Intl.Segmenter, that follows the Unicode text segmentation rules and uses dictionaries for languages written without spaces. We counted the pieces it marks as word-like. - The
\w+pattern. A common shortcut in program code. In JavaScript, where we ran it, a word is a run of the unaccented letters A to Z, digits and the underscore. - Runs of letters and digits in any script. The same idea, extended to every alphabet: anything that is not a letter, a digit or an accent mark ends the word.
How we tested
We needed the same text in several languages, so we used the Universal Declaration of Human Rights as published by the UDHR in Unicode project: the full English, French, Spanish, Korean, Japanese, Simplified Chinese and Thai versions, titles and article headings included. Each text was pasted into the word counter on this site in Chromium 153 and the Words and Characters figures were read from the page. In the same browser we ran the other three rules on the identical text. As a cross-check, splitting each text on whitespace in Python gave the same seven numbers as our counter.
Results for the whole document
| Language | Characters | Split on spaces | Browser segmenter | \w+ pattern | Letter and digit runs |
|---|---|---|---|---|---|
| English | 10,637 | 1,747 | 1,753 | 1,753 | 1,753 |
| French | 11,901 | 1,949 | 1,946 | 2,143 | 2,038 |
| Spanish | 11,887 | 1,913 | 1,913 | 2,089 | 1,913 |
| Korean | 4,715 | 1,185 | 1,186 | 30 | 1,186 |
| Japanese | 4,182 | 92 | 2,171 | 24 | 301 |
| Chinese (Simplified) | 2,988 | 97 | 1,606 | 5 | 237 |
| Thai | 9,290 | 341 | 2,331 | 30 | 349 |
English: six words apart, all of them hyphens
The whole difference in the English text comes from five places where a hyphen joins words. Co-operation appears twice, and non-political and well-being once each: one word by spaces, two by every other rule. Non-self-governing is one word by spaces and three by the others. That adds up to exactly the six words between 1,747 and 1,753. This text has few hyphens and no contractions or web addresses. As the short strings further down show, each of those pulls the rules apart, so a text with more of them will show a wider gap.
French and Spanish: apostrophes and accents
French shows how much a small rule matters. The text contains 92 words joined by an apostrophe, such as l'homme. The rule that cuts at every non-letter splits each of them in two, which is the whole difference between 1,946 and 2,038. The browser segmenter keeps them whole. Counting by spaces gives 1,949: three hyphenated words count once instead of twice, but six semicolons count as words, because French puts a space before a semicolon and the punctuation mark is left standing alone.
The \w+ pattern does worst here. It knows only unaccented letters, so an é or ñ inside a word cuts it in two, and one at the start or end is simply dropped (café becomes caf). It reported 2,143 words for French and 2,089 for Spanish, 10% and 9% above the count by spaces. Spanish, with no apostrophes and no hyphenated words in this text, got 1,913 from all three other rules.
Korean: spaces work, the ASCII pattern does not
Korean puts spaces between words, so counting by spaces (1,185) and the segmenter (1,186) differ by a single pair of words joined with a middle dot. The \w+ pattern found 30 "words", all of them the article numbers 1 to 30, because Hangul is not in its alphabet.
Japanese, Chinese and Thai: counting by spaces fails
These three languages are written without spaces between words. Counting by spaces therefore counts lines and phrases: 92 for the Japanese text, 97 for the Chinese, 341 for the Thai. The letter-run rule does little better, since it breaks only at spaces and punctuation. Only the segmenter, which looks words up in a dictionary, returns numbers of a sensible size: 2,171, 1,606 and 2,331.
Even those are one tool's opinion. Where a word ends in Japanese or Chinese is a matter of convention, and a different dictionary will draw some of the lines elsewhere. This is why length limits in these languages are often set in characters, not words. If you write in one of them, read the Characters figure on our counter and ignore Words, reading time and speaking time.
Small cases that split the rules
We also ran short strings through the same four rules.
| Text | Split on spaces | Browser segmenter | \w+ pattern | Letter and digit runs |
|---|---|---|---|---|
don't | 1 | 1 | 2 | 2 |
rock'n'roll | 1 | 1 | 3 | 3 |
well-being | 1 | 2 | 2 | 2 |
and/or | 1 | 2 | 2 | 2 |
word—word (dash, no spaces) | 1 | 2 | 2 | 2 |
word — word (dash with spaces) | 3 | 2 | 2 | 2 |
3.5 | 1 | 1 | 2 | 2 |
1,000 | 1 | 1 | 2 | 2 |
10:30 | 1 | 2 | 2 | 2 |
U.S.A. | 1 | 3 | 3 | 3 |
help@glowhalo.org | 1 | 3 | 3 | 3 |
https://tools.glowhalo.org/words/ | 1 | 5 | 5 | 5 |
naïve café | 2 | 2 | 3 | 2 |
... | 1 | 0 | 0 | 0 |
Two patterns stand out. Counting by spaces never splits anything, so a web address is one word and so is a pair of words joined by a dash typed without spaces; but it also counts a lone dash or a row of dots as a word. The pattern rules split at the punctuation marks we tried between letters or digits, so a contraction becomes two words and a decimal number becomes two as well.
What to do when the number matters
- Count with the tool that will judge you. If a journal, a course or a client checks the limit in a particular program, that program's number is the only one that counts. No other counter can promise to match it on every text.
- Leave a margin near a limit. In our English text the rules were less than 0.4% apart; text with many hyphens, contractions or links will be further apart. For English text like this one, staying a few percent under a hard limit makes a surprise much less likely. In French and Spanish the
\w+pattern ran about 10% above the count by spaces, so a few percent is not enough if a tool of that kind does the checking. - Type dashes the way you want them counted. A dash with spaces around it adds a word under the spaces rule; a dash without spaces glues two words into one under that same rule.
- For Japanese, Chinese or Thai, use characters. Word counts for these languages depend entirely on the tool.
- If you write code that counts words, avoid plain
\w+for anything but unaccented English. It dropped almost all of the Korean text and inflated the French count by a tenth.
Limits of this test
One document cannot stand for all writing: the English version has no contractions, no web addresses and few numbers. The segmenter's results come from Chromium 153; other browsers and later versions carry their own dictionaries and may give slightly different counts, especially for Japanese, Chinese and Thai. We did not test word processors, so nothing here says which rule any particular product follows.
The measurements are in two files: documents.csv (the seven translations) and tokens.csv (the short strings, including some not shown above). The columns are the text or language, characters, split_on_spaces, browser_segmenter, ascii_word_regex and unicode_letter_runs.
Common questions
Which rule is the correct one?
None of them is official. Counting by spaces is the easiest to check by hand. The segmenter follows a published Unicode standard and handles more languages. What matters is using the same rule as whoever set your limit.
Does a hyphenated word count as one word or two?
It depends on the rule. Counted by spaces it is one; the segmenter and the pattern rules counted well-being as two.
Why does my word count change when I paste text from a PDF?
Copying from a PDF can leave a word split at the hyphen where a line ended, as in exam- ple. Each rule then counts two pieces where the page shows one word. Rejoining those words before counting brings the number back in line with the original. We did not test PDFs here.
References
- Unicode Standard Annex #29: Unicode Text Segmentation
- MDN: Intl.Segmenter
- UDHR in Unicode (source of the seven translations)
Figures without a source link come from the steps shown on this page. Companion tool: Word Counter. Spotted an error? Write to help@glowhalo.org. Chromium is a trademark of its owner; GlowHalo is not affiliated with it.