trohith89 commited on
Commit
6a0d5d5
Β·
verified Β·
1 Parent(s): 4f29551

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +464 -148
app.py CHANGED
@@ -1,211 +1,527 @@
1
  import streamlit as st
2
 
3
- # Custom Sidebar Styles
4
  sidebar = st.sidebar
5
- sidebar.title("🌐 NLP Techniques")
6
-
7
- # Apply custom CSS styles to the sidebar
8
- st.markdown("""
9
- <style>
10
- .css-1d391kg {
11
- background-color: #2C3E50;
12
- color: white;
13
- }
14
- .sidebar .sidebar-content {
15
- background-color: #34495E;
16
- }
17
- </style>
18
- """, unsafe_allow_html=True)
19
-
20
- # Sidebar radio button with emojis and unique color
21
- st.session_state.selected_page = sidebar.radio(
22
- "Select a page:",
23
- ["πŸ”§ NLP Techniques", "πŸ“‹ Text Preprocessing", "πŸ“Š Model Evaluation"],
24
- index=0
25
- )
26
-
27
- # Initialize session state for the selected page
28
  if 'selected_page' not in st.session_state:
29
- st.session_state.selected_page = "πŸ”§ NLP Techniques"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  # Content for "NLP Techniques"
32
- if st.session_state.selected_page == "πŸ”§ NLP Techniques":
33
  technique_option = sidebar.radio("Select an NLP Technique:", [
34
- "πŸ› οΈ NLP Techniques Overview",
35
- "βœ‚οΈ Tokenization",
36
- "🚫 Stop Words Removal",
37
- "πŸ”„ Lemmatization",
38
- "πŸͺ“ Stemming",
39
- "🎯 One-Hot Encoding",
40
- "πŸ’¬ Bag of Words (BoW)",
41
- "πŸ“Š TF-IDF",
42
- "🌍 Word Embeddings",
43
- "🏷️ Named Entity Recognition (NER)",
44
- "πŸ“ Part-of-Speech (POS) Tagging",
45
- "πŸ’– Sentiment Analysis"
46
- ], index=0)
47
-
48
- if technique_option == "πŸ› οΈ NLP Techniques Overview":
49
- st.write("""
50
- ### πŸ”§ Key NLP Techniques
51
- NLP (Natural Language Processing) involves a variety of techniques for processing and analyzing text data.
52
- These techniques help in making sense of the text and extracting valuable insights.
53
-
54
- 1. **Tokenization**: Breaking down text into smaller units (words or sentences).
55
- 2. **Part-of-Speech (POS) Tagging**: Identifying the grammatical role of words.
56
- 3. **Named Entity Recognition (NER)**: Identifying named entities (e.g., persons, locations).
57
- 4. **Dependency Parsing**: Analyzing sentence structure.
58
- 5. **Sentiment Analysis**: Analyzing the sentiment of the text (positive, negative, neutral).
59
- 6. **Word Embeddings**: Representing words as vectors that capture their meanings.
60
-
61
- **Example**: Sentiment analysis can help identify whether a customer review is positive, negative, or neutral based on the words used.
62
- """)
63
-
64
- elif technique_option == "βœ‚οΈ Tokenization":
65
- st.write("""
66
- #### βœ‚οΈ Tokenization
67
- Tokenization is the process of breaking text into smaller, meaningful pieces called tokens. These can be words, sentences, or subwords.
68
 
69
  - **Example**:
70
- - Sentence: "NLP is exciting!"
71
- - Tokenized words: `["NLP", "is", "exciting"]`
72
  """)
73
 
74
- elif technique_option == "🚫 Stop Words Removal":
75
  st.write("""
76
- #### 🚫 Stop Words Removal
77
- Stop words are common words that don't add significant meaning to text analysis. Removing them helps reduce noise and dimensionality.
78
 
79
- - **Example**: The sentence "NLP is amazing!" could be reduced to `["NLP", "amazing"]` after removing the word "is".
80
  """)
81
 
82
- elif technique_option == "πŸ”„ Lemmatization":
83
  st.write("""
84
- #### πŸ”„ Lemmatization
85
- Lemmatization reduces words to their base or dictionary form while considering the context. Unlike stemming, lemmatization ensures the root word is valid.
86
 
87
  - **Example**:
88
  - "Better" β†’ "Good"
89
  - "Running" β†’ "Run"
90
  """)
91
 
92
- elif technique_option == "πŸͺ“ Stemming":
93
  st.write("""
94
- #### πŸͺ“ Stemming
95
- Stemming is the process of trimming prefixes and suffixes from words to obtain their root form, which might not always be a valid word.
96
 
97
  - **Example**:
98
  - "Running" β†’ "Run"
99
  - "Happiness" β†’ "Happi"
100
  """)
101
 
102
- elif technique_option == "🎯 One-Hot Encoding":
103
  st.write("""
104
- #### 🎯 One-Hot Encoding
105
- One-Hot Encoding converts words into binary vectors. Each word in the vocabulary is assigned a unique vector where only one element is 1, and all others are 0.
106
 
107
  - **Example**:
108
  - Vocabulary: `["cat", "dog", "fish"]`
109
- - "cat": `[1, 0, 0]`
110
- - "dog": `[0, 1, 0]`
 
 
 
111
  """)
112
 
113
- elif technique_option == "πŸ’¬ Bag of Words (BoW)":
114
  st.write("""
115
- #### πŸ’¬ Bag of Words (BoW)
116
- The Bag of Words model represents text as a collection of words, ignoring grammar and word order. It focuses on the frequency of words.
117
 
118
  - **Example**:
119
  - Text: "I love NLP"
120
  - BoW: `{"I": 1, "love": 1, "NLP": 1}`
 
 
121
  """)
122
 
123
- elif technique_option == "πŸ“Š TF-IDF":
124
  st.write("""
125
- #### πŸ“Š TF-IDF (Term Frequency-Inverse Document Frequency)
126
- TF-IDF assigns weights to words based on their frequency in a document relative to all documents, emphasizing rare but meaningful words.
127
 
128
- - **Example**:
129
- - "data" in a data science article has a higher TF-IDF score compared to a general article.
130
  """)
131
 
132
- elif technique_option == "🌍 Word Embeddings":
133
  st.write("""
134
- #### 🌍 Word Embeddings
135
- Word embeddings map words to dense vectors, capturing semantic relationships. Similar words have similar vector representations.
136
 
137
- - **Example**:
138
- - "King" and "Queen" are closer in vector space due to their semantic relationship.
139
  """)
140
 
141
- elif technique_option == "🏷️ Named Entity Recognition (NER)":
142
  st.write("""
143
- #### 🏷️ Named Entity Recognition (NER)
144
- NER identifies entities such as people, organizations, dates, and locations in text, aiding in information extraction.
145
 
146
  - **Example**:
147
- - Text: "Elon Musk is the CEO of Tesla."
148
- - Entities: `["Elon Musk" (Person), "Tesla" (Organization)]`
149
  """)
150
 
151
- elif technique_option == "πŸ“ Part-of-Speech (POS) Tagging":
152
  st.write("""
153
- #### πŸ“ Part-of-Speech (POS) Tagging
154
- POS tagging assigns grammatical labels (noun, verb, adjective, etc.) to words in a sentence, aiding in understanding the sentence structure.
155
 
156
  - **Example**:
157
- - Sentence: "The dog barks loudly."
158
- - POS Tags: `[("The", "DT"), ("dog", "NN"), ("barks", "VBZ"), ("loudly", "RB")]`
159
  """)
160
 
161
- elif technique_option == "πŸ’– Sentiment Analysis":
162
  st.write("""
163
- #### πŸ’– Sentiment Analysis
164
- Sentiment analysis determines the sentiment expressed in text, often classifying it as positive, negative, or neutral.
165
 
166
  - **Example**:
167
- - "I absolutely love this!" β†’ Positive sentiment
168
- """)
169
-
170
- # Custom CSS for general styles
171
- st.markdown("""
172
- <style>
173
- body {
174
- background-color: #F0F8FF;
175
- color: #2C3E50;
176
- }
177
- .css-1v0mbd0 {
178
- color: #16A085;
179
- font-family: 'Arial', sans-serif;
180
- }
181
- .stText {
182
- color: #34495E;
183
- }
184
- .stMarkdown p {
185
- font-size: 1.2em;
186
- color: #34495E;
187
- font-family: 'Arial', sans-serif;
188
- }
189
- .stRadio button {
190
- background-color: #16A085;
191
- color: white;
192
- }
193
- .css-1d391kg {
194
- background-color: #2C3E50;
195
- color: white;
196
- }
197
- .css-1v0mbd0 {
198
- font-size: 1.5em;
199
- color: #16A085;
200
- }
201
- </style>
202
- """, unsafe_allow_html=True)
203
-
204
- # Custom Sidebar Styles
205
- sidebar = st.sidebar
206
- sidebar.title("🌐 NLP Techniques")
207
- st.session_state.selected_page = sidebar.radio(
208
- "Select a page:",
209
- ["πŸ”§ NLP Techniques", "πŸ“‹ Text Preprocessing", "πŸ“Š Model Evaluation"],
210
- index=0
211
- )
 
1
  import streamlit as st
2
 
3
+ # Sidebar for navigation
4
  sidebar = st.sidebar
5
+
6
+ # Sidebar header
7
+ sidebar.header('🌐 NLP Exploration')
8
+
9
+ # Sidebar options for NLP Overview, Lifecycle, and Techniques
10
+ sidebar_option = sidebar.radio('Choose a section to explore:', ['🧠 What is NLP?', 'πŸ”„ NLP Lifecycle', 'βš™οΈ NLP Techniques'])
11
+
12
+ # Store the selected page in session state
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  if 'selected_page' not in st.session_state:
14
+ st.session_state.selected_page = sidebar_option
15
+
16
+ # Update the selected page if the user selects a different option
17
+ if sidebar_option != st.session_state.selected_page:
18
+ st.session_state.selected_page = sidebar_option
19
+
20
+ # Dynamically update the title based on the selected option
21
+ def set_title(title, color="black"):
22
+ st.markdown(f"<h1 style='text-align: center; color: {color}; font-size: 36px;'>{title}</h1>", unsafe_allow_html=True)
23
+
24
+ # Function to add a paragraph with consistent formatting
25
+ def add_paragraph(content):
26
+ st.markdown(f"<p style='font-size: 16px; line-height: 1.6;'>{content}</p>", unsafe_allow_html=True)
27
+
28
+ # Function for adding a bullet list
29
+ def add_bullet_list(items):
30
+ for item in items:
31
+ st.markdown(f"- {item}", unsafe_allow_html=True)
32
+
33
+ # Content for "What is NLP?"
34
+ if st.session_state.selected_page == '🧠 What is NLP?':
35
+ set_title('Introduction to Natural Language Processing (NLP)', color="darkblue")
36
+
37
+ st.markdown("<h2 style='text-align: center; color: darkblue;'>πŸ“˜ What is NLP?</h2>", unsafe_allow_html=True)
38
+
39
+ add_paragraph("""
40
+ Natural Language Processing (NLP) is a branch of Artificial Intelligence (AI) that focuses on enabling computers to understand, interpret, and generate human language in a way that is meaningful. NLP allows machines to process and analyze large amounts of unstructured natural language data, including text and speech.
41
+ """)
42
+
43
+ st.markdown("<h3 style='text-align: center; color: darkgreen;'>Key Concepts of NLP</h3>", unsafe_allow_html=True)
44
+
45
+ add_bullet_list([
46
+ "πŸ”  **Syntax**: The arrangement of words in a sentence to ensure proper structure.",
47
+ "πŸ’¬ **Semantics**: The study of meaning in words and sentences.",
48
+ "🌍 **Pragmatics**: How context influences the interpretation of language.",
49
+ "πŸ”„ **Discourse**: The way that meaning is influenced by the flow of conversation or written text."
50
+ ])
51
+
52
+ st.markdown("<h3 style='text-align: center; color: darkgreen;'>Applications of NLP</h3>", unsafe_allow_html=True)
53
+
54
+ add_bullet_list([
55
+ "🌐 **Machine Translation**: Translating text between languages, such as Google Translate.",
56
+ "πŸ—£οΈ **Speech Recognition**: Converting spoken language into text, as seen in Siri or Google Assistant.",
57
+ "πŸ’­ **Sentiment Analysis**: Analyzing text to determine its sentiment, such as positive or negative reviews.",
58
+ "✍️ **Text Summarization**: Creating concise summaries from longer texts, such as news articles."
59
+ ])
60
+
61
+ add_paragraph("""
62
+ NLP is used in a wide variety of industries like healthcare, finance, and customer service to automate tasks, analyze data, and improve customer experiences. By enabling computers to process human language, NLP opens up new possibilities for innovation and efficiency.
63
+ """)
64
+
65
+ # Content for NLP Lifecycle
66
+ elif st.session_state.selected_page == "πŸ”„ NLP Lifecycle":
67
+ lifecycle_option = sidebar.radio("Select NLP Lifecycle Step:", [
68
+ "🌐 Overview of the NLP Life Cycle",
69
+ "🎯 Problem Definition",
70
+ "πŸ“Š Data Collection",
71
+ "πŸ“ˆ Simple EDA",
72
+ "🧹 Data Preprocessing",
73
+ "πŸ“ Feature Engineering",
74
+ "πŸ‹οΈβ€β™‚οΈ Model Training",
75
+ "πŸ… Evaluation",
76
+ "πŸš€ Deployment"
77
+ ])
78
+
79
+ if lifecycle_option == "🌐 Overview of the NLP Life Cycle":
80
+ set_title('NLP Life Cycle Overview', color="darkblue")
81
+
82
+ add_paragraph("""
83
+ The NLP lifecycle is a comprehensive process that involves several key stages, from defining the problem to deploying a model and maintaining it. Each step plays a crucial role in transforming raw text data into actionable insights or automated systems. The stages can be broken down as follows:
84
+ """)
85
+
86
+ add_bullet_list([
87
+ "1. **Problem Definition**: Identifying the business problem that can be solved using NLP.",
88
+ "2. **Data Collection**: Gathering relevant textual data that will be used to train models.",
89
+ "3. **Exploratory Data Analysis (EDA)**: Understanding the data's structure, identifying patterns, and spotting potential issues.",
90
+ "4. **Data Preprocessing**: Cleaning and formatting data to prepare it for analysis, such as removing noise or handling missing values.",
91
+ "5. **Feature Engineering**: Creating new features or selecting important attributes to improve model performance.",
92
+ "6. **Model Training**: Selecting the appropriate algorithms and training models using the prepared data.",
93
+ "7. **Evaluation**: Assessing the model's accuracy and performance using various metrics like precision, recall, and F1-score.",
94
+ "8. **Deployment**: Implementing the model into a production environment, ready for real-world use.",
95
+ "9. **Monitoring and Maintenance**: Continuously checking model performance and making updates to keep it effective."
96
+ ])
97
+
98
+ add_paragraph("""
99
+ The NLP lifecycle is iterative; as new data becomes available or requirements change, steps like model retraining and maintenance are necessary. This ensures that NLP systems remain relevant and effective over time.
100
+ """)
101
+
102
+ # More specific steps in NLP lifecycle would go here based on lifecycle_option selection...
103
+
104
+ # Content for NLP Techniques
105
+ elif st.session_state.selected_page == 'βš™οΈ NLP Techniques':
106
+ set_title('Techniques in Natural Language Processing', color="darkblue")
107
+
108
+ st.markdown("<h2 style='text-align: center; color: darkblue;'>πŸ”§ Key NLP Techniques</h2>", unsafe_allow_html=True)
109
+
110
+ add_paragraph("""
111
+ NLP involves several techniques and algorithms to process and analyze text data effectively. Some of the key techniques include:
112
+ """)
113
+
114
+ add_bullet_list([
115
+ "🧠 **Tokenization**: Breaking text into smaller units like words or sentences to make it easier to process.",
116
+ "πŸ”€ **Stemming and Lemmatization**: Reducing words to their base or root form to standardize text (e.g., 'running' to 'run').",
117
+ "🎯 **Named Entity Recognition (NER)**: Identifying entities like names, dates, or locations within text.",
118
+ "πŸ’‘ **Part-of-Speech Tagging**: Assigning a part of speech (e.g., noun, verb) to each word in a sentence.",
119
+ "πŸ” **Word Embeddings**: Mapping words into numerical vectors (e.g., Word2Vec, GloVe) to capture semantic meaning.",
120
+ "🌐 **Topic Modeling**: Grouping a set of documents into topics based on common themes, using techniques like LDA (Latent Dirichlet Allocation)."
121
+ ])
122
+
123
+ add_paragraph("""
124
+ These techniques are essential for tasks like machine translation, sentiment analysis, and chatbot development. NLP models that leverage these techniques can understand and generate human language with remarkable accuracy.
125
+ """)
126
+ import streamlit as st
127
+
128
+ # Sidebar for navigation
129
+ sidebar = st.sidebar
130
+
131
+ # Sidebar header
132
+ sidebar.header('🌐 NLP Navigation')
133
+
134
+ # Sidebar options for NLP Overview, Lifecycle, and Techniques
135
+ sidebar_option = sidebar.radio('Choose a section to explore:', ['🧠What is NLP?', 'πŸ”„NLP Lifecycle', 'βš™οΈNLP Techniques'])
136
+
137
+ # Store the selected page in session state
138
+ if 'selected_page' not in st.session_state:
139
+ st.session_state.selected_page = sidebar_option
140
+
141
+ # Update the selected page if the user selects a different option
142
+ if sidebar_option != st.session_state.selected_page:
143
+ st.session_state.selected_page = sidebar_option
144
+
145
+ # Dynamically update the title based on the selected option
146
+ def set_title(title, color="black"):
147
+ st.markdown(f"<h1 style='text-align: center; color: {color};'>{title}</h1>", unsafe_allow_html=True)
148
+
149
+ if st.session_state.selected_page == '🧠What is NLP?':
150
+ set_title('Understanding Natural Language Processing (NLP)', color="darkgreen")
151
+
152
+ elif st.session_state.selected_page == 'πŸ”„NLP Lifecycle':
153
+ set_title('NLP Lifecycle: From Data Collection to Deployment', color="darkgreen")
154
+
155
+ elif st.session_state.selected_page == 'βš™οΈNLP Techniques':
156
+ set_title('NLP Techniques: Methods and Applications', color="darkgreen")
157
+
158
+ # Content for "What is NLP?"
159
+ if st.session_state.selected_page == '🧠What is NLP?':
160
+ st.markdown("<h2 style='text-align: center; color: darkgreen;'>πŸ“˜ Introduction to NLP</h2>", unsafe_allow_html=True)
161
+ st.write("""
162
+ #### πŸ€– What is NLP?
163
+ Natural Language Processing (NLP) is a subfield of Artificial Intelligence (AI) focused on the interaction between computers and human languages. Its goal is to enable machines to understand, interpret, and generate human language meaningfully.
164
+
165
+ NLP allows machines to analyze vast amounts of natural language data, such as:
166
+ - πŸ“œ Text from documents
167
+ - πŸ—£οΈ Speech from conversations
168
+ - πŸ–ΌοΈ Images with textual descriptions
169
+
170
+ #### Key Components of NLP:
171
+ - **Syntax**: The structure of sentences and the arrangement of words.
172
+ - **Semantics**: The meaning of words and how they are used.
173
+ - **Pragmatics**: Understanding language in context, including the speaker's intent.
174
+ - **Discourse**: Analyzing the structure and flow of sentences in a larger context.
175
+
176
+ #### Applications of NLP:
177
+ - **Machine Translation**: Translating text from one language to another (e.g., Google Translate).
178
+ - **Speech Recognition**: Converting spoken words into written text (e.g., Siri, Alexa).
179
+ - **Sentiment Analysis**: Determining the sentiment behind a text (positive, negative, or neutral).
180
+ - **Text Summarization**: Automatically generating a concise version of a text (e.g., summarizing articles).
181
+
182
+ NLP has significant applications in various fields like healthcare, finance, customer service, and many others.
183
+ """)
184
+
185
+ # Content for NLP Lifecycle
186
+ elif st.session_state.selected_page == "πŸ”„NLP Lifecycle":
187
+ lifecycle_option = sidebar.radio("Select NLP Lifecycle Step:", [
188
+ "🌐 Overview of the NLP Life Cycle",
189
+ "🎯 Problem Definition",
190
+ "πŸ“Š Data Collection",
191
+ "πŸ“ˆ Simple EDA",
192
+ "🧹 Data Preprocessing",
193
+ "πŸ“ Feature Engineering",
194
+ "πŸ‹οΈβ€β™‚οΈ Model Training",
195
+ "πŸ… Model Evaluation",
196
+ "πŸš€ Deployment"
197
+ ])
198
+
199
+ if lifecycle_option == "🌐 Overview of the NLP Life Cycle":
200
+ st.write("""
201
+ #### Overview of the NLP Life Cycle:
202
+ The NLP life cycle outlines a structured approach to building, deploying, and maintaining systems that handle human language. It turns unstructured text into actionable insights, making the process flexible and adaptive to real-world changes.
203
+
204
+ - **The Process Flow**:
205
+ 1. Problem identification and text data collection.
206
+ 2. Data cleaning and preprocessing.
207
+ 3. Model building and testing.
208
+ 4. Continuous monitoring and updates to ensure optimal performance.
209
+
210
+ - **Key Features**:
211
+ - Flexible and adaptive: The NLP life cycle evolves as language, trends, and data change.
212
+ - Cross-disciplinary: Combines expertise from linguistics, computer science, and data analysis.
213
+ - Practical and scalable: Solutions are designed to be implemented in real-world applications.
214
+
215
+ #### Major Stages in the NLP Life Cycle:
216
+ 1. πŸ”§ Problem Definition
217
+ 2. πŸ“Š Data Collection
218
+ 3. πŸ” Simple EDA (Exploratory Data Analysis)
219
+ 4. 🧹 Data Preprocessing
220
+ 5. πŸ“ Feature Engineering
221
+ 6. πŸ‹οΈβ€β™‚οΈ Model Training
222
+ 7. πŸ… Model Evaluation
223
+ 8. βš™οΈ Model Tuning
224
+ 9. πŸš€ Deployment
225
+ 10. πŸ› οΈ Monitoring and Maintenance
226
+ """)
227
+
228
+ elif lifecycle_option == "🎯 Problem Definition":
229
+ st.write("""
230
+ #### πŸ”§ 1. Problem Definition:
231
+ The first step in the NLP lifecycle is defining the problem. Understanding the objective is key to determining how NLP can be applied.
232
+
233
+ - **Key Questions to Define the Problem**:
234
+ - 🎯 What is the goal of this analysis (e.g., sentiment classification, topic modeling)?
235
+ - πŸ“ What type of data are we dealing with (e.g., reviews, articles, social media posts)?
236
+ - πŸ“Š What is the desired outcome (e.g., sentiment score, summary, or label)?
237
+
238
+ **Example Problem**: Classifying customer reviews as positive or negative.
239
+ """)
240
+
241
+ elif lifecycle_option == "πŸ“Š Data Collection":
242
+ st.write("""
243
+ #### πŸ“š 2. Data Collection:
244
+ Data collection is the foundation of the NLP process. It involves gathering relevant textual data from multiple sources.
245
+
246
+ - **Common Data Collection Methods**:
247
+ - 🌐 Public datasets (e.g., Kaggle, government websites).
248
+ - πŸ”Œ APIs for data retrieval (e.g., Twitter API for tweets).
249
+ - πŸ•ΈοΈ Web scraping (e.g., using BeautifulSoup or Scrapy).
250
+ - βœ‹ Manual data entry in some cases.
251
+
252
+ **Example**: Scraping product reviews from e-commerce websites to analyze customer sentiment.
253
+
254
+ #### Extracting Data from Files:
255
+ Once data is collected, it’s often in formats like CSV, JSON, or Excel. Tools like **Pandas** in Python can be used to extract and structure this data for analysis.
256
+
257
+ **Steps**:
258
+ - Identify the file format (e.g., `.csv`, `.json`).
259
+ - Use functions like `pd.read_csv()` to load the data into a Pandas DataFrame.
260
+ - Clean and verify the data using methods like `df.head()` or `df.info()` to inspect the first few records and data types.
261
+
262
+ **Code Example**:
263
+ ```python
264
+ import pandas as pd
265
+
266
+ # Extracting Data from a CSV File
267
+ df = pd.read_csv('data.csv')
268
+ print(df.head())
269
+ ```
270
+ """)
271
+
272
+ elif lifecycle_option == "πŸ“ˆ Simple EDA":
273
+ st.write("""
274
+ #### πŸ” 3. Simple EDA (Exploratory Data Analysis):
275
+ Simple EDA provides an initial understanding of the data. It helps identify patterns, outliers, and potential issues that may impact the analysis.
276
+
277
+ - **Key Tasks in EDA**:
278
+ - Check the data balance: Is the data evenly distributed or skewed?
279
+ - Visualize distributions: Use histograms and boxplots.
280
+ - Check for missing data: Identify any gaps in the data.
281
+ - Outlier detection: Spot extreme values and decide whether to keep or remove them.
282
+
283
+ **Example**: In a classification dataset, check for a 70:30 imbalance between positive and negative classes.
284
+ """)
285
+
286
+ elif lifecycle_option == "🧹 Data Preprocessing":
287
+ st.write("""
288
+ #### 🧹 4. Text Preprocessing:
289
+ Text preprocessing is essential for converting raw text into a format suitable for analysis or model training.
290
+
291
+ **Steps in Text Preprocessing**:
292
+ - **Tokenization**: Splitting text into smaller pieces (words or sentences).
293
+ - **Removing Stopwords**: Eliminate common, less meaningful words (e.g., 'the', 'and').
294
+ - **Stemming and Lemmatization**: Reduce words to their root forms (e.g., 'running' to 'run').
295
+ - **Removing Special Characters**: Strip out unnecessary symbols, emojis, and URLs.
296
+
297
+ **Code Example**:
298
+ ```python
299
+ import re
300
+
301
+ # Sample text
302
+ text = "The quick brown fox 🦊 jumps over the lazy dog!"
303
+
304
+ # Remove special characters
305
+ clean_text = re.sub(r'[^a-zA-Z\s]', '', text)
306
+ print(clean_text)
307
+ ```
308
+ **Output**: "The quick brown fox jumps over the lazy dog"
309
+ """)
310
+
311
+ elif lifecycle_option == "πŸ“ Feature Engineering":
312
+ st.write("""
313
+ #### πŸ“ 5. Feature Engineering:
314
+ After preprocessing, the text must be transformed into a numerical representation for machine learning models.
315
+
316
+ **Common Feature Engineering Techniques**:
317
+ - **Bag of Words (BoW)**: Counts the frequency of words in the text.
318
+ - **TF-IDF**: Measures word importance based on frequency and rarity.
319
+ - **Word Embeddings**: Transforms words into dense vectors (e.g., Word2Vec, GloVe).
320
+
321
+ **Example**: Converting the sentence "I love NLP" into a numerical vector using BoW.
322
+ """)
323
+
324
+ elif lifecycle_option == "πŸ‹οΈβ€β™‚οΈ Model Training":
325
+ st.write("""
326
+ #### πŸ‹οΈβ€β™‚οΈ 6. Model Training:
327
+ Once the data is preprocessed, we can train machine learning models on it. The choice of model depends on the NLP task (e.g., classification, sentiment analysis).
328
+
329
+ **Common Models**:
330
+ - **Text Classification**: Naive Bayes, SVM, or deep learning models.
331
+ - **Sentiment Analysis**: Logistic Regression, Naive Bayes, BERT.
332
+
333
+ **Example**: Training a Naive Bayes model to classify text into categories like "Sports", "Politics", etc.
334
+ """)
335
+
336
+ elif lifecycle_option == "πŸ… Model Evaluation":
337
+ st.write("""
338
+ #### πŸ… 7. Model Evaluation:
339
+ Evaluating the performance of your model is crucial to ensure its reliability.
340
+
341
+ - **Metrics**: Accuracy, Precision, Recall, F1-Score.
342
+ - **Confusion Matrix**: Visual representation of true positives, false positives, etc.
343
+
344
+ **Example**: Evaluating a sentiment analysis model with accuracy and F1-score on test data.
345
+ """)
346
+
347
+ elif lifecycle_option == "πŸš€ Deployment":
348
+ st.write("""
349
+ #### πŸš€ 8. Deployment:
350
+ Once the model is trained and evaluated, it is deployed to production for real-time use.
351
+
352
+ **Key Steps**:
353
+ - **Integration**: Connecting the model with a live application (e.g., a chatbot).
354
+ - **Monitoring**: Regularly tracking the model’s performance over time.
355
+ - **Updating**: Periodically retraining the model with new data.
356
+
357
+ **Example**: Deploying a sentiment analysis model via a REST API to evaluate customer reviews in real-time.
358
+ """)
359
+
360
+ # Content for NLP Techniques
361
+ elif st.session_state.selected_page == "βš™οΈNLP Techniques":
362
+ st.write("""
363
+ #### βš™οΈ Common NLP Techniques:
364
+ There are several techniques in NLP that enable computers to process language in meaningful ways.
365
+
366
+ **1. Tokenization**: Breaking text into individual words or phrases.
367
+
368
+ **2. Named Entity Recognition (NER)**: Identifying entities such as names, locations, dates, etc.
369
+
370
+ **3. Part-of-Speech (POS) Tagging**: Labeling words based on their parts of speech (e.g., noun, verb).
371
+
372
+ **4. Sentiment Analysis**: Determining the sentiment expressed in the text (positive, negative, or neutral).
373
+
374
+ **5. Word Embeddings**: Converting words into high-dimensional vectors to capture semantic meaning.
375
+
376
+ **6. Text Classification**: Assigning predefined labels to text (e.g., spam detection, topic categorization).
377
+
378
+ **7. Machine Translation**: Translating text from one language to another.
379
+
380
+ **8. Text Summarization**: Condensing long texts into shorter, meaningful summaries.
381
+ """)
382
 
383
  # Content for "NLP Techniques"
384
+ elif st.session_state.selected_page == "βš™οΈNLP Techniques":
385
  technique_option = sidebar.radio("Select an NLP Technique:", [
386
+ "NLP Techniques Overview",
387
+ "Tokenization",
388
+ "Stop Words Removal",
389
+ "Lemmatization",
390
+ "Stemming",
391
+ "One-Hot Encoding",
392
+ "Bag of Words (BoW)",
393
+ "TF-IDF",
394
+ "Word Embeddings",
395
+ "Named Entity Recognition (NER)",
396
+ "Part-of-Speech (POS) Tagging",
397
+ "Sentiment Analysis"
398
+ ])
399
+
400
+ if technique_option == "NLP Techniques Overview":
401
+ st.write("""
402
+ ### βš™οΈ Key NLP Techniques
403
+ Natural Language Processing (NLP) involves a variety of techniques for processing and analyzing text data. Here are some of the most important methods:
404
+
405
+ 1. **Tokenization**: Breaking text into smaller units such as words or sentences.
406
+ 2. **Part-of-Speech (POS) Tagging**: Identifying the grammatical role of words in a sentence (e.g., noun, verb, adjective).
407
+ 3. **Named Entity Recognition (NER)**: Identifying and classifying entities like names, dates, and locations.
408
+ 4. **Dependency Parsing**: Analyzing the syntactic structure of sentences.
409
+ 5. **Sentiment Analysis**: Determining the sentiment expressed in the text (positive, negative, or neutral).
410
+ 6. **Word Embeddings**: Representing words as vectors in continuous space to capture semantic relationships (e.g., Word2Vec, GloVe).
411
+
412
+ **Example**: Sentiment analysis can identify whether customer reviews are positive, negative, or neutral based on the words used in the text.
413
+ """)
414
+
415
+ elif technique_option == "Tokenization":
416
+ st.write("""
417
+ #### 1. Tokenization
418
+ Tokenization is the process of breaking text into smaller units, known as tokens. Tokens can be words, sentences, or subwords. This step is essential for most NLP tasks, as it provides the foundation for further analysis.
 
419
 
420
  - **Example**:
421
+ - Sentence: "Natural Language Processing is amazing!"
422
+ - Tokenized words: `["Natural", "Language", "Processing", "is", "amazing"]`
423
  """)
424
 
425
+ elif technique_option == "Stop Words Removal":
426
  st.write("""
427
+ #### 2. Stop Words Removal
428
+ Stop words are common words (like 'the', 'and', 'in', etc.) that often do not carry much significant meaning for text analysis. Removing them helps reduce the dimensionality of the text and the noise in the dataset.
429
 
430
+ - **Example**: In the sentence "NLP is fun!", the stop word "is" may be removed, leaving "NLP" and "fun" for analysis.
431
  """)
432
 
433
+ elif technique_option == "Lemmatization":
434
  st.write("""
435
+ #### 3. Lemmatization
436
+ Lemmatization is the process of reducing a word to its base or root form based on its meaning. It considers the context of the word in a sentence and ensures that the resulting word is a valid word in the language.
437
 
438
  - **Example**:
439
  - "Better" β†’ "Good"
440
  - "Running" β†’ "Run"
441
  """)
442
 
443
+ elif technique_option == "Stemming":
444
  st.write("""
445
+ #### 4. Stemming
446
+ Stemming is similar to lemmatization but is a simpler, rule-based approach. It involves chopping off prefixes or suffixes from words to reduce them to a root form, which may not always be a valid word.
447
 
448
  - **Example**:
449
  - "Running" β†’ "Run"
450
  - "Happiness" β†’ "Happi"
451
  """)
452
 
453
+ elif technique_option == "One-Hot Encoding":
454
  st.write("""
455
+ #### 5. One-Hot Encoding
456
+ One-Hot Encoding is a technique where each word in the vocabulary is represented as a binary vector. Each word is assigned a unique index, and the corresponding vector has a 1 at that index and 0 elsewhere.
457
 
458
  - **Example**:
459
  - Vocabulary: `["cat", "dog", "fish"]`
460
+ - Encoding for "cat": `[1, 0, 0]`
461
+ - Encoding for "dog": `[0, 1, 0]`
462
+
463
+ **Pros**: Simple and easy to implement.
464
+ **Cons**: Results in sparse vectors and can create high-dimensional spaces when the vocabulary is large.
465
  """)
466
 
467
+ elif technique_option == "Bag of Words (BoW)":
468
  st.write("""
469
+ #### 6. Bag of Words (BoW)
470
+ The Bag of Words model represents text as an unordered collection of words, without considering grammar or word order. This technique is commonly used for text classification and representation.
471
 
472
  - **Example**:
473
  - Text: "I love NLP"
474
  - BoW: `{"I": 1, "love": 1, "NLP": 1}`
475
+
476
+ This model simply counts the frequency of each word in the text.
477
  """)
478
 
479
+ elif technique_option == "TF-IDF":
480
  st.write("""
481
+ #### 7. TF-IDF (Term Frequency-Inverse Document Frequency)
482
+ TF-IDF is a statistical measure used to evaluate the importance of a word within a document, considering its frequency in that document and its inverse frequency across a collection of documents.
483
 
484
+ - **Example**:
485
+ - In a document about data analysis, the word "data" might have a high TF-IDF score, while it would have a low score in a document about cooking.
486
  """)
487
 
488
+ elif technique_option == "Word Embeddings":
489
  st.write("""
490
+ #### 8. Word Embeddings
491
+ Word embeddings represent words in a continuous vector space, capturing semantic meanings. Words with similar meanings have similar vector representations. Popular word embedding models include Word2Vec, GloVe, and FastText.
492
 
493
+ - **Example**: The words "king" and "queen" are represented as vectors that are close to each other in the vector space due to their semantic similarity.
 
494
  """)
495
 
496
+ elif technique_option == "Named Entity Recognition (NER)":
497
  st.write("""
498
+ #### 9. Named Entity Recognition (NER)
499
+ NER involves identifying and classifying named entities in text, such as people, organizations, locations, and dates. This is often used for information extraction from unstructured text.
500
 
501
  - **Example**:
502
+ - Text: "Barack Obama was born in Hawaii."
503
+ - Extracted Entities: `["Barack Obama" (Person), "Hawaii" (Location)]`
504
  """)
505
 
506
+ elif technique_option == "Part-of-Speech (POS) Tagging":
507
  st.write("""
508
+ #### 10. Part-of-Speech (POS) Tagging
509
+ POS tagging assigns grammatical labels to words in a sentence, such as noun (NN), verb (VB), or adjective (JJ). This helps understand the syntactic structure of the sentence.
510
 
511
  - **Example**:
512
+ - Sentence: "The cat sat on the mat."
513
+ - POS Tags: `[("The", "DT"), ("cat", "NN"), ("sat", "VBD"), ("on", "IN"), ("the", "DT"), ("mat", "NN")]`
514
  """)
515
 
516
+ elif technique_option == "Sentiment Analysis":
517
  st.write("""
518
+ #### 11. Sentiment Analysis
519
+ Sentiment analysis involves determining the sentiment of a text, often classifying it as positive, negative, or neutral. It is commonly used for analyzing customer feedback, social media posts, and product reviews.
520
 
521
  - **Example**:
522
+ - Text: "I love this product!"
523
+ - Sentiment: Positive
524
+
525
+ Sentiment analysis helps businesses and organizations understand public perception and customer satisfaction.
526
+ """)
527
+