Skip to content
Snippets Groups Projects
Commit ff2c3ca6 authored by jamescalam's avatar jamescalam
Browse files

chore: remove print

parent 981b0390
No related branches found
No related tags found
No related merge requests found
...@@ -53,13 +53,11 @@ class TfidfEncoder(SparseEncoder): ...@@ -53,13 +53,11 @@ class TfidfEncoder(SparseEncoder):
raise TypeError("`routes` parameter must be a list of Route objects.") raise TypeError("`routes` parameter must be a list of Route objects.")
def _build_word_index(self, docs: List[str]) -> Dict: def _build_word_index(self, docs: List[str]) -> Dict:
print(docs)
words = set() words = set()
for doc in docs: for doc in docs:
for word in doc.split(): for word in doc.split():
words.add(word) words.add(word)
word_index = {word: i for i, word in enumerate(words)} word_index = {word: i for i, word in enumerate(words)}
print(word_index)
return word_index return word_index
def _compute_tf(self, docs: List[str]) -> np.ndarray: def _compute_tf(self, docs: List[str]) -> np.ndarray:
......
...@@ -37,13 +37,10 @@ class HybridRouter(BaseRouter): ...@@ -37,13 +37,10 @@ class HybridRouter(BaseRouter):
auto_sync: Optional[str] = None, auto_sync: Optional[str] = None,
alpha: float = 0.3, alpha: float = 0.3,
): ):
print("...2.1")
if index is None: if index is None:
logger.warning("No index provided. Using default HybridLocalIndex.") logger.warning("No index provided. Using default HybridLocalIndex.")
index = HybridLocalIndex() index = HybridLocalIndex()
print("...2.2")
encoder = self._get_encoder(encoder=encoder) encoder = self._get_encoder(encoder=encoder)
print("...2.3")
super().__init__( super().__init__(
encoder=encoder, encoder=encoder,
llm=llm, llm=llm,
...@@ -53,22 +50,17 @@ class HybridRouter(BaseRouter): ...@@ -53,22 +50,17 @@ class HybridRouter(BaseRouter):
aggregation=aggregation, aggregation=aggregation,
auto_sync=auto_sync, auto_sync=auto_sync,
) )
print("...0")
# initialize sparse encoder # initialize sparse encoder
self.sparse_encoder = self._get_sparse_encoder(sparse_encoder=sparse_encoder) self.sparse_encoder = self._get_sparse_encoder(sparse_encoder=sparse_encoder)
print("...5")
# set alpha # set alpha
self.alpha = alpha self.alpha = alpha
print("...6")
# fit sparse encoder if needed # fit sparse encoder if needed
if ( if (
isinstance(self.sparse_encoder, TfidfEncoder) isinstance(self.sparse_encoder, TfidfEncoder)
and hasattr(self.sparse_encoder, "fit") and hasattr(self.sparse_encoder, "fit")
and self.routes and self.routes
): ):
print("...3")
self.sparse_encoder.fit(self.routes) self.sparse_encoder.fit(self.routes)
print("...4")
# run initialize index now if auto sync is active # run initialize index now if auto sync is active
if self.auto_sync: if self.auto_sync:
self._init_index_state() self._init_index_state()
...@@ -94,7 +86,6 @@ class HybridRouter(BaseRouter): ...@@ -94,7 +86,6 @@ class HybridRouter(BaseRouter):
# TODO: to merge, self._encode should probably output a special # TODO: to merge, self._encode should probably output a special
# TODO Embedding type that can be either dense or hybrid # TODO Embedding type that can be either dense or hybrid
dense_emb, sparse_emb = self._encode(all_utterances) dense_emb, sparse_emb = self._encode(all_utterances)
print(f"{sparse_emb=}")
self.index.add( self.index.add(
embeddings=dense_emb.tolist(), embeddings=dense_emb.tolist(),
routes=route_names, routes=route_names,
...@@ -180,8 +171,6 @@ class HybridRouter(BaseRouter): ...@@ -180,8 +171,6 @@ class HybridRouter(BaseRouter):
xq_s = self.sparse_encoder(text) xq_s = self.sparse_encoder(text)
# xq_s = np.squeeze(xq_s) # xq_s = np.squeeze(xq_s)
# convex scaling # convex scaling
print(f"{self.sparse_encoder.__class__.__name__=}")
print(f"_encode: {xq_d.shape=}, {xq_s=}")
xq_d, xq_s = self._convex_scaling(dense=xq_d, sparse=xq_s) xq_d, xq_s = self._convex_scaling(dense=xq_d, sparse=xq_s)
return xq_d, xq_s return xq_d, xq_s
...@@ -202,7 +191,6 @@ class HybridRouter(BaseRouter): ...@@ -202,7 +191,6 @@ class HybridRouter(BaseRouter):
# create dense query vector # create dense query vector
xq_d = np.array(dense_vec) xq_d = np.array(dense_vec)
# convex scaling # convex scaling
print(f"_async_encode: {xq_d.shape=}, {xq_s=}")
xq_d, xq_s = self._convex_scaling(dense=xq_d, sparse=xq_s) xq_d, xq_s = self._convex_scaling(dense=xq_d, sparse=xq_s)
return xq_d, xq_s return xq_d, xq_s
......
...@@ -146,14 +146,12 @@ class TestHybridRouter: ...@@ -146,14 +146,12 @@ class TestHybridRouter:
assert len(route_layer.routes) == 2, "route_layer.routes is not 2" assert len(route_layer.routes) == 2, "route_layer.routes is not 2"
def test_query_and_classification(self, openai_encoder, routes): def test_query_and_classification(self, openai_encoder, routes):
print("...1")
route_layer = HybridRouter( route_layer = HybridRouter(
encoder=openai_encoder, encoder=openai_encoder,
sparse_encoder=sparse_encoder, sparse_encoder=sparse_encoder,
routes=routes, routes=routes,
auto_sync="local", auto_sync="local",
) )
print("...2")
route_layer.set_threshold(0.0) route_layer.set_threshold(0.0)
query_result = route_layer(UTTERANCES[0]) query_result = route_layer(UTTERANCES[0])
assert query_result.name in ["Route 1", "Route 2"] assert query_result.name in ["Route 1", "Route 2"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment