teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

訂正

2021/02/20 08:24

投稿

fukubaka
fukubaka

スコア11

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,5 @@
1
1
  ### 実行したいこと
2
- TF-IDFを算出したいのですが、出力データが大きすぎるのか、以下のエラーが出ていました。このエラーを解消する方法ございましたら是非ご教授よろしくお願いいたします。
2
+ TF-IDFを算出したいのですが、出力データが大きすぎるのか、以下のエラーが出ていました。膨大な量の文章でのTF-IDFの算出ですが、値が変動する可能性を考慮して、データを分割するとは望ましくないと考えております。このエラーを解消する方法ございましたら是非ご教授よろしくお願いいたします。
3
3
 
4
4
  Memory error:
5
5
 

2

訂正

2021/02/20 08:24

投稿

fukubaka
fukubaka

スコア11

title CHANGED
@@ -1,1 +1,1 @@
1
- TF-IDF 単語も一緒に出力させたい。
1
+ TF-IDF データの容量?エラーの対処方法
body CHANGED
@@ -1,34 +1,41 @@
1
- このコードを変更して、抽出した単語の名前とSVD後の値を一緒に出力したいです。
2
- ぜひご教授願ます。
1
+ ### 実行したこと
2
+ TF-IDFを算出したいのですが、出力データが大きすぎるのか、以下のエラーが出ていました。このエラーを解消する方法ございましたら是非ご教授よろしくお願いいたします。
3
3
 
4
- ```ここに言語を入力
5
- class MecabTokenizer:
6
- def __init__(self):
7
- self.wakati = MeCab.Tagger('-Owakati')
8
- self.wakati.parse('')
9
-
10
- def tokenize(self, line):
11
- txt = self.wakati.parse(line)
12
- txt = txt.split()
13
- return txt
14
-
15
- def mecab_tokenizer(self, line):
16
- node = self.wakati.parseToNode(line)
17
- keywords = []
18
- while node:
19
- if node.feature.split(",")[0] == "名詞" or node.feature.split(",")[0] == "形容詞":
20
- keywords.append(node.surface)
21
- node = node.next
22
- return keywords
4
+ Memory error:
23
5
 
24
- n_comp = 40 #次元圧縮後の次元数
6
+ Unable to allocate 89.4 GiB for an array with shape (19720, 608678) and data type float64
25
7
 
8
+
9
+
10
+
11
+ ```python
12
+ #省略
26
- for i in ['Title1','Title2','Title3']:
13
+ for i in ['description2']:
27
14
  print (i)
28
- tfidf_vec = TfidfVectorizer(analyzer='word',ngram_range=(1,2))
15
+ tfidf_vec2 = TfidfVectorizer(analyzer='word',ngram_range=(1,2))
16
+ y = tfidf_vec2.fit_transform(df[i].values.tolist())
17
+ df_tfidf2 = pd.DataFrame(y.toarray(), columns=tfidf_vec2.get_feature_names())
18
+ ```
19
+ ```
20
+ MemoryError Traceback (most recent call last)
21
+ <ipython-input-23-d4e72a34568f> in <module>
22
+ 3 tfidf_vec2 = TfidfVectorizer(analyzer='word',ngram_range=(1,2))
29
- text_tfidf = tfidf_vec.fit_transform(df[i].values.tolist() )
23
+ 4 y = tfidf_vec2.fit_transform(df[i].values.tolist())
30
- text_svd = TruncatedSVD(n_components=n_comp,algorithm='arpack',random_state=9999)
31
- df_svd = pd.DataFrame(text_svd.fit_transform(text_tfidf))
24
+ ----> 5 df_tfidf2 = pd.DataFrame(y.toarray(), columns=tfidf_vec2.get_feature_names())
25
+
26
+ ~\anaconda3\lib\site-packages\scipy\sparse\compressed.py in toarray(self, order, out)
27
+ 1023 if out is None and order is None:
28
+ 1024 order = self._swap('cf')[0]
29
+ -> 1025 out = self._process_toarray_args(order, out)
30
+ 1026 if not (out.flags.c_contiguous or out.flags.f_contiguous):
32
- df_svd.columns = ['svd_'+str(i)+str(j+1) for j in range(n_comp)]
31
+ 1027 raise ValueError('Output array must be C or F contiguous')
32
+
33
+ ~\anaconda3\lib\site-packages\scipy\sparse\base.py in _process_toarray_args(self, order, out)
33
- df = pd.concat([df,df_svd],axis=1)
34
+ 1187 return out
35
+ 1188 else:
36
+ -> 1189 return np.zeros(self.shape, dtype=self.dtype, order=order)
37
+ 1190
38
+ 1191
39
+
40
+ MemoryError: Unable to allocate 89.4 GiB for an array with shape (19720, 608678) and data type float64
34
41
  ```

1

訂正

2021/02/20 08:20

投稿

fukubaka
fukubaka

スコア11

title CHANGED
File without changes
body CHANGED
@@ -23,11 +23,11 @@
23
23
 
24
24
  n_comp = 40 #次元圧縮後の次元数
25
25
 
26
- for i in ['channelTitle2','description2','title2']:#,'new_title','new_description',
26
+ for i in ['Title1','Title2','Title3']:
27
27
  print (i)
28
28
  tfidf_vec = TfidfVectorizer(analyzer='word',ngram_range=(1,2))
29
- text_tfidf = tfidf_vec.fit_transform(df[i].values.tolist() )
29
+ text_tfidf = tfidf_vec.fit_transform(df[i].values.tolist() )
30
- text_svd = TruncatedSVD(n_components=n_comp, algorithm='arpack',random_state=9999)
30
+ text_svd = TruncatedSVD(n_components=n_comp,algorithm='arpack',random_state=9999)
31
31
  df_svd = pd.DataFrame(text_svd.fit_transform(text_tfidf))
32
32
  df_svd.columns = ['svd_'+str(i)+str(j+1) for j in range(n_comp)]
33
33
  df = pd.concat([df,df_svd],axis=1)