Word Counter › Guides

Why do word counters disagree? One text counted four ways in seven languages

Open the tool: Word Counter

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

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

Split on spacesBrowser segmenterEnglish1,7471,753French1,9491,946Spanish1,9131,913Korean1,1851,186Japanese922,171Chinese971,606Thai3412,331
Words found in the same document: split on spaces vs the browser's word segmenter — chart drawn from the table below.
LanguageCharactersSplit on spacesBrowser segmenter\w+ patternLetter and digit runs
English10,6371,7471,7531,7531,753
French11,9011,9491,9462,1432,038
Spanish11,8871,9131,9132,0891,913
Korean4,7151,1851,186301,186
Japanese4,182922,17124301
Chinese (Simplified)2,988971,6065237
Thai9,2903412,33130349

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.

TextSplit on spacesBrowser segmenter\w+ patternLetter and digit runs
don't1122
rock'n'roll1133
well-being1222
and/or1222
word—word (dash, no spaces)1222
word — word (dash with spaces)3222
3.51122
1,0001122
10:301222
U.S.A.1333
help@glowhalo.org1333
https://tools.glowhalo.org/words/1555
naïve café2232
...1000

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

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

  1. Unicode Standard Annex #29: Unicode Text Segmentation
  2. MDN: Intl.Segmenter
  3. 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.

More guides

Text & developerIs minifying JSON still worth it once gzip or Brotli is on?JSON indented with 2 spaces was 26 to 140% bigger than minified in our test. After gzip the gap was 3 to 21%, and after Brotli 2 to 8%. When minifying matters and when it does not.Read guide →Text & developerDoes Base64 really make data 33% bigger? We measured it before and after compressionBase64 added about 33% to every file we tried. After gzip the cost was under 1% for images and 40 to 65% for text. What that means for data URIs, JSON and email.Read guide →Text & developerUUID v4 or v7 as a database primary key? We inserted a million rows of eachRandom v4 keys were 3–4.7 times slower to insert than time-ordered v7 keys in our SQLite test. What causes the gap and when it matters.Read guide →