Skip to content

Commit

Permalink
Quiet logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
attardi committed Oct 18, 2020
1 parent 4290b00 commit b973fd4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
19 changes: 8 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ else ifeq ($(LANG), fr)
else ifeq ($(LANG), it)
CORPUS=it_isdt
RES2=Italian-ISDT
MODEL = --bert= dbmdz/bert-base-italian-xxl-cased
MODEL = --bert=dbmdz/bert-base-italian-xxl-cased
BERT = dbmdz-xxl
else ifeq ($(LANG), lt)
CORPUS=lt_alksnis
Expand Down Expand Up @@ -146,9 +146,11 @@ endif
.PRECIOUS: exp/$(LANG)-$(FEAT)$(VER)/model

# relate LANG to CORPUS
exp/$(LANG)%: exp/$(CORPUS).$(BERT)%
exp/$(LANG)%: exp/$(CORPUS).$(BERT)$(VER)%
@:

TARGET=exp/$(CORPUS).$(BERT)$(VER)

exp/$(CORPUS).$(BERT)$(VER)/model:
python -u -m diaparser.cmds.biaffine_dependency train -d=$(GPU) -p=$@ \
-c=$(CONFIG) $(MODEL) $(ATTN) \
Expand All @@ -161,11 +163,6 @@ exp/$(CORPUS).$(BERT)$(VER).test.conllu: exp/$(CORPUS).$(BERT)$(VER)/model
--pred=$@
python $(CORPUS_DIR)/fix-root.py $@

exp/$(CORPUS).$(BERT)$(VER).test.time: exp/$(CORPUS).$(BERT)$(VER)/model
( time python -m diaparser.cmds.biaffine_dependency predict -d=$(GPU) -p=$< --feat=$(FEAT) --tree \
$(BLIND_TEST) \
--pred=/dev/null; ) &> $@

LANGS=ar bg cs en et fi fr it lt lv nl pl ru sk sv ta uk
LANGS1=ar bg en et fi sk
LANGS2=fr it ru ta uk sv
Expand All @@ -184,16 +181,16 @@ train:
# ----------------------------------------------------------------------
# Evaluation

%.test.nen.conllu: %.test.conllu
$(TARGET).test.nen.conllu: $(TARGET).test.conllu
perl $(UD_TOOLS)/enhanced_collapse_empty_nodes.pl $< > $@

%.test.eval: %.test.nen.conllu
$(TARGET).test.eval: $(TARGET).test.nen.conllu
python $(UD_TOOLS)/iwpt20_xud_eval.py -v $(UD_TOOLS)/../test-gold/$(LANG).nen.conllu $< > $@

%.test.evalb: %.test.eval
$(TARGET).test.evalb: $(TARGET).test.eval
python $(CORPUS_DIR)/eval.py -g $(GOLD_TEST) -s $@ --evalb

%.test.eval07: %.test.conllu
$(TARGET).test.eval07: $(TARGET).test.conllu
perl $(CORPUS_DIR)/eval07.pl -p -q -g $(GOLD_TEST) -s $< > $@

evaluate:
Expand Down
4 changes: 2 additions & 2 deletions diaparser/cmds/biaffine_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ..parsers import BiaffineDependencyParser
from .cmd import parse

import os

def main():
parser = argparse.ArgumentParser(description='Create Biaffine Dependency Parser.')
Expand Down Expand Up @@ -45,7 +45,7 @@ def main():
subparser.add_argument('--pred', default='pred.conllx', help='path to predicted result')
subparser.add_argument('--text', metavar='LANGUAGE', default=None,
help='parse plain text in the given language rather than CoNLL-U files.')
subparser.add_argument('--cache-dir', default='~/.cache/parser',
subparser.add_argument('--cache-dir', default=os.path.expanduser('~/.cache/diaparser'),
help='path to saved parser/tokenizer models')
parse(parser)

Expand Down
2 changes: 1 addition & 1 deletion diaparser/cmds/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def parse(argparser):
torch.set_num_threads(args.threads)
torch.manual_seed(args.seed)
init_device(args.device)
init_logger(logger, f"{args.path}.{args.mode}.log")
init_logger(logger, f"{args.path}.{args.mode}.log", verbose=args.verbose)
logger.info('Configuration:\n' + str(args))

if args.mode == 'train':
Expand Down
9 changes: 5 additions & 4 deletions tokenizer/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ def format(self, sentences):
"""
Convert sentences to TSV format.
"""
empty_fields = '\t_' * 8
for i, sentence in enumerate(sentences):
yield f'# sent_id = {i+1}'
sent_text = sentence.text.replace("\n", " ")
yield f'# text = {sent_text}'
for token in sentence.tokens:
# multiword
if len(token.words) > 1:
token_ids = '-'.join([str(id) for id in token.id])
yield f'{token_ids}\t{token.text}'
token_range = f'{token.id[0]}-{token.id[-1]}'
yield f'{token_range}\t{token.text + empty_fields}'
for word in token.words:
yield f'{word.id}\t{word.text}'
yield f'{word.id}\t{word.text + empty_fields}'
else:
yield f'{token.id[0]}\t{token.text}'
yield f'{token.id[0]}\t{token.text + empty_fields}'
yield ''

def reader(self):
Expand Down

0 comments on commit b973fd4

Please sign in to comment.