文章目录
fastHAN
self.label_vocab
Out[6]:
{
'POS': Vocabulary(['S-root', 'B-NR', 'M-NR', 'E-NR', 'B-NN']...),
'CWS': Vocabulary(['S', 'B', 'E', 'M']...),
'NER': Vocabulary(['O', 'B-NT', 'M-NT', 'E-NT', 'B-NR']...),
'Parsing': Vocabulary(['APP', 'nn', 'nsubj', 'rcmod', 'cpm']...),
'pos': Vocabulary(['root', 'NR', 'NN', 'VV', 'DEC']...)}
self.char_vocab
Out[10]: Vocabulary(['[unused12]', '有', '的', '厂', '长']...)
len(self.char_vocab)
Out[11]: 8675
内容太多,感觉有点干不动了,先挂起这条线
https://zhuanlan.zhihu.com/p/67106791
CNNCharEmbedding
看代码
txt = ["中华 人民 共和国",
"中央 人民 政府"]
words
Out[2]:
tensor([[3, 2, 4],
[5, 2, 6]])
根据words_to_chars_embedding
这个lookup-table转chars
chars.shape
Out[3]: torch.Size([2, 3, 7])
# 2 batch 3 words 7 chars
割最大长度
说实话我不知道+2怎么来的
max_word_len = word_lengths.max()
chars = chars[:, :, :max_word_len]
chars.shape
Out[4]: torch.Size([2, 3, 5])
做Embedding
chars = self.char_embedding(chars)
chars.shape
Out[6]: torch.Size([2, 3, 5, 50])
把字符和batch合并为batch
reshaped_chars = chars.reshape(batch_size * max_len, max_word_len, -1)
reshaped_chars.shape
Out[5]: torch.Size([6, 5, 50</