Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
strategy_embedding
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rank
strategy_embedding
Commits
279f2323
Commit
279f2323
authored
Nov 24, 2020
by
赵威
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
write data
parent
e337d89f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
answer_similarity.py
doc_similarity/answer_similarity.py
+6
-3
No files found.
doc_similarity/answer_similarity.py
View file @
279f2323
import
json
import
os
import
random
import
sys
...
...
@@ -7,7 +8,9 @@ sys.path.append(os.path.realpath("."))
import
faiss
import
numpy
as
np
from
bert_serving.client
import
BertClient
from
utils.cache
import
redis_client_db
from
utils.es
import
es_scan
,
get_answer_info_from_es
from
utils.files
import
MODEL_PATH
def
cos_sim
(
vector_a
,
vector_b
):
...
...
@@ -52,6 +55,8 @@ if __name__ == "__main__":
level_dict
[
content_level
]
.
append
(
id
)
embedding_dict
[
id
]
=
bc
.
encode
([
content
])
.
tolist
()[
0
]
redis_client_db
.
hmset
(
"answer:level_dict"
,
json
.
dumps
(
level_dict
))
tmp_tuple
=
random
.
choice
(
list
(
embedding_dict
.
items
()))
print
(
tmp_tuple
)
answer_ids
=
np
.
array
(
list
(
embedding_dict
.
keys
()))
.
astype
(
"int"
)
...
...
@@ -66,9 +71,7 @@ if __name__ == "__main__":
print
(
"trained: "
+
str
(
index2
.
is_trained
))
print
(
"total index: "
+
str
(
index2
.
ntotal
))
base_dir
=
os
.
getcwd
()
model_dir
=
os
.
path
.
join
(
base_dir
,
"_models"
)
index_path
=
os
.
path
.
join
(
model_dir
,
"faiss_answer_similarity.index"
)
index_path
=
os
.
path
.
join
(
MODEL_PATH
,
"faiss_answer_similarity.index"
)
faiss
.
write_index
(
index2
,
index_path
)
print
(
index_path
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment