Skip to content
Snippets Groups Projects
Commit 543b5ae9 authored by jezozwierzak's avatar jezozwierzak
Browse files

Added option --with-heads

parent e2ebf2b5
No related branches found
No related tags found
No related merge requests found
...@@ -163,7 +163,7 @@ class Chunker: ...@@ -163,7 +163,7 @@ class Chunker:
else: else:
non_O_chan = chan_name non_O_chan = chan_name
non_O_tag = there_iob non_O_tag = there_iob
if chan.is_head_at(tok_idx): if self.with_heads and chan.is_head_at(tok_idx):
non_O_chan += '-H' non_O_chan += '-H'
# B-NP, I-VP etc. or O # B-NP, I-VP etc. or O
class_label = 'O' if non_O_chan is None else '%s-%s' % (non_O_tag, non_O_chan) class_label = 'O' if non_O_chan is None else '%s-%s' % (non_O_tag, non_O_chan)
...@@ -234,7 +234,7 @@ class Chunker: ...@@ -234,7 +234,7 @@ class Chunker:
# TODO: rename the from_string in corpus2 and fix it here # TODO: rename the from_string in corpus2 and fix it here
tag_to_set = 'O' if chan_name != non_O_chan else non_O_tag tag_to_set = 'O' if chan_name != non_O_chan else non_O_tag
chan.set_iob_at(tok_idx, corpus2.from_string(tag_to_set)) chan.set_iob_at(tok_idx, corpus2.from_string(tag_to_set))
if tag_to_set != 'O' and is_head: if tag_to_set != 'O' and is_head and self.with_heads:
chan.set_head_at(tok_idx, True) chan.set_head_at(tok_idx, True)
# switch back to segments # switch back to segments
for chan_name in chans: for chan_name in chans:
......
...@@ -64,6 +64,9 @@ def go(): ...@@ -64,6 +64,9 @@ def go():
parser.add_option('-v', '--verbose', action='store_true', parser.add_option('-v', '--verbose', action='store_true',
dest='verbose', default=False, dest='verbose', default=False,
help='verbose mode') help='verbose mode')
parser.add_option('--with-heads', action='store_true',
dest='with_heads', default=False,
help='Training or chunking with heads mode.')
parser.add_option('--train', action='store_true', parser.add_option('--train', action='store_true',
dest='is_training', help='train the chunker') dest='is_training', help='train the chunker')
parser.add_option('--batch', action='store_true', parser.add_option('--batch', action='store_true',
...@@ -78,7 +81,7 @@ def go(): ...@@ -78,7 +81,7 @@ def go():
files = args[1:] files = args[1:]
tagr = chunker.Chunker(config_fname, options.data_dir, tagr = chunker.Chunker(config_fname, options.data_dir,
verbose = options.verbose) verbose = options.verbose, with_heads = options.with_heads)
if options.is_training: if options.is_training:
# chunker training # chunker training
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment