Skip to main content

Tixent: A Text Splitting Tool

PyPI PyPI - Version PyPI - Python Version License

CI/CD test lint

Build System Hatch project

Code pre-commit Code style: black Imports: isort Checked with mypy Ruff

Docstrings docformatter numpy


Installation

pip install tixent

Example

Suppose we have a function template that generates a string from a list of texts. Additionally, suppose we have a large list of texts. When you apply that list of texts to the function, it generates a long string.

Tixent can split the string generated by the template function so that the return value of counter for each element is less than a certain number.

Here, counter is a function that maps a string to an integer. Examples of such functions are len, which measures the length of a string, or tiktoken_counter("text-davinci-003"), which measures the number of tokens in a string

from typing import List

from tixent import split, tiktoken_counter


def summarization_template(texts: List[str]) -> str:
    text = " ".join(texts)
    t = "Summarize the following text.\n"
    t += f'Text: """{text}"""'
    return t


texts = [
    "Lorem ipsum dolor sit amet",
    "consectetur adipiscing elit",
    "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua",
    "Ut enim ad minim veniam",
    "quis nostrud exercitation ullamco laboris nisi",
    "ut aliquip ex ea commodo consequat",
    "Duis aute irure dolor in reprehenderit in voluptate velit",
    "esse cillum dolore eu fugiat nulla pariatur",
    "Excepteur sint occaecat cupidatat non proident",
    "sunt in culpa qui officia deserunt mollit anim id est laborum",
]
counter = tiktoken_counter("text-davinci-003")
max_count = 60

split_texts = split(texts, summarization_template, counter, max_count)
for text in split_texts:
    count = counter(text)
    assert count <= max_count
    print(f"count: {count}")
    print(text)
    print()
count: 60
Summarize the following text.
Text: """Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua Ut enim ad minim veniam"""

count: 58
Summarize the following text.
Text: """quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat Duis aute irure dolor in reprehenderit in voluptate velit"""

count: 43
Summarize the following text.
Text: """esse cillum dolore eu fugiat nulla pariatur Excepteur sint occaecat cupidatat non proident"""

count: 31
Summarize the following text.
Text: """sunt in culpa qui officia deserunt mollit anim id est laborum"""

Metadata

Release files for tixent 0.0.3

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

Source distribution (sdist)

Source distribution for tixent 0.0.3
File Size Uploaded
tixent-0.0.3.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tixent 0.0.3
File Interpreter ABI Platform
tixent-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 12.0 kB

Release files / tixent-0.0.3.tar.gz

Download URL tixent-0.0.3.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
72084f3d107d953435b72c004c93af334a121330d115d92a8a1d2fa2e41c9488
BLAKE2b-256 checksum
How to use checksums
1d34a38d076c40a35dae1edd784c4eb2543b186212260aec42e8aa9ee85f32f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.25.1

Release files / tixent-0.0.3-py3-none-any.whl

Download URL tixent-0.0.3-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3edee261041b62f17a8da48d7852baf71b6e1e0fa34194c10abc7a6432973b48
BLAKE2b-256 checksum
How to use checksums
a5e05ac3b710c107bfc52faee283a413d6563f8d0ac376de778b7c8cdf93da4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.25.1

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

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