def __init__(self, model_path, word_dim=None, char_dim=None, nlayers=2,
hidden_dim=128, relu_dim=64, dep_dim=100, dropout_ratio=0.5):
self.model_path = model_path
defs_file = model_path + "/tagger_defs.txt"
if word_dim is None:
# use as supertagger
self.train = False
Param.load(self, defs_file)
self.extractor = FeatureExtractor(model_path)
else:
# training
self.train = True
p = Param(self)
p.dep_dim = dep_dim
p.word_dim = word_dim
p.char_dim = char_dim
p.hidden_dim = hidden_dim
p.relu_dim = relu_dim
p.nlayers = nlayers
p.n_words = len(read_model_defs(model_path + "/words.txt"))
p.n_chars = len(read_model_defs(model_path + "/chars.txt"))
p.targets = read_model_defs(model_path + "/target.txt")
p.dump(defs_file)
self.in_dim = self.word_dim + self.char_dim
self.dropout_ratio = dropout_ratio
super(PeepHoleJaLSTMParser, self).__init__(
emb_word=L.EmbedID(self.n_words, self.word_dim),
emb_char=L.EmbedID(self.n_chars, 50, ignore_label=IGNORE),
conv_char=L.Convolution2D(1, self.char_dim,
(3, 50), stride=1, pad=(1, 0)),
lstm_f1=DyerLSTM(self.in_dim, self.hidden_dim),
lstm_f2=DyerLSTM(self.hidden_dim, self.hidden_dim),
lstm_b1=DyerLSTM(self.in_dim, self.hidden_dim),
lstm_b2=DyerLSTM(self.hidden_dim, self.hidden_dim),
linear_cat1=L.Linear(2 * self.hidden_dim, self.relu_dim),
linear_cat2=L.Linear(self.relu_dim, len(self.targets)),
linear_dep=L.Linear(2 * self.hidden_dim, self.dep_dim),
linear_head=L.Linear(2 * self.hidden_dim, self.dep_dim),
biaffine=Biaffine(self.dep_dim)
)
评论列表
文章目录