Update README.md
Browse files
README.md
CHANGED
@@ -14,3 +14,50 @@ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-
|
|
14 |
|
15 |
Inspired by this video which discusses how Anthropic is studying how their model works using Dictionary Learning.
|
16 |
https://youtu.be/AYTYk-kmXuI?t=168
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
Inspired by this video which discusses how Anthropic is studying how their model works using Dictionary Learning.
|
16 |
https://youtu.be/AYTYk-kmXuI?t=168
|
17 |
+
|
18 |
+
|
19 |
+
Importing Libraries:
|
20 |
+
|
21 |
+
streamlit for creating the app.
|
22 |
+
Scikit-learn (sklearn.decomposition.DictionaryLearning and datasets.load_digits) for dictionary learning and loading the dataset.
|
23 |
+
matplotlib for plotting.
|
24 |
+
numpy for numerical operations.
|
25 |
+
Streamlit App Initialization:
|
26 |
+
|
27 |
+
The app sets a title and a description with st.title and st.write.
|
28 |
+
Loading Data:
|
29 |
+
|
30 |
+
Digit data is loaded using load_digits(). This dataset contains 8x8 images of digits (0-9).
|
31 |
+
Sample Image Display:
|
32 |
+
|
33 |
+
A slider is created with st.slider to select an index for displaying a sample image from the dataset using st.image.
|
34 |
+
Selecting Number of Components:
|
35 |
+
|
36 |
+
Another slider allows users to choose the number of dictionary components (n_components) for dictionary learning.
|
37 |
+
Performing Dictionary Learning:
|
38 |
+
|
39 |
+
DictionaryLearning is initialized with the selected number of components and fitted to the data.
|
40 |
+
The dictionary elements learned are stored in dictionary.
|
41 |
+
Displaying Dictionary Components:
|
42 |
+
|
43 |
+
The learned dictionary components are displayed as images using Matplotlib. Each component is reshaped into an 8x8 image.
|
44 |
+
Displaying Sparsity:
|
45 |
+
|
46 |
+
Sparsity is calculated as the mean of zero entries in the transformed data (X_transformed) and displayed with st.write.
|
47 |
+
|
48 |
+
|
49 |
+
Assistant: Sure! The requirements.txt file is used to specify the dependencies needed for your Python project. For the Streamlit application demonstrating dictionary learning, you'll need the following libraries:
|
50 |
+
|
51 |
+
streamlit to create the interactive web app.
|
52 |
+
scikit-learn for performing dictionary learning and loading the dataset.
|
53 |
+
matplotlib for plotting the images.
|
54 |
+
numpy for numerical operations.
|
55 |
+
Here is a requirements.txt file that includes all these dependencies:
|
56 |
+
|
57 |
+
streamlit>=1.0.0
|
58 |
+
scikit-learn>=0.24.0
|
59 |
+
matplotlib>=3.0.0
|
60 |
+
numpy>=1.19.0
|
61 |
+
|
62 |
+
|
63 |
+
|