def sifrank_extract(self, text, nphrase=15, ratio=0.6): keyphrases = SIFRank(text, self.SIF, self.vncorenlp, N=nphrase, ratio=ratio) return keyphrases
def sifrank(): data = request.json query = data.get("text", "") top_n = int(data.get("n", 15)) keywords = SIFRank(query, SIF, en_model, N=top_n, elmo_layers_weight=elmo_layers_weight) return jsonify(keywords)
def extract_keyword(text, plus=False, topk=15, kwdict=None, cut_dict=False): if plus == False: keyphrases = SIFRank(text, SIF, zh_model, N=topk, elmo_layers_weight=elmo_layers_weight, kwdict=kwdict, cut_dict=cut_dict) else: keyphrases = SIFRank_plus(text, SIF, zh_model, N=topk, elmo_layers_weight=elmo_layers_weight, kwdict=kwdict, cut_dict=cut_dict) return keyphrases
# Date: 2020/2/21 from embeddings import sent_emb_sif, word_emb_elmo from model.method import SIFRank, SIFRank_plus import thulac import jieba.analyse #download from https://github.com/HIT-SCIR/ELMoForManyLangs model_file = r'../auxiliary_data/zhs.model/' ELMO = word_emb_elmo.WordEmbeddings(model_file) SIF = sent_emb_sif.SentEmbeddings(ELMO, lamda=1.0) #download from http://thulac.thunlp.org/ zh_model = thulac.thulac(model_path=r'../auxiliary_data/thulac.models/',user_dict=r'../auxiliary_data/user_dict.txt') elmo_layers_weight = [0.0, 1.0, 0.0] text = "计算机科学与技术(Computer Science and Technology)是国家一级学科,下设信息安全、软件工程、计算机软件与理论、计算机系统结构、计算机应用技术、计算机技术等专业。 [1]主修大数据技术导论、数据采集与处理实践(Python)、Web前/后端开发、统计与数据分析、机器学习、高级数据库系统、数据可视化、云计算技术、人工智能、自然语言处理、媒体大数据案例分析、网络空间安全、计算机网络、数据结构、软件工程、操作系统等课程,以及大数据方向系列实验,并完成程序设计、数据分析、机器学习、数据可视化、大数据综合应用实践、专业实训和毕业设计等多种实践环节。" keyphrases = SIFRank(text, SIF, zh_model, N=15,elmo_layers_weight=elmo_layers_weight) keyphrases_ = SIFRank_plus(text, SIF, zh_model, N=15, elmo_layers_weight=elmo_layers_weight) print("------------------------------------------") print("原文:"+text) print("------------------------------------------") print("SIFRank_zh结果:") print(keyphrases) print("SIFRank+_zh结果:") print(keyphrases_) print("------------------------------------------") print("jieba分词TFIDF算法结果:") print(jieba.analyse.tfidf(text, topK=15, withWeight=True, allowPOS=('n','nr','ns'))) print("jieba分词TFIDF算法结果:") print(jieba.analyse.textrank(text, topK=15, withWeight=True, allowPOS=('n','nr','ns')))
try: for key, data in data.items(): lables = labels[key] lables_stemed = [] for lable in lables: tokens = lable.split() lables_stemed.append(' '.join(porter.stem(t) for t in tokens)) print(key) dist_sorted = SIFRank(data, SIF, en_model, elmo_layers_weight=elmo_layers_weight, if_DS=True, if_EA=True) # dist_sorted = SIFRank_plus(data, SIF, en_model, elmo_layers_weight=elmo_layers_weight) j = 0 for temp in dist_sorted[0:15]: tokens = temp[0].split() tt = ' '.join(porter.stem(t) for t in tokens) if (tt in lables_stemed or temp[0] in labels[key]): if (j < 5): num_c_5 += 1 num_c_10 += 1 num_c_15 += 1 elif (j < 10 and j >= 5):
#! /usr/bin/env python # -*- coding: utf-8 -*- # __author__ = "Sponge_sy" # Date: 2020/2/21 import nltk from embeddings import sent_emb_sif, word_emb_elmo from model.method import SIFRank, SIFRank_plus from stanfordcorenlp import StanfordCoreNLP import time #download from https://allennlp.org/elmo options_file = "../auxiliary_data/elmo_2x4096_512_2048cnn_2xhighway_options.json" weight_file = "../auxiliary_data/elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5" porter = nltk.PorterStemmer() ELMO = word_emb_elmo.WordEmbeddings(options_file, weight_file, cuda_device=0) SIF = sent_emb_sif.SentEmbeddings(ELMO, lamda=1.0) en_model = StanfordCoreNLP(r'E:\Python_Files\stanford-corenlp-full-2018-02-27',quiet=True)#download from https://stanfordnlp.github.io/CoreNLP/ elmo_layers_weight = [0.0, 1.0, 0.0] text = "Discrete output feedback sliding mode control of second order systems - a moving switching line approach The sliding mode control systems (SMCS) for which the switching variable is designed independent of the initial conditions are known to be sensitive to parameter variations and extraneous disturbances during the reaching phase. For second order systems this drawback is eliminated by using the moving switching line technique where the switching line is initially designed to pass the initial conditions and is subsequently moved towards a predetermined switching line. In this paper, we make use of the above idea of moving switching line together with the reaching law approach to design a discrete output feedback sliding mode control. The main contributions of this work are such that we do not require to use system states as it makes use of only the output samples for designing the controller. and by using the moving switching line a low sensitivity system is obtained through shortening the reaching phase. Simulation results show that the fast output sampling feedback guarantees sliding motion similar to that obtained using state feedback" keyphrases = SIFRank(text, SIF, en_model, elmo_layers_weight=elmo_layers_weight) keyphrases_ = SIFRank_plus(text, SIF, en_model, elmo_layers_weight=elmo_layers_weight) print(keyphrases) print(keyphrases_)