Exemplo n.º 1
0
 def __init__(self, cb_id, nn_id):
     """
     init global variables
     """
     self.cb_id = cb_id
     self.nn_id = nn_id
     self.seq2seq_model = PredictNetSeq2Seq()
     self.wcnn_model = PredictNetWcnn()
Exemplo n.º 2
0
 def __init__(self, cb_id, nn_id):
     """
     init global variables
     """
     self.cb_id = cb_id
     self.nn_id = nn_id
     # self.seq2seq_model = PredictNetSeq2Seq()
     self.wcnn_model = PredictNetWcnn()
    def post(self, request, type, nnid, ver):
        """
        - desc : insert cnn configuration data
        """
        try:
            if (ver == 'active'):
                if (type == 'w2v'):
                    return_data = PredictNetW2V().run(nnid, request.data)
                elif (type == "d2v"):
                    return_data = PredictNetD2V().run(nnid, request.data)
                elif (type == "cnn"):
                    # TO-DO : need predict function for active taged version
                    raise Exception("on developing now !")
                elif (type == "wdnn"):
                    return_data = PredictNetWdnn().run(nnid, ver,
                                                       request.FILES)
                elif (type == "seq2seq"):
                    return_data = PredictNetSeq2Seq().run(nnid, request.data)
                elif (type == "autoencoder"):
                    return_data = PredictNetAutoEncoder().run(
                        nnid, request.data)
                elif (type == "renet"):
                    #return_data = PredictNetRenet().run(nnid, ver, request.FILES)
                    # TO-DO : need to create PredictNetRenet class first
                    raise Exception("on developing now !")
                elif (type == "anomaly"):
                    return_data = PredictNetAnomaly().run(nnid, request.data)
                elif (type == "wcnn"):
                    return_data = PredictNetWcnn().run(nnid, request.data)
                elif (type == "bilstmcrf"):
                    return_data = PredictNetBiLstmCrf().run(nnid, request.data)
                else:
                    raise Exception("Not defined type error")
            else:
                if (type == 'w2v'):
                    # TO-DO : need predict function for specific  version
                    raise Exception("on developing now !")
                elif (type == "d2v"):
                    # TO-DO : need predict function for specific  version
                    raise Exception("on developing now !")
                elif (type == "cnn"):
                    return_data = PredictNetCnn().run(nnid, ver, request.FILES)
                elif (type == "wdnn"):
                    return_data = PredictNetWdnn().run(nnid, ver,
                                                       request.FILES)
                elif (type == "seq2seq"):
                    # TO-DO : need predict function for specific  version
                    raise Exception("on developing now !")
                elif (type == "renet"):
                    return_data = PredictNetRenet().run(
                        nnid, ver, request.FILES)
                else:
                    raise Exception("Not defined type error")

            return Response(json.dumps(return_data))
        except Exception as e:
            return_data = {"status": "404", "result": str(e)}
            return Response(json.dumps(return_data))
Exemplo n.º 4
0
class IntendAnalyzer(ShareData):
    """
    parse raw text to tageed, entity filterd sentence
    ※ Example
    input : I bought a car yesterday
    output : I bought a car [time]
    """
    def __init__(self, cb_id, nn_id):
        """
        init global variables
        """
        self.cb_id = cb_id
        self.nn_id = nn_id
        #self.seq2seq_model = PredictNetSeq2Seq()
        self.wcnn_model = PredictNetWcnn()

    def parse(self, share_data, type):
        """
        run intent analyzer
        :param context:
        :return:
        """
        if (share_data.get_intent_id() != ""):
            logging.info("■■■■■■■■■■ 의도 존재  : " + share_data.get_intent_id())
        else:
            if (type == 'Rule'):
                convert_data = share_data.get_convert_dict_data()
                logging.info("■■■■■■■■■■ Rule 의도 분석 Input Data : " +
                             ' '.join(convert_data))
                intent_model = self.get_intent_model(' '.join(convert_data))
                logging.info("■■■■■■■■■■ Rule 의도 분석 결과(Model) : " +
                             intent_model)
                share_data.set_pattern_intent_id([intent_model])
                share_data.set_intent_history({"P": intent_model})

            elif (type == 'NER'):
                convert_data = share_data.get_convert_data()
                logging.info("■■■■■■■■■■ NER 의도 분석 Input Data : " +
                             ' '.join(convert_data))
                intent_model = self.get_intent_model(' '.join(convert_data))
                logging.info("■■■■■■■■■■ NER 의도 분석 결과(Model) : " +
                             intent_model)
                share_data.set_intent_id([intent_model])
                share_data.set_intent_history({"i": intent_model})

        return share_data

    def get_intent_model(self, convert_data):
        intent_model = str(
            self.wcnn_model.run(self.nn_id, {
                "input_data": convert_data,
                "num": 0,
                "clean_ans": False
            })[0])
        return intent_model
Exemplo n.º 5
0
class IntendAnalyzer(ShareData):
    """
    parse raw text to tageed, entity filterd sentence
    ※ Example
    input : I bought a car yesterday
    output : I bought a car [time]
    """
    def __init__(self, cb_id, nn_id):
        """
        init global variables
        """
        self.cb_id = cb_id
        self.nn_id = nn_id
        self.seq2seq_model = PredictNetSeq2Seq()
        self.wcnn_model = PredictNetWcnn()

    def parse(self, share_data):
        """
        run intent analyzer
        :param context:
        :return:
        """
        if (share_data.get_intent_id() != ""):
            print("■■■■■■■■■■ 의도 존재  : " + share_data.get_intent_id())
        else:
            convert_data = share_data.get_convert_data()
            intent_model = self.get_intent_model(convert_data)
            print("■■■■■■■■■■ 의도 분석 결과 : " + intent_model)

            intent_rule = self.get_rule_value(convert_data)

            share_data.set_intent_id(intent_model)
            share_data.set_intent_history(intent_model)

            # slot_key = ChatKnowledgeDataDict(self.cb_id).get_essential_entity(share_data.get_intent_id())
            # share_data.set_story_key_entity(slot_key)
        return share_data

    def get_intent_model(self, convert_data):
        # result = self.seq2seq_model.run(self.nn_id , {"input_data": convert_data, "num": 0, "clean_ans": False})[0][1][0]
        intent_model = str(
            self.wcnn_model.run(self.nn_id, {
                "input_data": convert_data,
                "num": 0,
                "clean_ans": False
            })[0])
        return intent_model

    def get_rule_value(self, convert_data):
        result = ""
        return result
Exemplo n.º 6
0
    def post(self, request, type, nnid, ver):
        """
        Request Deep Neural Network to predict result with given data   \n
        input formats can be varies on type of networks     \n
        but usually you can use it with parm input_data     \n
        ---
        # Class Name : ServiceManagerPredict

        # Description:
            request predict service via rest service
            It caches the model and vectors on first request
            It may can take some time at first for caching, after than we can response the request
            within 1.0 sec
        """
        try:
            if ver == 'active':
                condition = {'nn_id': nnid}
                ver = NNCommonManager().get_nn_info(
                    condition)[0]['nn_wf_ver_id']

            if (type == "resnet" or type == "inceptionv4"):
                return_data = PredictNetImage().run(nnid, ver, request)
            elif (type == 'w2v'):
                return_data = PredictNetW2V().run(nnid, request.data)
            elif (type == "d2v"):
                return_data = PredictNetD2V().run(nnid, request.data)
            elif (type == "cnn"):
                return_data = PredictNetCnn().run(nnid, ver, request.FILES)
            elif (type == "wdnn"):
                return_data = PredictNetWdnn().run(nnid, ver, request)
            elif (type == "seq2seq"):
                return_data = PredictNetSeq2Seq().run(nnid, request.data)
            elif (type == "autoencoder"):
                return_data = PredictNetAutoEncoder().run(nnid, request.data)
            elif (type == "anomaly"):
                return_data = PredictNetAnomaly().run(nnid, request.data)
            elif (type == "wcnn"):
                return_data = PredictNetWcnn().run(nnid, request.data)
            elif (type == "bilstmcrf"):
                return_data = PredictNetBiLstmCrf().run(nnid, request.data)
            elif (type == "ngram_mro"):
                return_data = PredictNetNgram().run(type, nnid, ver,
                                                    request.data)
            elif (type == "xgboost_reg"):
                return_data = PredictNetXgboost().run(nnid, ver, request.FILES)

            return Response(return_data)
        except Exception as e:
            return_data = {"status": "404", "result": str(e)}
            return Response(json.dumps(return_data))
Exemplo n.º 7
0
class IntendAnalyzer(ShareData):

    """
    parse raw text to tageed, entity filterd sentence
    ※ Example
    input : I bought a car yesterday
    output : I bought a car [time]
    """

    def __init__(self, cb_id, nn_id):
        """
        init global variables
        """
        self.cb_id = cb_id
        self.nn_id = nn_id
        # self.seq2seq_model = PredictNetSeq2Seq()
        self.wcnn_model = PredictNetWcnn()

    def parse(self, share_data, type):
        """
        run intent analyzer
        :param context:
        :return:
        """
        if (share_data.get_intent_id() != ""):
            logging.info("■■■■■■■■■■ 의도 존재  : " + share_data.get_intent_id())
        else:
            if(type == 'Rule' and self.nn_id != ''):
                convert_data = share_data.get_convert_dict_data()
                logging.info("■■■■■■■■■■ Dict 의도 분석 Input Data : " + ' '.join(convert_data))
                intent_model = self.get_intent_model(' '.join(convert_data))
                logging.info("■■■■■■■■■■ Dict 의도 분석 결과(Model) : " + intent_model)
                share_data.set_pattern_intent_id([intent_model])
                share_data.set_intent_history({"P": intent_model})

            elif(type == 'NER' and self.nn_id != ''):
                convert_data = share_data.get_convert_data()
                logging.info("■■■■■■■■■■ NER 의도 분석 Input Data : " + ' '.join(convert_data))
                intent_model = self.get_intent_model(' '.join(convert_data))
                logging.info("■■■■■■■■■■ NER 의도 분석 결과(Model) : " + intent_model)
                share_data.set_intent_id([intent_model])
                share_data.set_intent_history({"i": intent_model})

        return share_data

    def get_intent_model(self, convert_data):
        intent_model = str(self.wcnn_model.run(self.nn_id, {"input_data": convert_data, "num": 0, "clean_ans": False})[0])
        return intent_model
    def post(self, request, type, nnid, ver):
        """
        Request Deep Neural Network to predict result with given data   \n
        input formats can be varies on type of networks     \n
        but usually you can use it with parm input_data     \n
        ---
        # Class Name : ServiceManagerPredict

        # Description:
            request predict service via rest service
            It caches the model and vectors on first request
            It may can take some time at first for caching, after than we can response the request
            within 1.0 sec
        """
        try:
            if (ver == 'active'):
                if (type == 'w2v'):
                    return_data = PredictNetW2V().run(nnid, request.data)
                elif (type == "d2v"):
                    return_data = PredictNetD2V().run(nnid, request.data)
                elif (type == "cnn"):
                    # TO-DO : need predict function for active taged version
                    raise Exception("on developing now !")
                elif (type == "wdnn"):
                    return_data = PredictNetWdnn().run(nnid, ver,
                                                       request.FILES)
                elif (type == "seq2seq"):
                    return_data = PredictNetSeq2Seq().run(nnid, request.data)
                elif (type == "autoencoder"):
                    return_data = PredictNetAutoEncoder().run(
                        nnid, request.data)
                elif (type == "renet"):
                    #return_data = PredictNetRenet().run(nnid, ver, request.FILES)
                    # TO-DO : need to create PredictNetRenet class first
                    raise Exception("on developing now !")
                elif (type == "anomaly"):
                    return_data = PredictNetAnomaly().run(nnid, request.data)
                elif (type == "wcnn"):
                    return_data = PredictNetWcnn().run(nnid, request.data)
                elif (type == "bilstmcrf"):
                    return_data = PredictNetBiLstmCrf().run(nnid, request.data)
                else:
                    raise Exception("Not defined type error")
            else:
                if (type == 'w2v'):
                    # TO-DO : need predict function for specific  version
                    raise Exception("on developing now !")
                elif (type == "d2v"):
                    # TO-DO : need predict function for specific  version
                    raise Exception("on developing now !")
                elif (type == "cnn"):
                    return_data = PredictNetCnn().run(nnid, ver, request.FILES)
                elif (type == "wdnn"):
                    return_data = PredictNetWdnn().run(nnid, ver,
                                                       request.FILES)
                elif (type == "seq2seq"):
                    # TO-DO : need predict function for specific  version
                    raise Exception("on developing now !")
                elif (type == "renet"):
                    return_data = PredictNetRenet().run(
                        nnid, ver, request.FILES)
                else:
                    raise Exception("Not defined type error")

            return Response(json.dumps(return_data))
        except Exception as e:
            return_data = {"status": "404", "result": str(e)}
            return Response(json.dumps(return_data))