예제 #1
0
    def test_semantic_role_labeling(self):
        predictor = pretrained.srl_with_elmo_luheng_2018()

        sentence = "If you liked the music we were playing last night, you will absolutely love what we're playing tomorrow!"

        result = predictor.predict_json({"sentence": sentence})

        assert result["words"] == [
                "If", "you", "liked", "the", "music", "we", "were", "playing", "last", "night", ",",
                "you", "will", "absolutely", "love", "what", "we", "'re", "playing", "tomorrow", "!"
        ]

        assert result["verbs"] == [
                {"verb": "liked",
                 "description": "If [ARG0: you] [V: liked] [ARG1: the music we were playing last night] , you will absolutely love what we 're playing tomorrow !",
                 "tags": ["O", "B-ARG0", "B-V", "B-ARG1", "I-ARG1", "I-ARG1", "I-ARG1", "I-ARG1", "I-ARG1", "I-ARG1", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O"]},
                {"verb": "were",
                 "description": "If you liked the music we [V: were] playing last night , you will absolutely love what we 're playing tomorrow !",
                 "tags": ["O", "O", "O", "O", "O", "O", "B-V", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O"]},
                {"verb": "playing",
                 "description": "If you liked [ARG1: the music] [ARG0: we] were [V: playing] [ARGM-TMP: last] night , you will absolutely love what we 're playing tomorrow !",
                 "tags": ["O", "O", "O", "B-ARG1", "I-ARG1", "B-ARG0", "O", "B-V", "B-ARGM-TMP", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O"]},
                {"verb": "will",
                 "description": "If you liked the music we were playing last night , you [V: will] absolutely love what we 're playing tomorrow !",
                 "tags": ["O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "B-V", "O", "O", "O", "O", "O", "O", "O", "O"]},
                {"verb": "love",
                 "description": "[ARGM-ADV: If you liked the music we were playing last night] , [ARG0: you] [ARGM-MOD: will] [ARGM-ADV: absolutely] [V: love] [ARG1: what we 're playing tomorrow] !",
                 "tags": ["B-ARGM-ADV", "I-ARGM-ADV", "I-ARGM-ADV", "I-ARGM-ADV", "I-ARGM-ADV", "I-ARGM-ADV", "I-ARGM-ADV", "I-ARGM-ADV", "I-ARGM-ADV", "I-ARGM-ADV", "O", "B-ARG0", "B-ARGM-MOD", "B-ARGM-ADV", "B-V", "B-ARG1", "I-ARG1", "I-ARG1", "I-ARG1", "I-ARG1", "O"]},
                {"verb": "'re",
                 "description": "If you liked the music we were playing last night , you will absolutely love what we [V: 're] playing tomorrow !",
                 "tags": ["O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "B-V", "O", "O", "O"]},
                {"verb": "playing",
                 "description": "If you liked the music we were playing last night , you will absolutely love [ARG1: what] [ARG0: we] 're [V: playing] [ARGM-TMP: tomorrow] !",
                 "tags": ["O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "O", "B-ARG1", "B-ARG0", "O", "B-V", "B-ARGM-TMP", "O"]}
        ]
예제 #2
0
def _get_predictor():

    return [
        pretrained.srl_with_elmo_luheng_2018(),
        biaffine_parser_stanford_dependencies_todzat_2017(),
        named_entity_recognition_with_elmo_peters_2018(),
        lemma(),
        pretrained.neural_coreference_resolution_lee_2017(),
        fine_grained_named_entity_recognition_with_elmo_peters_2018()
    ]
예제 #3
0
def main(args):
    if args.tagger == "srl":
        model = srl_with_elmo_luheng_2018()
        tagger_function = model.predict
    elif args.tagger == "oie":
        model = open_information_extraction_stanovsky_2018()
        tagger_function = lambda sentence: model.predict_json(
            {"sentence": sentence})
    elif args.tagger == "dep":
        model = biaffine_parser_stanford_dependencies_todzat_2017()
        tagger_function = lambda sentence: get_verb_info_from_graph(
            get_nx_graph_from_dep(model.predict(sentence)))
    else:
        raise RuntimeError(f"Unknown tagger type: {args.tagger}")
    if args.include_coref:
        coref_model = neural_coreference_resolution_lee_2017()
    else:
        coref_model = None
    if args.verbose:
        logging.basicConfig(level=logging.INFO)
    make_files_for_semparse(args.data_files_path, args.output_path,
                            tagger_function, coref_model)