Skip to content

Commit

Permalink
Revise docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yzhangcs committed Jul 23, 2021
1 parent d6bf471 commit 7fbeb5a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='supar',
version='1.1.1',
version='1.1.2',
author='Yu Zhang',
author_email='yzhang.cs@outlook.com',
description='Syntactic/Semantic Parsing Models',
Expand Down
8 changes: 4 additions & 4 deletions supar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'VISemanticDependencyParser',
'Parser']

__version__ = '1.1.1'
__version__ = '1.1.2'

PARSER = {parser.NAME: parser for parser in [BiaffineDependencyParser,
CRFDependencyParser,
Expand All @@ -28,7 +28,7 @@
VISemanticDependencyParser]}

SRC = {'github': 'https://github.com/yzhangcs/parser/releases/download',
'hlt': 'http://hlt.suda.edu.cn/LA/yzhang/supar'}
'hlt': 'http://hlt.suda.edu.cn/~yzhang/supar'}
NAME = {
'biaffine-dep-en': 'ptb.biaffine.dep.lstm.char',
'biaffine-dep-zh': 'ctb7.biaffine.dep.lstm.char',
Expand All @@ -49,5 +49,5 @@
'vi-sdp-roberta-en': 'dm.vi.sdp.roberta',
'vi-sdp-electra-zh': 'semeval16.vi.sdp.electra'
}
MODEL = {n: f"{SRC['github']}/v1.1.0/{m}.zip" for n, m in NAME.items()}
CONFIG = {n: f"{SRC['github']}/v1.1.0/{m}.ini" for n, m in NAME.items()}
MODEL = {src: {n: f"{link}/v1.1.0/{m}.zip" for n, m in NAME.items()} for src, link in SRC.items()}
CONFIG = {src: {n: f"{link}/v1.1.0/{m}.ini" for n, m in NAME.items()} for src, link in SRC.items()}
8 changes: 4 additions & 4 deletions supar/models/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def loss(self, s_span, s_label, charts, mask, mbr=True):
s_span (~torch.Tensor): ``[batch_size, seq_len, seq_len]``.
Scores of all constituents.
s_label (~torch.Tensor): ``[batch_size, seq_len, seq_len, n_labels]``.
Scores of all labels on each constituent.
Scores of all constituent labels.
charts (~torch.LongTensor): ``[batch_size, seq_len, seq_len]``.
The tensor of gold-standard labels. Positions without labels are filled with -1.
mask (~torch.BoolTensor): ``[batch_size, seq_len, seq_len]``.
Expand All @@ -204,7 +204,7 @@ def decode(self, s_span, s_label, mask):
s_span (~torch.Tensor): ``[batch_size, seq_len, seq_len]``.
Scores of all constituents.
s_label (~torch.Tensor): ``[batch_size, seq_len, seq_len, n_labels]``.
Scores of all labels on each constituent.
Scores of all constituent labels.
mask (~torch.BoolTensor): ``[batch_size, seq_len, seq_len]``.
The mask for covering the unpadded tokens in each chart.
Expand Down Expand Up @@ -406,7 +406,7 @@ def loss(self, s_span, s_pair, s_label, charts, mask):
s_pair (~torch.Tensor): ``[batch_size, seq_len, seq_len, seq_len]``.
Scores of second-order triples.
s_label (~torch.Tensor): ``[batch_size, seq_len, seq_len, n_labels]``.
Scores of all labels on each constituent.
Scores of all constituent labels.
charts (~torch.LongTensor): ``[batch_size, seq_len, seq_len]``.
The tensor of gold-standard labels. Positions without labels are filled with -1.
mask (~torch.BoolTensor): ``[batch_size, seq_len, seq_len]``.
Expand All @@ -430,7 +430,7 @@ def decode(self, s_span, s_label, mask):
s_span (~torch.Tensor): ``[batch_size, seq_len, seq_len]``.
Scores of all constituents.
s_label (~torch.Tensor): ``[batch_size, seq_len, seq_len, n_labels]``.
Scores of all labels on each constituent.
Scores of all constituent labels.
mask (~torch.BoolTensor): ``[batch_size, seq_len, seq_len]``.
The mask for covering the unpadded tokens in each chart.
Expand Down
10 changes: 3 additions & 7 deletions supar/parsers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def build(cls, path, **kwargs):
raise NotImplementedError

@classmethod
def load(cls, path, reload=False, src=None, checkpoint=False, **kwargs):
def load(cls, path, reload=False, src='github', checkpoint=False, **kwargs):
r"""
Loads a parser with data fields and pretrained model parameters.
Expand All @@ -176,7 +176,7 @@ def load(cls, path, reload=False, src=None, checkpoint=False, **kwargs):
Specifies where to download the model.
``'github'``: github release page.
``'hlt'``: hlt homepage, only accessible from 9:00 to 18:00 (UTC+8).
Default: None.
Default: ``'github'``.
checkpoint (bool):
If ``True``, loads all checkpoint states to restore the training process. Default: ``False``.
kwargs (dict):
Expand All @@ -190,11 +190,7 @@ def load(cls, path, reload=False, src=None, checkpoint=False, **kwargs):

args = Config(**locals())
args.device = 'cuda' if torch.cuda.is_available() else 'cpu'
if src is not None:
links = {n: f"{supar.SRC[src]}/v{supar.__version__}/{m}.zip" for n, m in supar.NAME.items()}
else:
links = supar.MODEL
state = torch.load(path if os.path.exists(path) else download(links.get(path, path), reload=reload))
state = torch.load(path if os.path.exists(path) else download(supar.MODEL[src].get(path, path), reload=reload))
cls = supar.PARSER[state['name']] if cls.NAME is None else cls
args = state['args'].update(args)
model = cls.MODEL(**args)
Expand Down
2 changes: 1 addition & 1 deletion supar/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def pop(self, key, val=None):
@classmethod
def load(cls, conf='', unknown=None, **kwargs):
config = ConfigParser()
config.read(conf if not conf or os.path.exists(conf) else download(supar.CONFIG.get(conf, conf)))
config.read(conf if not conf or os.path.exists(conf) else download(supar.CONFIG['github'].get(conf, conf)))
config = dict((name, literal_eval(value))
for section in config.sections()
for name, value in config.items(section))
Expand Down
4 changes: 2 additions & 2 deletions supar/utils/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,13 +542,13 @@ def build(cls, tree, sequence):
Args:
tree (nltk.tree.Tree):
An empty tree that provides a base for building a result tree.
An empty tree that provides a base for building a resulting tree.
sequence (list[tuple]):
A list of tuples used for generating a tree.
Each tuple consits of the indices of left/right boundaries and label of the constituent.
Returns:
A result constituency tree.
A resulting constituency tree.
Examples:
>>> tree = Tree.totree(['She', 'enjoys', 'playing', 'tennis', '.'], 'TOP')
Expand Down

0 comments on commit 7fbeb5a

Please sign in to comment.