Chonky

October 23, 2025 · View on GitHub

Chonky is a Python library that intelligently segments text into meaningful semantic chunks using a fine-tuned transformer model. This library can be used in the RAG systems.

Installation

pip install chonky

Usage:

from chonky import ParagraphSplitter

# on the first run it will download the transformer model
splitter = ParagraphSplitter(device="cpu")

# Or you can select the model
# splitter = ParagraphSplitter(
#  model_id="mirth/chonky_modernbert_base_1",
#  device="cpu"
# )

text = (
    "Before college the two main things I worked on, outside of school, were writing and programming. "
    "I didn't write essays. I wrote what beginning writers were supposed to write then, and probably still are: short stories. "
    "My stories were awful. They had hardly any plot, just characters with strong feelings, which I imagined made them deep. "
    "The first programs I tried writing were on the IBM 1401 that our school district used for what was then called 'data processing.' "
    "This was in 9th grade, so I was 13 or 14. The school district's 1401 happened to be in the basement of our junior high school, "
    "and my friend Rich Draves and I got permission to use it. It was like a mini Bond villain's lair down there, with all these alien-looking machines — "
    "CPU, disk drives, printer, card reader — sitting up on a raised floor under bright fluorescent lights."
)

for chunk in splitter(text):
  print(chunk)
  print("--")

Sample Output

Before college the two main things I worked on, outside of school, were writing and programming. I didn't write essays. I wrote what beginning writers were supposed to write then, and probably still are: short stories. My stories were awful. They had hardly any plot, just characters with strong feelings, which I imagined made them deep.
--
The first programs I tried writing were on the IBM 1401 that our school district used for what was then called "data processing." This was in 9th grade, so I was 13 or 14. The school district's 1401 happened to be in the basement of our junior high school, and my friend Rich Draves and I got permission to use it.
--
 It was like a mini Bond villain's lair down there, with all these alien-looking machines — CPU, disk drives, printer, card reader — sitting up on a raised floor under bright fluorescent lights.
--

The usage pattern is the following: strip all the markup tags to produce pure text and feed this text into the splitter. For this purpose there is helper class MarkupRemover (it automatically detects the content format):

from chonky.markup_remover import MarkupRemover
from chonky import ParagraphSplitter

remover = MarkupRemover()
splitter = ParagraphSplitter()

text = remover("# Header 1 ...")
splitter(text)

Supported formats: markdown, xml, html.

Supported models

Model IDSeq LengthNumber of ParamsMultilingual
mirth/chonky_modernbert_large_11024396M
mirth/chonky_modernbert_base_11024150M
mirth/chonky_mmbert_small_multilingual_1 🆕1024140M
mirth/chonky_distilbert_base_uncased_151266.4M

Benchmarks

The following values are token based F1 scores computed on first 1M tokens of each datasets (due to performance reasons).

Various English datasets:

The do_ps fragment for SaT models here is do_paragraph_segmentation flag.

Modelbookcorpusen_judgementspaul_graham20_newsgroups
chonkY_modernbert_large_10.790.290.690.17
chonkY_modernbert_base_10.720.080.630.15
chonkY_mmbert_small_multilingual_1 🆕0.720.20.560.13
chonkY_distilbert_base_uncased_10.690.050.520.15
SaT(sat-12l-sm, do_ps=False)0.330.030.430.31
SaT(sat-12l-sm, do_ps=True)0.330.060.420.3
SaT(sat-3l, do_ps=False)0.280.030.420.34
SaT(sat-3l, do_ps=True)0.090.070.410.15
chonkIE SemanticChunker(bge-small-en-v1.5)0.210.010.120.06
chonkIE SemanticChunker(potion-base-8M)0.190.010.150.08
chonkIE RecursiveChunker0.070.010.050.02
langchain SemanticChunker(all-mpnet-base-v2)0000
langchain SemanticChunker(bge-small-en-v1.5)0000
langchain SemanticChunker(potion-base-8M)0000
langchain RecursiveChar0000
llamaindex SemanticSplitter(bge-small-en-v1.5)0.0600.060.02

Project Gutenberg validation:

Modeldeenesfritnlplptrusvzh
chonky_mmbert_small_multi_1 🆕0.880.780.910.930.860.810.810.880.970.910.11
chonky_modernbert_large_10.530.430.480.510.560.210.650.530.870.510.33
chonky_modernbert_base_10.420.380.340.40.330.220.410.350.270.310.26
chonky_distilbert_base_uncased_10.190.30.170.20.180.040.270.210.220.190.15
Number of val tokens1M1M1M1M1M1M38K1M24K1M132K