Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Semantic Router
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
aurelio-labs
Semantic Router
Commits
ff2c3ca6
Commit
ff2c3ca6
authored
3 months ago
by
jamescalam
Browse files
Options
Downloads
Patches
Plain Diff
chore: remove print
parent
981b0390
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
semantic_router/encoders/tfidf.py
+0
-2
0 additions, 2 deletions
semantic_router/encoders/tfidf.py
semantic_router/routers/hybrid.py
+0
-12
0 additions, 12 deletions
semantic_router/routers/hybrid.py
tests/unit/test_hybrid_layer.py
+0
-2
0 additions, 2 deletions
tests/unit/test_hybrid_layer.py
with
0 additions
and
16 deletions
semantic_router/encoders/tfidf.py
+
0
−
2
View file @
ff2c3ca6
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
semantic_router/routers/hybrid.py
+
0
−
12
View file @
ff2c3ca6
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
tests/unit/test_hybrid_layer.py
+
0
−
2
View file @
ff2c3ca6
...
@@ -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
"
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment