Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant pass transformer pipeline to RollingWindowSplitter function #30

Open
TatvaJoshi opened this issue Dec 31, 2024 · 0 comments
Open

Comments

@TatvaJoshi
Copy link

TatvaJoshi commented Dec 31, 2024

from transformers import AutoTokenizer, pipeline
from optimum.onnxruntime import ORTModelForFeatureExtraction
from semantic_router.splitters import RollingWindowSplitter

model_path = "/apps/data/gte-base/onnx"
model = ORTModelForFeatureExtraction.from_pretrained(model_path, file_name="model.onnx")
tokenizer = AutoTokenizer.from_pretrained(model_path)

embedder = pipeline("feature-extraction", model=model, tokenizer=tokenizer)

splitter = RollingWindowSplitter(
encoder=embedder,
dynamic_threshold=True,
min_split_tokens=75,
max_split_tokens=365,
window_size=3, # Adjust based on your requirements
plot_splits=False, # Set to True to visualize chunking
enable_statistics=False # Set to True to print chunking stats
)

text = "Your long text document goes here."

chunks = splitter(text)

for i, chunk in enumerate(chunks):
print(f"Chunk {i+1}: {chunk}")

*RETURNS this error:

splitter = RollingWindowSplitter(
Traceback (most recent call last):
File "/apps/data/test.py", line 14, in
splitter = RollingWindowSplitter(
File "/apps/data/.venv/lib64/python3.9/site-packages/semantic_router/splitters/rolling_window.py", line 60, in init
super().init(name=name, encoder=encoder)
File "/apps/data/.venv/lib64/python3.9/site-packages/pydantic/v1/main.py", line 341, in init
raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for RollingWindowSplitter
encoder
value is not a valid dict (type=type_error.dict)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant