|
148 | 148 | "source": [ |
149 | 149 | "from adalflow.core.embedder import Embedder\n", |
150 | 150 | "from adalflow.components.model_client import TransformersClient\n", |
| 151 | + "\n", |
151 | 152 | "# from adalflow.utils import enable_library_logging\n", |
152 | 153 | "\n", |
153 | 154 | "# enable_library_logging(level=\"DEBUG\")\n", |
|
499 | 500 | }, |
500 | 501 | { |
501 | 502 | "cell_type": "code", |
502 | | - "execution_count": null, |
| 503 | + "execution_count": 29, |
503 | 504 | "metadata": {}, |
504 | 505 | "outputs": [], |
505 | 506 | "source": [ |
506 | | - "from adalflow.core.types import Embedding, EmbedderOutput\n", |
| 507 | + "from adalflow.core.types import Embedding\n", |
507 | 508 | "from adalflow.core.functional import normalize_vector\n", |
508 | 509 | "from typing import List\n", |
509 | 510 | "from adalflow.core.component import Component\n", |
510 | 511 | "from copy import deepcopy\n", |
| 512 | + "\n", |
| 513 | + "\n", |
511 | 514 | "class DecreaseEmbeddingDim(Component):\n", |
512 | | - " def __init__(self, old_dim: int, new_dim: int, normalize: bool = True):\n", |
| 515 | + " def __init__(self, old_dim: int, new_dim: int, normalize: bool = True):\n", |
513 | 516 | " super().__init__()\n", |
514 | 517 | " self.old_dim = old_dim\n", |
515 | 518 | " self.new_dim = new_dim\n", |
516 | 519 | " self.normalize = normalize\n", |
517 | 520 | " assert self.new_dim < self.old_dim, \"new_dim should be less than old_dim\"\n", |
518 | 521 | "\n", |
519 | 522 | " def call(self, input: List[Embedding]) -> List[Embedding]:\n", |
520 | | - " output: EmbedderOutput = deepcopy(input)\n", |
521 | | - " for embedding in output.data:\n", |
| 523 | + " output: List[Embedding] = deepcopy(input)\n", |
| 524 | + " for embedding in output:\n", |
522 | 525 | " old_embedding = embedding.embedding\n", |
523 | 526 | " new_embedding = old_embedding[: self.new_dim]\n", |
524 | 527 | " if self.normalize:\n", |
525 | 528 | " new_embedding = normalize_vector(new_embedding)\n", |
526 | 529 | " embedding.embedding = new_embedding\n", |
527 | | - " return output.data" |
| 530 | + " return output\n", |
| 531 | + "\n", |
| 532 | + " def _extra_repr(self) -> str:\n", |
| 533 | + " repr_str = f\"old_dim={self.old_dim}, new_dim={self.new_dim}, normalize={self.normalize}\"\n", |
| 534 | + " return repr_str" |
528 | 535 | ] |
529 | 536 | }, |
530 | 537 | { |
|
0 commit comments