Valentin G. J. Herrmann

(not to be confused with this Valentin Herrmann)

How many chinese characters do you need to learn to know 99 out of 100 in an average text?

For quite a long time I have wondered how many characters one needs to know to know 90%, 95% or even 99% of chinese characters in an average text.

On the internet numbers of about 2000 get thrown around frequently, but rarely more concrete evidence is provided. In this blog post I would like to showcase the following short python script and graph:

We can hence create the following table:

%n
50170
60260
70395
80610
901030
951510
992700
99.94350

Thus the easiest 2700 characters suffice to know 99% of characters in an average text.

My script is:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import numpy as np
import plotly.graph_objects as go
import json


def gen_normalization_table():
    return str.maketrans({"麽": "麼", "爲": "為", "爲": "為", "説": "說", "裏": "裡"})


def normalize_chinese(txt, table=gen_normalization_table()):
    return txt.translate(table)


def getFreqDict():
    with open("words.json") as f:
        freqList = json.load(f)

    freqDict = {}
    total = 0

    for x in freqList:
        freq = x["frequency"]
        word = normalize_chinese(x["word"])
        total += freq * len(word)
        for c in word:
            freqDict[c] = freqDict.get(c, 0) + freq

    return {word: freq / total for word, freq in freqDict.items()}


d = getFreqDict()

X = np.arange(1, len(d) + 1)

vals = [val for _, val in sorted(d.items(), key=lambda item: -item[1])]
Y = np.cumsum(np.fromiter(vals, float))


fig = go.Figure()

fig.add_trace(go.Scatter(x=X, y=Y, mode="lines"))

fig.update_layout(
    xaxis=dict(dtick=500, showgrid=True),
    yaxis=dict(dtick=0.10, showgrid=True),
    template="plotly_white",
)

fig.show()

# Export as interactive HTML
fig.write_html("plot.html", full_html=True, include_plotlyjs=True)

The words.json comes from https://huggingface.co/datasets/zetavg/tw-sinica-corpus-word-frequency/raw/main/words.json