# -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-26 23:20
from hanlp.pretrained.glove import GLOVE_6B_100D
from hanlp.components.parsers.biaffine_parser import BiaffineDependencyParser, BiaffineSemanticDependencyParser
from tests import cdroot

cdroot()
save_dir = 'data/model/semeval15_biaffine_psd'
parser = BiaffineSemanticDependencyParser()
# parser.fit('data/semeval15/en.psd.train.conll', 'data/semeval15/en.psd.dev.conll', save_dir,
#            pretrained_embed={'class_name': 'HanLP>Word2VecEmbedding',
#                              'config': {
#                                  'trainable': False,
#                                  'embeddings_initializer': 'zero',
#                                  'filepath': GLOVE_6B_100D,
#                                  'expand_vocab': True,
#                                  'lowercase': False,
#                                  'unk': 'unk',
#                                  'normalize': True,
#                                  'name': 'glove.6B.100d'
#                              }},
#            # lstm_dropout=0,
#            # mlp_dropout=0,
#            # embed_dropout=0,
#            epochs=1
#            )
parser.load(save_dir)
parser.save_meta(save_dir)
parser.transform.summarize_vocabs()
sentence = [('Is', 'VBZ'), ('this', 'DT'), ('the', 'DT'), ('future', 'NN'),
# -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-26 23:20
from hanlp.datasets.parsing.semeval2016 import SEMEVAL2016_TEXT_TRAIN, SEMEVAL2016_TEXT_VALID, SEMEVAL2016_TEXT_TEST
from hanlp.pretrained.word2vec import SEMEVAL16_EMBEDDINGS_300_TEXT_CN
from hanlp.utils.tf_util import nice

nice()
from hanlp.components.parsers.biaffine_parser import BiaffineSemanticDependencyParser
from tests import cdroot

cdroot()
save_dir = 'data/model/sdp/semeval16-text'
parser = BiaffineSemanticDependencyParser()
parser.fit(
    SEMEVAL2016_TEXT_TRAIN,
    SEMEVAL2016_TEXT_VALID,
    save_dir,
    pretrained_embed={
        'class_name': 'HanLP>Word2VecEmbedding',
        'config': {
            'trainable': False,
            'embeddings_initializer': 'zero',
            'filepath': SEMEVAL16_EMBEDDINGS_300_TEXT_CN,
            'expand_vocab': True,
            'lowercase': True,
            'normalize': True,
        }
    },
)
parser.load(save_dir)
Exemple #3
0
# -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-01-01 18:26
from hanlp.components.parsers.biaffine_parser import BiaffineSemanticDependencyParser
from hanlp.pretrained.glove import GLOVE_6B_100D
from tests import cdroot

cdroot()
save_dir = 'data/model/sdp/semeval15_biaffine_dm'
parser = BiaffineSemanticDependencyParser()
parser.fit(
    'data/semeval15/en.dm.train.conll',
    'data/semeval15/en.dm.dev.conll',
    save_dir,
    pretrained_embed={
        'class_name': 'HanLP>Word2VecEmbedding',
        'config': {
            'trainable': False,
            'embeddings_initializer': 'zero',
            'filepath': GLOVE_6B_100D,
            'expand_vocab': True,
            'lowercase': True,
            'normalize': True,
        }
    },
)
sentence = [('Is', 'VBZ'), ('this', 'DT'), ('the', 'DT'), ('future', 'NN'),
            ('of', 'IN'), ('chamber', 'NN'), ('music', 'NN'), ('?', '.')]
print(parser.predict(sentence))
parser.evaluate('data/semeval15/en.id.dm.auto.conllu', save_dir)
parser.evaluate('data/semeval15/en.ood.dm.auto.conllu', save_dir)
# -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-01-01 18:26
from hanlp.components.parsers.biaffine_parser import BiaffineSemanticDependencyParser
from hanlp.pretrained.glove import GLOVE_6B_100D
from tests import cdroot

cdroot()
save_dir = 'data/model/sdp/semeval15_biaffine_pas'
parser = BiaffineSemanticDependencyParser()
parser.fit(
    'data/semeval15/en.pas.train.conll',
    'data/semeval15/en.pas.dev.conll',
    save_dir,
    pretrained_embed={
        'class_name': 'HanLP>Word2VecEmbedding',
        'config': {
            'trainable': False,
            'embeddings_initializer': 'zero',
            'filepath': GLOVE_6B_100D,
            'expand_vocab': True,
            'lowercase': True,
            'normalize': True,
        }
    },
)
parser.load(
    save_dir
)  # disable variational dropout during evaluation so as to use CudaLSTM
sentence = [('Is', 'VBZ'), ('this', 'DT'), ('the', 'DT'), ('future', 'NN'),
            ('of', 'IN'), ('chamber', 'NN'), ('music', 'NN'), ('?', '.')]