Skip to content

Commit

Permalink
fix: embedder tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
ajithvcoder committed Dec 12, 2024
1 parent 7137548 commit bb7cc10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
8 changes: 4 additions & 4 deletions docs/source/tutorials/embedder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ If we want to decreate the embedding dimension to only 256 to save memory, we ca

.. code-block:: python
from adalflow.core.types import Embedding
from adalflow.core.types import Embedding, EmbedderOutput
from adalflow.core.functional import normalize_vector
from typing import List
from adalflow.core.component import Component
Expand All @@ -139,14 +139,14 @@ If we want to decreate the embedding dimension to only 256 to save memory, we ca
assert self.new_dim < self.old_dim, "new_dim should be less than old_dim"
def call(self, input: List[Embedding]) -> List[Embedding]:
output: List[Embedding] = deepcopy(input)
for embedding in output:
output: EmbedderOutput = deepcopy(input)
for embedding in output.data:
old_embedding = embedding.embedding
new_embedding = old_embedding[: self.new_dim]
if self.normalize:
new_embedding = normalize_vector(new_embedding)
embedding.embedding = new_embedding
return output
return output.data
def _extra_repr(self) -> str:
repr_str = f"old_dim={self.old_dim}, new_dim={self.new_dim}, normalize={self.normalize}"
Expand Down
14 changes: 5 additions & 9 deletions tutorials/embedder.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,11 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from adalflow.core.types import Embedding\n",
"from adalflow.core.types import Embedding, EmbedderOutput\n",
"from adalflow.core.functional import normalize_vector\n",
"from typing import List\n",
"from adalflow.core.component import Component\n",
Expand All @@ -517,18 +517,14 @@
" assert self.new_dim < self.old_dim, \"new_dim should be less than old_dim\"\n",
"\n",
" def call(self, input: List[Embedding]) -> List[Embedding]:\n",
" output: List[Embedding] = deepcopy(input)\n",
" for embedding in output:\n",
" output: EmbedderOutput = deepcopy(input)\n",
" for embedding in output.data:\n",
" old_embedding = embedding.embedding\n",
" new_embedding = old_embedding[: self.new_dim]\n",
" if self.normalize:\n",
" new_embedding = normalize_vector(new_embedding)\n",
" embedding.embedding = new_embedding\n",
" return output\n",
" \n",
" def _extra_repr(self) -> str:\n",
" repr_str = f\"old_dim={self.old_dim}, new_dim={self.new_dim}, normalize={self.normalize}\"\n",
" return repr_str"
" return output.data"
]
},
{
Expand Down

0 comments on commit bb7cc10

Please sign in to comment.