Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ Note: as the model is not being re-trained, but uses the training data during in

### Dynamic Few-Shot Text Classification

*To use this feature, you need to install `annoy` library:*

```bash
pip install scikit-llm[annoy]
```

`DynamicFewShotGPTClassifier` dynamically selects N samples per class to include in the prompt. This allows the few-shot classifier to scale to datasets that are too large for the standard context window of LLMs.

*How does it work?*
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ dependencies = [
"pandas>=1.5.0",
"openai>=0.27.0",
"tqdm>=4.60.0",
"annoy>=1.17.2",
"google-cloud-aiplatform>=1.27.0"
]
name = "scikit-llm"
version = "0.3.3"
version = "0.3.4"
authors = [
{ name="Oleg Kostromin", email="kostromin97@gmail.com" },
{ name="Iryna Kondrashchenko", email="iryna230520@gmail.com" },
Expand All @@ -29,6 +28,7 @@ classifiers = [

[project.optional-dependencies]
gpt4all = ["gpt4all>=1.0.0"]
annoy = ["annoy>=1.17.2"]

[tool.ruff]
select = [
Expand Down
10 changes: 9 additions & 1 deletion skllm/memory/_annoy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import tempfile
from typing import Any, List

from annoy import AnnoyIndex
try:
from annoy import AnnoyIndex
except (ImportError, ModuleNotFoundError):
AnnoyIndex = None

from numpy import ndarray

from skllm.memory.base import _BaseMemoryIndex
Expand All @@ -20,6 +24,10 @@ class AnnoyMemoryIndex(_BaseMemoryIndex):
"""

def __init__(self, dim: int, metric: str = "euclidean", **kwargs: Any) -> None:
if AnnoyIndex is None:
raise ImportError(
"Annoy is not installed. Please install annoy by running `pip install scikit-llm[annoy]`."
)
self._index = AnnoyIndex(dim, metric)
self.metric = metric
self.dim = dim
Expand Down