trohith89 commited on
Commit
4f29551
Β·
verified Β·
1 Parent(s): 3ad4835

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +148 -406
app.py CHANGED
@@ -1,469 +1,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
-
127
- # Content for NLP Lifecycle
128
- elif st.session_state.selected_page == "πŸ”„NLP Lifecycle":
129
- lifecycle_option = sidebar.radio("Select NLP Lifecycle Step:", [
130
- "🌐 Overview of the NLP Life Cycle",
131
- "🎯 Problem Definition",
132
- "πŸ“Š Data Collection",
133
- "πŸ“ˆ Simple EDA",
134
- "🧹 Data Preprocessing",
135
- "πŸ“ Feature Engineering",
136
- "πŸ‹οΈβ€β™‚οΈ Model Training",
137
- "πŸ… Model Evaluation",
138
- "πŸš€ Deployment"
139
- ])
140
-
141
- if lifecycle_option == "🌐 Overview of the NLP Life Cycle":
142
- st.write("""
143
- #### Overview of the NLP Life Cycle:
144
- 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.
145
-
146
- - **The Process Flow**:
147
- 1. Problem identification and text data collection.
148
- 2. Data cleaning and preprocessing.
149
- 3. Model building and testing.
150
- 4. Continuous monitoring and updates to ensure optimal performance.
151
-
152
- - **Key Features**:
153
- - Flexible and adaptive: The NLP life cycle evolves as language, trends, and data change.
154
- - Cross-disciplinary: Combines expertise from linguistics, computer science, and data analysis.
155
- - Practical and scalable: Solutions are designed to be implemented in real-world applications.
156
-
157
- #### Major Stages in the NLP Life Cycle:
158
- 1. πŸ”§ Problem Definition
159
- 2. πŸ“Š Data Collection
160
- 3. πŸ” Simple EDA (Exploratory Data Analysis)
161
- 4. 🧹 Data Preprocessing
162
- 5. πŸ“ Feature Engineering
163
- 6. πŸ‹οΈβ€β™‚οΈ Model Training
164
- 7. πŸ… Model Evaluation
165
- 8. βš™οΈ Model Tuning
166
- 9. πŸš€ Deployment
167
- 10. πŸ› οΈ Monitoring and Maintenance
168
- """)
169
-
170
- elif lifecycle_option == "🎯 Problem Definition":
171
- st.write("""
172
- #### πŸ”§ 1. Problem Definition:
173
- The first step in the NLP lifecycle is defining the problem. Understanding the objective is key to determining how NLP can be applied.
174
-
175
- - **Key Questions to Define the Problem**:
176
- - 🎯 What is the goal of this analysis (e.g., sentiment classification, topic modeling)?
177
- - πŸ“ What type of data are we dealing with (e.g., reviews, articles, social media posts)?
178
- - πŸ“Š What is the desired outcome (e.g., sentiment score, summary, or label)?
179
-
180
- **Example Problem**: Classifying customer reviews as positive or negative.
181
- """)
182
-
183
- elif lifecycle_option == "πŸ“Š Data Collection":
184
- st.write("""
185
- #### πŸ“š 2. Data Collection:
186
- Data collection is the foundation of the NLP process. It involves gathering relevant textual data from multiple sources.
187
-
188
- - **Common Data Collection Methods**:
189
- - 🌐 Public datasets (e.g., Kaggle, government websites).
190
- - πŸ”Œ APIs for data retrieval (e.g., Twitter API for tweets).
191
- - πŸ•ΈοΈ Web scraping (e.g., using BeautifulSoup or Scrapy).
192
- - βœ‹ Manual data entry in some cases.
193
-
194
- **Example**: Scraping product reviews from e-commerce websites to analyze customer sentiment.
195
-
196
- #### Extracting Data from Files:
197
- 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.
198
-
199
- **Steps**:
200
- - Identify the file format (e.g., `.csv`, `.json`).
201
- - Use functions like `pd.read_csv()` to load the data into a Pandas DataFrame.
202
- - Clean and verify the data using methods like `df.head()` or `df.info()` to inspect the first few records and data types.
203
-
204
- **Code Example**:
205
- ```python
206
- import pandas as pd
207
-
208
- # Extracting Data from a CSV File
209
- df = pd.read_csv('data.csv')
210
- print(df.head())
211
- ```
212
- """)
213
 
214
- elif lifecycle_option == "πŸ“ˆ Simple EDA":
215
- st.write("""
216
- #### πŸ” 3. Simple EDA (Exploratory Data Analysis):
217
- Simple EDA provides an initial understanding of the data. It helps identify patterns, outliers, and potential issues that may impact the analysis.
218
-
219
- - **Key Tasks in EDA**:
220
- - Check the data balance: Is the data evenly distributed or skewed?
221
- - Visualize distributions: Use histograms and boxplots.
222
- - Check for missing data: Identify any gaps in the data.
223
- - Outlier detection: Spot extreme values and decide whether to keep or remove them.
224
-
225
- **Example**: In a classification dataset, check for a 70:30 imbalance between positive and negative classes.
226
- """)
227
-
228
- elif lifecycle_option == "🧹 Data Preprocessing":
229
- st.write("""
230
- #### 🧹 4. Text Preprocessing:
231
- Text preprocessing is essential for converting raw text into a format suitable for analysis or model training.
232
-
233
- **Steps in Text Preprocessing**:
234
- - **Tokenization**: Splitting text into smaller pieces (words or sentences).
235
- - **Removing Stopwords**: Eliminate common, less meaningful words (e.g., 'the', 'and').
236
- - **Stemming and Lemmatization**: Reduce words to their root forms (e.g., 'running' to 'run').
237
- - **Removing Special Characters**: Strip out unnecessary symbols, emojis, and URLs.
238
-
239
- **Code Example**:
240
- ```python
241
- import re
242
-
243
- # Sample text
244
- text = "The quick brown fox 🦊 jumps over the lazy dog!"
245
-
246
- # Remove special characters
247
- clean_text = re.sub(r'[^a-zA-Z\s]', '', text)
248
- print(clean_text)
249
- ```
250
- **Output**: "The quick brown fox jumps over the lazy dog"
251
- """)
252
-
253
- elif lifecycle_option == "πŸ“ Feature Engineering":
254
- st.write("""
255
- #### πŸ“ 5. Feature Engineering:
256
- After preprocessing, the text must be transformed into a numerical representation for machine learning models.
257
-
258
- **Common Feature Engineering Techniques**:
259
- - **Bag of Words (BoW)**: Counts the frequency of words in the text.
260
- - **TF-IDF**: Measures word importance based on frequency and rarity.
261
- - **Word Embeddings**: Transforms words into dense vectors (e.g., Word2Vec, GloVe).
262
-
263
- **Example**: Converting the sentence "I love NLP" into a numerical vector using BoW.
264
- """)
265
-
266
- elif lifecycle_option == "πŸ‹οΈβ€β™‚οΈ Model Training":
267
- st.write("""
268
- #### πŸ‹οΈβ€β™‚οΈ 6. Model Training:
269
- 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).
270
-
271
- **Common Models**:
272
- - **Text Classification**: Naive Bayes, SVM, or deep learning models.
273
- - **Sentiment Analysis**: Logistic Regression, Naive Bayes, BERT.
274
-
275
- **Example**: Training a Naive Bayes model to classify text into categories like "Sports", "Politics", etc.
276
- """)
277
-
278
- elif lifecycle_option == "πŸ… Model Evaluation":
279
- st.write("""
280
- #### πŸ… 7. Model Evaluation:
281
- Evaluating the performance of your model is crucial to ensure its reliability.
282
-
283
- - **Metrics**: Accuracy, Precision, Recall, F1-Score.
284
- - **Confusion Matrix**: Visual representation of true positives, false positives, etc.
285
-
286
- **Example**: Evaluating a sentiment analysis model with accuracy and F1-score on test data.
287
- """)
288
-
289
- elif lifecycle_option == "πŸš€ Deployment":
290
- st.write("""
291
- #### πŸš€ 8. Deployment:
292
- Once the model is trained and evaluated, it is deployed to production for real-time use.
293
-
294
- **Key Steps**:
295
- - **Integration**: Connecting the model with a live application (e.g., a chatbot).
296
- - **Monitoring**: Regularly tracking the model’s performance over time.
297
- - **Updating**: Periodically retraining the model with new data.
298
-
299
- **Example**: Deploying a sentiment analysis model via a REST API to evaluate customer reviews in real-time.
300
- """)
301
-
302
- # Content for NLP Techniques
303
- elif st.session_state.selected_page == "βš™οΈNLP Techniques":
304
- st.write("""
305
- #### βš™οΈ Common NLP Techniques:
306
- There are several techniques in NLP that enable computers to process language in meaningful ways.
307
-
308
- **1. Tokenization**: Breaking text into individual words or phrases.
309
-
310
- **2. Named Entity Recognition (NER)**: Identifying entities such as names, locations, dates, etc.
311
-
312
- **3. Part-of-Speech (POS) Tagging**: Labeling words based on their parts of speech (e.g., noun, verb).
313
-
314
- **4. Sentiment Analysis**: Determining the sentiment expressed in the text (positive, negative, or neutral).
315
-
316
- **5. Word Embeddings**: Converting words into high-dimensional vectors to capture semantic meaning.
317
-
318
- **6. Text Classification**: Assigning predefined labels to text (e.g., spam detection, topic categorization).
319
-
320
- **7. Machine Translation**: Translating text from one language to another.
321
-
322
- **8. Text Summarization**: Condensing long texts into shorter, meaningful summaries.
323
- """)
324
  # Content for "NLP Techniques"
325
- elif st.session_state.selected_page == "βš™οΈNLP Techniques":
326
  technique_option = sidebar.radio("Select an NLP Technique:", [
327
- "NLP Techniques Overview",
328
- "Tokenization",
329
- "Stop Words Removal",
330
- "Lemmatization",
331
- "Stemming",
332
- "One-Hot Encoding",
333
- "Bag of Words (BoW)",
334
- "TF-IDF",
335
- "Word Embeddings",
336
- "Named Entity Recognition (NER)",
337
- "Part-of-Speech (POS) Tagging",
338
- "Sentiment Analysis"
339
- ])
340
-
341
- if technique_option == "NLP Techniques Overview":
342
- st.write("""
343
- ### βš™οΈ Key NLP Techniques
344
- Natural Language Processing (NLP) involves a variety of techniques for processing and analyzing text data. Here are some of the most important methods:
345
-
346
- 1. **Tokenization**: Breaking text into smaller units such as words or sentences.
347
- 2. **Part-of-Speech (POS) Tagging**: Identifying the grammatical role of words in a sentence (e.g., noun, verb, adjective).
348
- 3. **Named Entity Recognition (NER)**: Identifying and classifying entities like names, dates, and locations.
349
- 4. **Dependency Parsing**: Analyzing the syntactic structure of sentences.
350
- 5. **Sentiment Analysis**: Determining the sentiment expressed in the text (positive, negative, or neutral).
351
- 6. **Word Embeddings**: Representing words as vectors in continuous space to capture semantic relationships (e.g., Word2Vec, GloVe).
352
-
353
- **Example**: Sentiment analysis can identify whether customer reviews are positive, negative, or neutral based on the words used in the text.
354
- """)
355
-
356
- elif technique_option == "Tokenization":
357
- st.write("""
358
- #### 1. Tokenization
359
- 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.
 
360
 
361
  - **Example**:
362
- - Sentence: "Natural Language Processing is amazing!"
363
- - Tokenized words: `["Natural", "Language", "Processing", "is", "amazing"]`
364
  """)
365
 
366
- elif technique_option == "Stop Words Removal":
367
  st.write("""
368
- #### 2. Stop Words Removal
369
- 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.
370
 
371
- - **Example**: In the sentence "NLP is fun!", the stop word "is" may be removed, leaving "NLP" and "fun" for analysis.
372
  """)
373
 
374
- elif technique_option == "Lemmatization":
375
  st.write("""
376
- #### 3. Lemmatization
377
- 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.
378
 
379
  - **Example**:
380
  - "Better" β†’ "Good"
381
  - "Running" β†’ "Run"
382
  """)
383
 
384
- elif technique_option == "Stemming":
385
  st.write("""
386
- #### 4. Stemming
387
- 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.
388
 
389
  - **Example**:
390
  - "Running" β†’ "Run"
391
  - "Happiness" β†’ "Happi"
392
  """)
393
 
394
- elif technique_option == "One-Hot Encoding":
395
  st.write("""
396
- #### 5. One-Hot Encoding
397
- 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.
398
 
399
  - **Example**:
400
  - Vocabulary: `["cat", "dog", "fish"]`
401
- - Encoding for "cat": `[1, 0, 0]`
402
- - Encoding for "dog": `[0, 1, 0]`
403
-
404
- **Pros**: Simple and easy to implement.
405
- **Cons**: Results in sparse vectors and can create high-dimensional spaces when the vocabulary is large.
406
  """)
407
 
408
- elif technique_option == "Bag of Words (BoW)":
409
  st.write("""
410
- #### 6. Bag of Words (BoW)
411
- 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.
412
 
413
  - **Example**:
414
  - Text: "I love NLP"
415
  - BoW: `{"I": 1, "love": 1, "NLP": 1}`
416
-
417
- This model simply counts the frequency of each word in the text.
418
  """)
419
 
420
- elif technique_option == "TF-IDF":
421
  st.write("""
422
- #### 7. TF-IDF (Term Frequency-Inverse Document Frequency)
423
- 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.
424
 
425
- - **Example**:
426
- - 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.
427
  """)
428
 
429
- elif technique_option == "Word Embeddings":
430
  st.write("""
431
- #### 8. Word Embeddings
432
- 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.
433
 
434
- - **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.
 
435
  """)
436
 
437
- elif technique_option == "Named Entity Recognition (NER)":
438
  st.write("""
439
- #### 9. Named Entity Recognition (NER)
440
- 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.
441
 
442
  - **Example**:
443
- - Text: "Barack Obama was born in Hawaii."
444
- - Extracted Entities: `["Barack Obama" (Person), "Hawaii" (Location)]`
445
  """)
446
 
447
- elif technique_option == "Part-of-Speech (POS) Tagging":
448
  st.write("""
449
- #### 10. Part-of-Speech (POS) Tagging
450
- 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.
451
 
452
  - **Example**:
453
- - Sentence: "The cat sat on the mat."
454
- - POS Tags: `[("The", "DT"), ("cat", "NN"), ("sat", "VBD"), ("on", "IN"), ("the", "DT"), ("mat", "NN")]`
455
  """)
456
 
457
- elif technique_option == "Sentiment Analysis":
458
  st.write("""
459
- #### 11. Sentiment Analysis
460
- 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.
461
 
462
  - **Example**:
463
- - Text: "I love this product!"
464
- - Sentiment: Positive
465
-
466
- Sentiment analysis helps businesses and organizations understand public perception and customer satisfaction.
467
- """)
468
-
469
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ )