-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c90d4e0
commit 83af3f0
Showing
13 changed files
with
2,148 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import sys | ||
import os | ||
try: | ||
import cPickle as pickle | ||
except ImportError: | ||
import pickle | ||
|
||
|
||
class Memoize(object): | ||
def __init__(self, f): | ||
self.f = f | ||
self.cache = {} | ||
|
||
def __call__(self, *args): | ||
if args not in self.cache: | ||
self.cache[args] = self.f(*args) | ||
return self.cache[args] | ||
|
||
def load_pickle(path, memoized=True): | ||
return _load_pickle_memoize(path) if memoized else _load_pickle(path) | ||
|
||
def _load_pickle(path): | ||
with open(path, 'rb') as f: | ||
return pickle.load(f) | ||
|
||
@Memoize | ||
def _load_pickle_memoize(path): | ||
return _load_pickle(path) | ||
|
||
|
||
def write_pickle(o, path): | ||
dir = path.rsplit('/', 1)[0] | ||
if not os.path.exists(dir): | ||
os.mkdir(dir) | ||
with open(path, 'wb') as f: | ||
pickle.dump(o, f, -1) | ||
|
||
def log(*args): | ||
msg = ' '.join(map(str, args)) | ||
sys.stdout.write(msg + '\n') | ||
sys.stdout.flush() | ||
|
||
|
||
def heading(*args): | ||
log() | ||
log(80 * '=') | ||
log(*args) | ||
log(80 * '=') | ||
|
||
|
||
import torch | ||
def print_rank_0(message, **kwargs): | ||
"""If distributed is initialized print only on rank 0.""" | ||
# if torch.distributed.is_initialized(): | ||
# if torch.distributed.get_rank() == 0: | ||
# print(message, flush=True, **kwargs) | ||
# else: | ||
# print(message, flush=True, **kwargs) | ||
print(message, flush=True, **kwargs) | ||
def is_rank_0(): | ||
# if torch.distributed.is_initialized(): | ||
# if torch.distributed.get_rank() == 0: | ||
# return True | ||
# else: | ||
# return True | ||
# return False | ||
return True |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from relogic.logickit.modules.span_extractors.endpoint_span_extractor import EndpointSpanExtractor | ||
from relogic.logickit.modules.span_extractors.self_attentive_span_extractor import SelfAttentiveSpanExtractor | ||
from relogic.logickit.modules.span_extractors.attentive_span_extractor import AttentiveSpanExtractor |
Oops, something went wrong.