Example #1
0
 def draw_weight(self, sentence):
     attn_data = self.__get_attention(self.model, sentence)
     gv = GraphVisualizer()
     x = attn_data["text"]
     y = x
     x_data = []
     y_data = []
     z_data = []
     for x_index in range(len(x)):
         x_data.append("(" + str(x_index) + ")" + x[x_index])
         z_data.append(attn_data["attn"][11][11][x_index][x_index])
     data_meta_list = []
     data_meta = {
         "graph_type": "histogram",
         "data_name": "Y",
         "x_data": x_data,
         "y_data": z_data,
         "y_axis": "y2"
     }
     data_meta_list.append(data_meta)
     graph_meta = {
         "title": "BERT NER WEIGHT",
         "x_tickangle": -45,
         "y1_tickangle": 0,
         "y2_tickangle": 0,
         "x_name": "TOKEN",
         "y1_name": "WEIGHT",
         "y2_name": "WEIGHT",
     }
     return gv.draw_histogram(data_meta_list, graph_meta)
Example #2
0
 def get_plotly_graph(self, max_words=100):
     gv = GraphVisualizer()
     x = self.get_word_list()[:max_words]
     y = [score for word, score in self.get_tf_list()][:max_words]
     z = [score for word, score in self.get_tfidf_list()][:max_words]
     data_meta_list = []
     data_meta = {
         "graph_type": "histogram",
         "data_name": "TF",
         "x_data": x,
         "y_data": y,
         "y_axis": "y1",
     }
     data_meta_list.append(data_meta)
     data_meta = {
         "graph_type": "scatter",
         "data_name": "TF-IDF",
         "x_data": x,
         "y_data": z,
         "y_axis": "y2"
     }
     data_meta_list.append(data_meta)
     graph_meta = {
         "title": "단어빈도 및 TF-IDF (TF & TF-IDF)",
         "x_tickangle": -45,
         "y1_tickangle": 0,
         "y2_tickangle": 0,
         "x_name": "단어 (WORD)",
         "y1_name": "빈도 (TF)",
         "y2_name": "TF-IDF",
     }
     return gv.draw_histogram(data_meta_list, graph_meta)
 def draw_weight(self, sentence):
     gv = GraphVisualizer()
     gv.set_plotly()
     token_list, weight_list = self.get_weight(sentence)
     x_data = [
         "(" + str(token_index) + ")" + token
         for token_index, token in enumerate(token_list)
     ]
     z_data = [weight for weight in weight_list]
     data_meta_list = []
     data_meta = {
         "graph_type": "histogram",
         "data_name": "Y",
         "x_data": x_data,
         "y_data": z_data,
         "y_axis": "y2"
     }
     data_meta_list.append(data_meta)
     graph_meta = {
         "title": "NER WEIGHT",
         "x_tickangle": -45,
         "y1_tickangle": 0,
         "y2_tickangle": 0,
         "x_name": "TOKEN",
         "y1_name": "WEIGHT",
         "y2_name": "WEIGHT",
     }
     return gv.draw_histogram(data_meta_list, graph_meta)