logo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions

Updated 1 year ago

towhee

Text Spliter

author: shiyu22


Description

Text spliter is used to split text into chunk lists.

Refer to Recursive Characters for the operation of splitting text.


Code Example

from towhee import pipe, ops, DataCollection

p = (
    pipe.input('url')
        .map('url', 'text', ops.text_loader())
        .flat_map('text', 'text', ops.text_spliter())
        .output('url', 'text')
    )

res = p('https://github.com/towhee-io/towhee/blob/main/README.md')
DataCollection(res).show()
result


Factory Constructor

Create the operator via the following factory method

towhee.text_loader(chunk_size=300)

Parameters:

type: str

​ The type of spliter, defaults to 'RecursiveCharacter'. You can set this parameter in ['RecursiveCharacter', 'Markdown', 'PythonCode', 'Character', 'NLTK', 'Spacy', 'Tiktoken', 'HuggingFace'].

chunk_size: int

​ The maximum size of chunk, defaults to 300.


Interface

The operator split incoming the text and return chunks.

Parameters:

data: str

​ The text data.

Return: List[Document]

A list of the chunked document.

shiyu22 e14750a173 Add spliter type param 6 Commits
file-icon .gitattributes
1.1 KiB
download-icon
Initial commit 1 year ago
file-icon README.md
2.1 KiB
download-icon
Add spliter type param 1 year ago
file-icon __init__.py
110 B
download-icon
Update spliter 1 year ago
file-icon requirements.txt
47 B
download-icon
Add spliter type param 1 year ago
file-icon result.png
149 KiB
download-icon
Update README 1 year ago
file-icon spliter.py
2.0 KiB
download-icon
Add spliter type param 1 year ago