Skip to main content

Semantic Chunking

Semantic Chunking is a Python library for segmenting text into meaningful chunks using embeddings from Sentence Transformers.

Features

  • Splits text into semantic chunks using cosine similarity
  • Configurable chunk size and similarity thresholds
  • Based on sentence-transformers

Installation

pip install semantic-chunking

USAGE

from semantic_chunking import SemanticChunker

def test_semantic_chunker():
    text = """Machine learning is a subset of artificial intelligence that focuses on the use of data and algorithms to imitate the way that humans learn.
    Deep learning is a more specialized version of machine learning that uses neural networks with multiple layers.
    These advanced algorithms can process complex patterns and make intelligent decisions with minimal human intervention.
    The applications of machine learning are vast, ranging from image recognition to natural language processing."""

    chunker = SemanticChunker(model_name='all-MiniLM-L6-v2', max_chunk_size=128, similarity_threshold=0.3)
    chunks = chunker.semantic_chunk(text)

    print("Semantic Chunks:")
    for i, chunk in enumerate(chunks, 1):
        print(f"Chunk {i}: {chunk}")
        print(f"Words: {len(chunk.split())}\n")

# Uncomment to test
test_semantic_chunker()

Metadata

Release files for semantic-chunking 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for semantic-chunking 0.1.1
File Size Uploaded
semantic_chunking-0.1.1.tar.gz 3.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for semantic-chunking 0.1.1
File Interpreter ABI Platform
semantic_chunking-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 6.8 kB

Release files / semantic_chunking-0.1.1.tar.gz

Download URL semantic_chunking-0.1.1.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d5b203bd891ecd4b9e8575ce27f7bc6d8897941e2bcd7676165819221db35305
BLAKE2b-256 checksum
How to use checksums
a6035b3025afd998d0f674b52b88e6ee72481118d146df328696152175f12827
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.10

Release files / semantic_chunking-0.1.1-py3-none-any.whl

Download URL semantic_chunking-0.1.1-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b561181ec0165eb57f8cbea381dc404e240714399ba193b273d371cc8b41af1
BLAKE2b-256 checksum
How to use checksums
efaebc386a2d4bb25d193e2f5c6f75aa0e31b296ac64922bb5eb7589ccd9f644
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.10

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page