Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Megatron-LM
Commits
3fb02b8e
Commit
3fb02b8e
authored
Apr 21, 2020
by
Neel Kant
Browse files
HashedIndex.load_from_file
parent
1b44a4c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletion
+12
-1
hashed_index.py
hashed_index.py
+12
-1
No files found.
hashed_index.py
View file @
3fb02b8e
...
@@ -101,6 +101,17 @@ class HashedIndex(object):
...
@@ -101,6 +101,17 @@ class HashedIndex(object):
self
.
block_data
=
defaultdict
(
list
)
self
.
block_data
=
defaultdict
(
list
)
self
.
hash_data
=
defaultdict
(
list
)
self
.
hash_data
=
defaultdict
(
list
)
@
classmethod
def
load_from_file
(
cls
,
fname
):
state_dict
=
pickle
.
load
(
open
(
fname
,
'rb'
))
hash_matrix
=
state_dict
[
'hash_matrix'
]
new_index
=
HashedIndex
(
hash_matrix
.
shape
[
0
],
hash_matrix
.
shape
[
1
]
*
2
)
new_index
.
block_data
=
state_dict
[
'block_data'
]
new_index
.
hash_data
=
state_dict
[
'hash_data'
]
new_index
.
hash_matrix
=
hash_matrix
return
new_index
def
test_retriever
():
def
test_retriever
():
initialize_megatron
(
extra_args_provider
=
None
,
initialize_megatron
(
extra_args_provider
=
None
,
...
@@ -108,7 +119,7 @@ def test_retriever():
...
@@ -108,7 +119,7 @@ def test_retriever():
model
=
load_checkpoint
()
model
=
load_checkpoint
()
model
.
eval
()
model
.
eval
()
dataset
=
get_dataset
()
dataset
=
get_dataset
()
hashed_index
=
HashedIndex
(
embed_size
=
128
,
num_buckets
=
2048
)
hashed_index
=
HashedIndex
.
load_from_file
(
'block_hash_data.pkl'
)
retriever
=
REALMRetriever
(
model
,
dataset
,
hashed_index
)
retriever
=
REALMRetriever
(
model
,
dataset
,
hashed_index
)
retriever
.
retrieve_evidence_blocks_text
(
"The last monarch from the house of windsor"
)
retriever
.
retrieve_evidence_blocks_text
(
"The last monarch from the house of windsor"
)
...
...
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