<jupyter_start><jupyter_text>Will be used BernoulliRBM model to learn data representation is an unsupervised manner  Import important library and dataset<jupyter_code>from sklearn.neural_network import BernoulliRBM
rmb = BernoulliRBM()
from tensorflow.keras.datasets import mnist
import numpy as np
(x_train, y_train),(x_test, y_test) = mnist.load_data()
img_size = x_train.shape[1]
original_dim = img_size * img_size
x_train = np.reshape(x_train, [-1, original_dim])
x_test = np.reshape(x_test, [-1, original_dim])
x_train = x_train.astype('float32')/255
x_test = x_test.astype('float32')/255
rmb = BernoulliRBM(verbose=True)
rmb.n_components= 100
rmb.fit(x_train)

r = rmb.transform(x_test)
import matplotlib.pyplot as plt
import umap
y_ = list(map(int, y_test))
x_ = rmb.transform(x_test)
x_ = umap.UMAP().fit_transform(x_)
plt.figure(figsize = (10, 8))
plt.title("Umap of 100 RBM components on MNIST")
plt.scatter(x_[:, 0], x_[:, 1], s=5.0, c=y_, alpha=0.75, cmap="tab10")
plt.xlabel('$z_1$')
plt.ylabel('$z_2$')
plt.colorbar()
# The v variable will be a 784 * 100 matrix describing the learned weights
v = rmb.components_
plt.figure()
cnt = 1
for i in range(10):
  x = x_test[i]
  for j in range(10):
    plt.subplot(10, 10, cnt)
    plt.imshow(x.reshape((28,28)), cmap='gray')
    x = rmb.gibbs(x)
    cnt += 1
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14222549742078114, 'fraction_numerical': 0.039056742815033164, 'mean_word_length': 5.466666666666667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '16059', 'license': 'Unlicense', 'n_tokens_mistral': 592, 'n_tokens_neox': 552, 'n_words': 131, 'path': 'Bernoulli_Restricted_Boltzman_Machine_Implementation.ipynb', 'repo_name': 'jahidhasan299/jahidhasan299-Deep-Learning-With-7-Real-Projects', 'size': '1357'}