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
7abb86d5
Commit
7abb86d5
authored
1 year ago
by
Ismail Ashraq
Browse files
Options
Downloads
Patches
Plain Diff
make default bm25 params optional
parent
a558eabb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
semantic_router/encoders/bm25.py
+15
-3
15 additions, 3 deletions
semantic_router/encoders/bm25.py
with
15 additions
and
3 deletions
semantic_router/encoders/bm25.py
+
15
−
3
View file @
7abb86d5
...
@@ -9,7 +9,12 @@ class BM25Encoder(BaseEncoder):
...
@@ -9,7 +9,12 @@ class BM25Encoder(BaseEncoder):
idx_mapping
:
dict
[
int
,
int
]
|
None
=
None
idx_mapping
:
dict
[
int
,
int
]
|
None
=
None
type
:
str
=
"
sparse
"
type
:
str
=
"
sparse
"
def
__init__
(
self
,
name
:
str
=
"
bm25
"
,
score_threshold
:
float
=
0.82
):
def
__init__
(
self
,
name
:
str
=
"
bm25
"
,
score_threshold
:
float
=
0.82
,
use_default_params
:
bool
=
True
,
):
super
().
__init__
(
name
=
name
,
score_threshold
=
score_threshold
)
super
().
__init__
(
name
=
name
,
score_threshold
=
score_threshold
)
try
:
try
:
from
pinecone_text.sparse
import
BM25Encoder
as
encoder
from
pinecone_text.sparse
import
BM25Encoder
as
encoder
...
@@ -18,9 +23,15 @@ class BM25Encoder(BaseEncoder):
...
@@ -18,9 +23,15 @@ class BM25Encoder(BaseEncoder):
"
Please install pinecone-text to use BM25Encoder.
"
"
Please install pinecone-text to use BM25Encoder.
"
"
You can install it with: `pip install semantic-router[hybrid]`
"
"
You can install it with: `pip install semantic-router[hybrid]`
"
)
)
logger
.
info
(
"
Downloading and initializing BM25 model parameters.
"
)
self
.
model
=
encoder
.
default
()
self
.
model
=
encoder
()
if
use_default_params
:
logger
.
info
(
"
Downloading and initializing default sBM25 model parameters.
"
)
self
.
model
=
encoder
.
default
()
self
.
_set_idx_mapping
()
def
_set_idx_mapping
(
self
):
params
=
self
.
model
.
get_params
()
params
=
self
.
model
.
get_params
()
doc_freq
=
params
[
"
doc_freq
"
]
doc_freq
=
params
[
"
doc_freq
"
]
if
isinstance
(
doc_freq
,
dict
):
if
isinstance
(
doc_freq
,
dict
):
...
@@ -53,3 +64,4 @@ class BM25Encoder(BaseEncoder):
...
@@ -53,3 +64,4 @@ class BM25Encoder(BaseEncoder):
if
self
.
model
is
None
:
if
self
.
model
is
None
:
raise
ValueError
(
"
Model is not initialized.
"
)
raise
ValueError
(
"
Model is not initialized.
"
)
self
.
model
.
fit
(
docs
)
self
.
model
.
fit
(
docs
)
self
.
_set_idx_mapping
()
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