docs: text splitters improvements (#4490)

#docs: text splitters improvements

Changes are only in the Jupyter notebooks.
- added links to the source packages and a short description of these
packages
- removed " Text Splitters" suffixes from the TOC elements (they made
the list of the text splitters messy)
- moved text splitters, based on the length function into a separate
list. They can be mixed with any classes from the "Text Splitters", so
it is a different classification.

## Who can review?
        @hwchase17 - project lead
        @eyurtsev
        @vowelparrot

NOTE: please, check out the results of the `Python code` text splitter
example (text_splitters/examples/python.ipynb). It looks suboptimal.
This commit is contained in:
Leonid Ganeline
2023-05-17 21:33:34 -07:00
committed by GitHub
parent 613bf9b514
commit c998569c8f
11 changed files with 356 additions and 73 deletions

View File

@@ -5,19 +5,21 @@
"id": "c350765d",
"metadata": {},
"source": [
"# Python Code Text Splitter\n",
"# Python Code\n",
"\n",
"PythonCodeTextSplitter splits text along python class and method definitions. It's implemented as a simple subclass of RecursiveCharacterSplitter with Python-specific separators. See the source code to see the Python syntax expected by default.\n",
"`PythonCodeTextSplitter` splits text along python class and method definitions. It's implemented as a simple subclass of `RecursiveCharacterSplitter` with Python-specific separators. See the source code to see the Python syntax expected by default.\n",
"\n",
"1. How the text is split: by list of python specific characters\n",
"2. How the chunk size is measured: by length function passed in (defaults to number of characters)"
"1. How the text is split: by list of python specific separators\n",
"2. How the chunk size is measured: by number of characters"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1703463f",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from langchain.text_splitter import PythonCodeTextSplitter"
@@ -27,7 +29,9 @@
"cell_type": "code",
"execution_count": 2,
"id": "f17a1854",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"python_text = \"\"\"\n",
@@ -77,6 +81,37 @@
"source": [
"docs"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "de625e08-c440-489d-beed-020b6c53bf69",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"['Foo:\\n\\n def bar():', 'foo():\\n\\ndef testing_func():', 'bar():']"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"python_splitter.split_text(python_text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "55aadd84-75ca-48ae-9b84-b39c368488ed",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
@@ -95,7 +130,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1"
"version": "3.10.6"
},
"vscode": {
"interpreter": {