MCPcopy Create free account
hub / github.com/chengsen/PyTorch_TextGCN / get_tfidf_vec

Method get_tfidf_vec

build_graph.py:139–175  ·  view source on GitHub ↗

学习获得tfidf矩阵,及其对应的单词序列 :param content_lst: :return:

(self)

Source from the content-addressed store, hash-verified

137 print_graph_detail(self.g)
138
139 def get_tfidf_vec(self):
140 """
141 学习获得tfidf矩阵,及其对应的单词序列
142 :param content_lst:
143 :return:
144 """
145 start = time()
146 text_tfidf = Pipeline([
147 ("vect", CountVectorizer(min_df=1,
148 max_df=1.0,
149 token_pattern=r"\S+",
150 )),
151 ("tfidf", TfidfTransformer(norm=None,
152 use_idf=True,
153 smooth_idf=False,
154 sublinear_tf=False
155 ))
156 ])
157
158 tfidf_vec = text_tfidf.fit_transform(open(self.content, "r"))
159
160 self.tfidf_time = time() - start
161 print("tfidf time:", self.tfidf_time)
162 print("tfidf_vec shape:", tfidf_vec.shape)
163 print("tfidf_vec type:", type(tfidf_vec))
164
165 self.node_num = tfidf_vec.shape[0]
166
167 # 映射单词
168 vocab_lst = text_tfidf["vect"].get_feature_names()
169 print("vocab_lst len:", len(vocab_lst))
170 for ind, word in enumerate(vocab_lst):
171 self.word2id[word] = ind
172
173 self.vocab_lst = vocab_lst
174
175 return tfidf_vec
176
177 def save(self):
178 print("total time:", self.pmi_time + self.tfidf_time)

Callers 1

get_tfidf_edgeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected