-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Szymon Dudycz <[email protected]> GitOrigin-RevId: 5c5610943bfe8cac35d6e799cb8b21db09fc0db2
- Loading branch information
1 parent
e4d6d91
commit 74259ca
Showing
5 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pandas as pd | ||
|
||
import pathway as pw | ||
from pathway.xpacks.llm.splitters import RecursiveSplitter | ||
|
||
|
||
def test_recursive_from_hf_tokenizer(): | ||
|
||
from transformers import AutoTokenizer | ||
|
||
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased") | ||
|
||
splitter = RecursiveSplitter(hf_tokenizer=tokenizer, chunk_size=25, chunk_overlap=0) | ||
txt = "Pójdź, kińże tę chmurność w głąb flaszy 🍾." # 23 tokens in bert tokenizer | ||
big_txt = "\n\n".join([txt] * 5) | ||
input_table = pw.debug.table_from_pandas(pd.DataFrame([dict(ret=big_txt)])) | ||
|
||
result = input_table.select(ret=splitter(pw.this.ret)).flatten(pw.this.ret) | ||
result = pw.debug.table_to_pandas(result) | ||
|
||
assert len(result) == 5 | ||
assert result.iloc[0].ret[0] == txt | ||
assert result.iloc[0].ret[1] == pw.Json({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters