1.代码
2019-CS224n-Assignment3 | 全栈说2
2.原始数据介绍
word
pos 词性
head
label 语法关系
head 指向word 构成label pos是word的词性
pos 共45个不同取值 词性
{'RBS', 'EX', 'VBP', ':', 'RP', 'IN', 'NNS', 'WRB', 'CC', 'POS', '#', 'FW', 'SYM', 'PRP', '-LRB-', '.', 'VB', 'NN', 'WP$', 'DT', 'NNP', 'VBN', 'NNPS', 'RB', 'JJS', 'CD', ',', 'VBG', 'MD', 'PDT', "''", 'UH', 'VBZ', 'WP', 'RBR', 'WDT', 'PRP$', 'VBD', 'JJ', 'LS', '-RRB-', '``', 'JJR', '$', 'TO'}
[':', '#', 'LRB', '.', ',', "''", 'RRB', '``', '$']不在列表中 其他都在
标记 | 含义 | 例子 |
CC | 连词 | and,or,but,if,while,although |
CD | 数词 | twenty-four,fourth,1991,14:24 |
DT | 限定词 | the,a,some,most,every,no |
EX | 存在量词 | there,there’s |
FW | 外来词 | dolce,ersatz,esprit,quo,maitre |
IN | 介词连词 | on,of,at,with,by,into,under |
JJ | 形容词 | new,good,high,special,big,local |
JJR | 比较级词语 | bleaker,braver,breezier,briefer,brighter,brisker |
JJS | 最高级词语 | calmest,cheapest,choicest,classiest,cleanest,clearest |
LS | 标记 | A,A. |
MD | 情态动词 | can,cannot,could,couldn’t |
NN | 名词 | year,home, |
NNS | 名词复数 | undergraduates |
NNP | 专有名词 | Alison,Africa,April,Washington |
NNPS | 专有名词复数 | Americans,Americas |
PDT | 前限定词 | all,both |
POS | 所有格标记 | ’ ‘s |
PRP | 人称代词 | hers herself |
PRP$ | 所有格 | her his |
RB | 副词 | occasionally unabatingly |
RBR | 副词比较级 | further gloomier |
RBS | 副词最高级 | best biggest |
RP | 虚词 | aboard about |
SYM | 符号 | % |
TO | 词to | to |
UH | 感叹词 | Goodbye Goody |
VB | 动词 | ask |
VBD | 动词过去式 | dipped pleaded |
VBG | 动词现在分词 | telegraphing stirring |
VBN | 动词过去分词 | multihulled dilapidated |
VBP | 动词现在式非第三人称时态 | predominate wrap |
VBZ | 动词现在式第三人称时态 | bases reconstructs |
WDT | Wh限定词 | who,which,when,what,where,how |
WP | WH代词 | that what whatever |
WP$ | WH代词所有格 | whose |
WRB | WH副词 |
(b)label的不同取值有39个 分别是
{'dep', 'root', 'nummod', 'advmod', 'nmod', 'expl', 'acl:relcl', 'nmod:tmod', 'acl', 'cop', 'discourse', 'iobj', 'nmod:npmod', 'cc:preconj', 'aux', 'ccomp', 'punct', 'advcl', 'mwe', 'csubj', 'parataxis', 'nsubj', 'conj', 'compound:prt', 'nsubjpass', 'neg', 'nmod:poss', 'mark', 'compound', 'xcomp', 'det', 'appos', 'det:predet', 'amod', 'auxpass', 'case', 'csubjpass', 'dobj', 'cc'}
其中 'mwe', 'dobj' 不在以下列表中
英语句法依存关系_喵吹吹风的博客-CSDN博客_依存句法分析 英文
3.代码部分详解
Neural Transition-Based Dependency Parsing - 简书
debug = True
# debug = False
assert(torch.__version__ == "1.0.0"), "Please install torch version 1.0.0"
print(80 * "=")
print("INITIALIZING")
print(80 * "=")
parser, embeddings, train_data, dev_data, test_data = load_and_preprocess_data(debug)
def load_and_preprocess_data(reduced=True):
config = Config()
print("Loading data...",)
start = time.time()
#read_conll 讲原文件中的1 4 6 7 单词(word) 词性(pos) 依赖关系(head) 句法关系(label)按照字典放在一个list中 list中每一个元素是一句话中的4列
#遇到空行 就是新的一句话
train_set = read_conll(os.path.join(config.data_path, config.train_file),
lowercase=config.lowercase)
#39832
dev_set = read_conll(os.path.join(config.data_path, config.dev_file),
lowercase=config.lowercase)
#1700
test_set = read_conll(os.path.join(config.data_path, config.test_file),