Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,13 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
|
| 3 |
# Apply custom styles using Streamlit's markdown
|
| 4 |
st.markdown("""
|
| 5 |
<style>
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
.main-title {
|
| 11 |
-
color: #FF5733;
|
| 12 |
-
font-size: 40px;
|
| 13 |
-
font-weight: bold;
|
| 14 |
-
text-align: center;
|
| 15 |
-
font-family: 'Roboto', sans-serif; /* Custom font */
|
| 16 |
-
}
|
| 17 |
-
|
| 18 |
-
.section-title {
|
| 19 |
-
color: #2E86C1;
|
| 20 |
-
font-size: 30px;
|
| 21 |
-
font-weight: bold;
|
| 22 |
-
margin-top: 20px;
|
| 23 |
-
font-family: 'Roboto', sans-serif; /* Custom font */
|
| 24 |
-
}
|
| 25 |
-
|
| 26 |
-
.sub-title {
|
| 27 |
-
color: #27AE60;
|
| 28 |
-
font-size: 24px;
|
| 29 |
-
font-weight: bold;
|
| 30 |
-
margin-top: 10px;
|
| 31 |
-
font-family: 'Roboto', sans-serif; /* Custom font */
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
.text {
|
| 35 |
-
font-size: 18px;
|
| 36 |
-
font-family: 'Roboto', sans-serif; /* Custom font */
|
| 37 |
-
}
|
| 38 |
</style>
|
| 39 |
""", unsafe_allow_html=True)
|
| 40 |
|
|
@@ -117,4 +90,63 @@ elif selected_method == "TF-IDF":
|
|
| 117 |
|
| 118 |
**Disadvantages:**
|
| 119 |
- β Still ignores word order
|
| 120 |
-
- β Does not capture deep
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from gensim.models import Word2Vec
|
| 3 |
|
| 4 |
# Apply custom styles using Streamlit's markdown
|
| 5 |
st.markdown("""
|
| 6 |
<style>
|
| 7 |
+
.main-title { color: #FF5733; font-size: 40px; font-weight: bold; text-align: center; }
|
| 8 |
+
.section-title { color: #2E86C1; font-size: 30px; font-weight: bold; margin-top: 20px; }
|
| 9 |
+
.sub-title { color: #27AE60; font-size: 24px; font-weight: bold; margin-top: 10px; }
|
| 10 |
+
.text { font-size: 18px; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
</style>
|
| 12 |
""", unsafe_allow_html=True)
|
| 13 |
|
|
|
|
| 90 |
|
| 91 |
**Disadvantages:**
|
| 92 |
- β Still ignores word order
|
| 93 |
+
- β Does not capture deep semantics
|
| 94 |
+
""")
|
| 95 |
+
|
| 96 |
+
elif selected_method == "One-Hot Encoding":
|
| 97 |
+
st.markdown('<p class="sub-title">One-Hot Encoding</p>', unsafe_allow_html=True)
|
| 98 |
+
st.markdown("""
|
| 99 |
+
**Definition**: Represents words as binary vectors where each word has a unique position in a vocabulary.
|
| 100 |
+
""")
|
| 101 |
+
st.markdown("""
|
| 102 |
+
**Uses:**
|
| 103 |
+
- β
Simple NLP tasks
|
| 104 |
+
- β
Word-level feature engineering
|
| 105 |
+
|
| 106 |
+
**Advantages:**
|
| 107 |
+
- β
Simple to understand
|
| 108 |
+
- β
Works well with small vocabulary sizes
|
| 109 |
+
|
| 110 |
+
**Disadvantages:**
|
| 111 |
+
- β Inefficient for large vocabularies
|
| 112 |
+
- β No information on word meaning
|
| 113 |
+
""")
|
| 114 |
+
|
| 115 |
+
elif selected_method == "Word Embeddings (Word2Vec)":
|
| 116 |
+
st.markdown('<p class="sub-title">Word Embeddings (Word2Vec)</p>', unsafe_allow_html=True)
|
| 117 |
+
st.markdown("""
|
| 118 |
+
**Definition**: Converts words into dense numerical vectors capturing semantic relationships.
|
| 119 |
+
""")
|
| 120 |
+
st.markdown("""
|
| 121 |
+
**Uses:**
|
| 122 |
+
- β
Machine translation
|
| 123 |
+
- β
Speech recognition
|
| 124 |
+
- β
Sentiment analysis
|
| 125 |
+
|
| 126 |
+
**Advantages:**
|
| 127 |
+
- β
Captures semantic relationships
|
| 128 |
+
- β
Works well for deep learning models
|
| 129 |
+
|
| 130 |
+
**Disadvantages:**
|
| 131 |
+
- β Requires large datasets to train
|
| 132 |
+
- β Computationally expensive
|
| 133 |
+
""")
|
| 134 |
+
|
| 135 |
+
# Sample texts for Word2Vec model
|
| 136 |
+
texts = [
|
| 137 |
+
"Natural Language Processing is fascinating.",
|
| 138 |
+
"Natural Language Processing involves understanding human language.",
|
| 139 |
+
"The field of NLP is growing rapidly."
|
| 140 |
+
]
|
| 141 |
+
model = Word2Vec(sentences=[text.split() for text in texts], vector_size=100, window=5, min_count=1, workers=4)
|
| 142 |
+
word_vectors = model.wv
|
| 143 |
+
word = 'natural'
|
| 144 |
+
if word in word_vectors:
|
| 145 |
+
st.markdown(f'Word2Vec Representation of "{word}":')
|
| 146 |
+
st.write(word_vectors[word])
|
| 147 |
+
else:
|
| 148 |
+
st.markdown(f'Word "{word}" not found in the vocabulary.')
|
| 149 |
+
|
| 150 |
+
# Footer
|
| 151 |
+
st.markdown('<hr>', unsafe_allow_html=True)
|
| 152 |
+
st.markdown('<p class="text" style="text-align:center;">Developed with β€οΈ using Streamlit for NLP enthusiasts.</p>', unsafe_allow_html=True)
|