Beispiel #1
0
def text_class():
    nlp = FastNLP("./data_for_tests/")
    nlp.load("text_class_model")
    text = "这是最好的基于深度学习的中文分词系统。"
    result = nlp.run(text)
    print(result)
    print("FastNLP finished!")
Beispiel #2
0
def text_classify(model_dir, config, section):
    nlp = FastNLP(model_dir=model_dir)
    nlp.load("text_classify_model", config_file=config, section_name=section)
    text = [
        "世界物联网大会明日在京召开龙头股启动在即", "乌鲁木齐市新增一处城市中心旅游目的地",
        "朱元璋的大明朝真的源于明教吗?——告诉你一个真实的“明教”"
    ]
    results = nlp.run(text)
    print(results)
Beispiel #3
0
def text_classify():
    nlp = FastNLP(model_dir=PATH_TO_TEXT_CLASSIFICATION_PICKLE_FILES)
    nlp.load("text_classify_model",
             config_file="text_classify.cfg",
             section_name="model")
    text = [
        "世界物联网大会明日在京召开龙头股启动在即", "乌鲁木齐市新增一处城市中心旅游目的地",
        "朱元璋的大明朝真的源于明教吗?——告诉你一个真实的“明教”"
    ]
    results = nlp.run(text)
    print(results)
    """
Beispiel #4
0
def word_seg():
    nlp = FastNLP(model_dir=PATH_TO_CWS_PICKLE_FILES)
    nlp.load("cws_basic_model", config_file="cws.cfg", section_name="POS_test")
    text = ["这是最好的基于深度学习的中文分词系统。", "大王叫我来巡山。", "我党多年来致力于改善人民生活水平。"]
    results = nlp.run(text)
    print(results)
    for example in results:
        words, labels = [], []
        for res in example:
            words.append(res[0])
            labels.append(res[1])
        print(interpret_word_seg_results(words, labels))
Beispiel #5
0
def word_seg(model_dir, config, section):
    nlp = FastNLP(model_dir=model_dir)
    nlp.load("cws_basic_model", config_file=config, section_name=section)
    text = ["这是最好的基于深度学习的中文分词系统。", "大王叫我来巡山。", "我党多年来致力于改善人民生活水平。"]
    results = nlp.run(text)
    print(results)
    for example in results:
        words, labels = [], []
        for res in example:
            words.append(res[0])
            labels.append(res[1])
        print(interpret_word_seg_results(words, labels))
Beispiel #6
0
def pos_tag():
    nlp = FastNLP(model_dir=PATH_TO_POS_TAG_PICKLE_FILES)
    nlp.load("pos_tag_model",
             config_file="pos_tag.config",
             section_name="pos_tag_model")
    text = ["这是最好的基于深度学习的中文分词系统。", "大王叫我来巡山。", "我党多年来致力于改善人民生活水平。"]
    results = nlp.run(text)
    for example in results:
        words, labels = [], []
        for res in example:
            words.append(res[0])
            labels.append(res[1])
        print(interpret_cws_pos_results(words, labels))
Beispiel #7
0
def pos_tag(model_dir, config, section):
    nlp = FastNLP(model_dir=model_dir)
    nlp.load("pos_tag_model", config_file=config, section_name=section)
    text = ["这是最好的基于深度学习的中文分词系统。", "大王叫我来巡山。", "我党多年来致力于改善人民生活水平。"]
    results = nlp.run(text)
    for example in results:
        words, labels = [], []
        for res in example:
            words.append(res[0])
            labels.append(res[1])
        try:
            print(interpret_cws_pos_results(words, labels))
        except RuntimeError:
            print("inconsistent pos tags. this is for test only.")