<jupyter_start><jupyter_text>Truncated SVD<jupyter_code>from gensim import matutils

num_terms = len(corpus_tfidf.obj.idfs)

tfidf_dense = matutils.corpus2dense(corpus_tfidf, num_terms)

print(tfidf_dense)
print(type(tfidf_dense))
print(tfidf_dense.shape)
U, s, V = np.linalg.svd(tfidf_dense)

print(U.shape, V.shape, s.shape)

S = np.zeros((9, 4))
S[:4, :4] = np.diag(s)

print(S)
#print(np.dot(U, np.dot(S, V)))

# np.allclose(tfidf_dense, np.dot(U, np.dot(S, V)))
s_2 = s[0:2]

S_2 = np.zeros((9, 4))
S_2[:2, :2] = np.diag(s_2)

#print(S_2)
print(np.dot(U, np.dot(S_2, V)))

np.set_printoptions(formatter={'float_kind':'{:f}'.format})

print(np.dot(U, np.dot(S_2, V)))
C = np.array([[1,0,1,1,0],[0,1,1,0,0],[1,0,0,0,0],[0,0,0,1,1],[0,0,0,1,0],[0,0,0,0,1]])
print(C.shape)
U, s, V = np.linalg.svd(C.T)
print(U)
print(s)
print(V)
s_2 = s[0:1]

S_2 = np.zeros((5, 6))
S_2[:1, :1] = np.diag(s_2)

print(S_2)
print(np.dot(U, np.dot(S_2, V)))<jupyter_output>[[ 2.16250096  0.          0.          0.          0.          0.        ]
 [ 0.          0.          0.          0.          0.          0.        ]
 [ 0.          0.          0.          0.          0.          0.        ]
 [ 0.          0.          0.          0.          0.          0.        ]
 [ 0.          0.          0.          0.          0.          0.        ]]
[[ 0.71287768  0.26635589  0.1939059   0.42524055  0.30957323  0.11566732]
 [ 0.20939855  0.07823858  0.05695734  0.12490888  0.09093311  0.03397577]
 [ 0.76983502  0.28763713  0.20939855  0.45921632  0.33430744  0.12490888]
 [ 1.13811823  0.42524055  0.30957323  0.67890191  0.49423757  0.18466434]
 [ 0.42524055  0.15888466  0.11566732  0.25366136  0.18466434  0.06899702]]
{'fraction_non_alphanumeric': 0.18815943728018758, 'fraction_numerical': 0.21512309495896834, 'mean_word_length': 2.092391304347826, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '213534', 'license': 'MIT', 'n_tokens_mistral': 1019, 'n_tokens_neox': 847, 'n_words': 132, 'path': 'Gensim, NLTK practice.ipynb', 'repo_name': 'kadakia/fake-news-and-more', 'size': '1706'}