7.0
热点
AI SCORE
开源项目2025-04-11 20:18
Chonky:神经网络语义分块工具
Hacker News · github.com#RAG#开源
Editor brief · 编辑速览
开源项目用神经方法优化文本语义分块,改进RAG系统的质量。
开源项目用神经方法优化文本语义分块,改进RAG系统的质量。
Chonky 是一个 Python 库,使用经过微调的 Transformer 模型将文本智能地分割成有意义的语义块。该库可用于 RAG 系统。
pip install chonky
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("--")
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.
--
使用模式如下:删除所有标记标签以生成纯文本,然后将该文本提供给分割器。为此有一个辅助类 MarkupRemover(它会自动检测内容格式):
from chonky.markup_remover import MarkupRemover
from chonky import ParagraphSplitter
remover = MarkupRemover()
splitter = ParagraphSplitter()
text = remover("# Header 1 ...")
splitter(text)
支持的格式:markdown、xml、html。
以下值是基于令牌的 F1 分数,计算于每个数据集的前 100 万个令牌(出于性能原因)。
各种英文数据集:
SaT 模型中的 do_ps 片段是 do_paragraph_segmentation 标志。
Project Gutenberg 验证: