def __init__(self, model_path, word_dim=None, char_dim=None):
self.model_path = model_path
defs_file = model_path + "/tagger_defs.txt"
if word_dim is None:
# use as supertagger
with open(defs_file) as f:
defs = json.load(f)
self.word_dim = defs["word_dim"]
self.char_dim = defs["char_dim"]
else:
# training
self.word_dim = word_dim
self.char_dim = char_dim
with open(defs_file, "w") as f:
json.dump({"model": self.__class__.__name__,
"word_dim": self.word_dim,
"char_dim": self.char_dim}, f)
self.extractor = FeatureExtractor(model_path)
self.targets = read_model_defs(model_path + "/target.txt")
self.train = True
hidden_dim = 1000
in_dim = WINDOW_SIZE * (self.word_dim + self.char_dim)
super(JaCCGEmbeddingTagger, self).__init__(
emb_word=L.EmbedID(len(self.extractor.words), self.word_dim),
emb_char=L.EmbedID(len(self.extractor.chars),
self.char_dim, ignore_label=IGNORE),
linear1=L.Linear(in_dim, hidden_dim),
linear2=L.Linear(hidden_dim, len(self.targets)),
)
评论列表
文章目录