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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +453 -115
app.py CHANGED
@@ -1,24 +1,13 @@
1
  import streamlit as st
2
 
3
- # Sidebar for navigation with updated emojis and colors
4
  sidebar = st.sidebar
5
 
6
  # Sidebar header
7
- sidebar.markdown(
8
- """
9
- <style>
10
- .sidebar .sidebar-content {
11
- background-color: #F8F9FA;
12
- }
13
- </style>
14
- """,
15
- unsafe_allow_html=True,
16
- )
17
-
18
- sidebar.header('🌟 Explore NLP!')
19
 
20
  # Sidebar options for NLP Overview, Lifecycle, and Techniques
21
- sidebar_option = sidebar.radio('🧭 Navigate:', ['Introduction 🌐', 'NLP Lifecycle πŸ”„', 'NLP Techniques βš™οΈ'])
22
 
23
  # Store the selected page in session state
24
  if 'selected_page' not in st.session_state:
@@ -28,104 +17,453 @@ if 'selected_page' not in st.session_state:
28
  if sidebar_option != st.session_state.selected_page:
29
  st.session_state.selected_page = sidebar_option
30
 
31
- # Define colors and style for content section
32
- st.markdown(
33
- """
34
- <style>
35
- body {
36
- font-family: 'Helvetica', sans-serif;
37
- }
38
- .stApp {
39
- background-color: #FFFFFF;
40
- }
41
- .title {
42
- color: #1E88E5;
43
- font-weight: bold;
44
- }
45
- .subtitle {
46
- color: #6D4C41;
47
- font-style: italic;
48
- }
49
- .content {
50
- font-size: 16px;
51
- line-height: 1.6;
52
- color: #4E4E4E;
53
- }
54
- ul {
55
- list-style-type: none;
56
- }
57
- li {
58
- padding: 5px 0;
59
- }
60
- </style>
61
- """,
62
- unsafe_allow_html=True,
63
- )
64
-
65
- # Page content rendering dynamically based on selection
66
- if st.session_state.selected_page == 'Introduction 🌐':
67
- st.title('✨ What is Natural Language Processing (NLP)?')
68
- st.markdown(
69
- """
70
- <div class="content">
71
- <p>Natural Language Processing (NLP) bridges the gap between human communication and computer understanding. It enables machines to interpret, analyze, and generate human language seamlessly.</p>
72
- <ul>
73
- <li><b>Syntax</b>: Sentence structure and arrangement.</li>
74
- <li><b>Semantics</b>: Word and sentence meanings.</li>
75
- <li><b>Applications</b>: Translation, sentiment analysis, and more!</li>
76
- </ul>
77
- </div>
78
- """,
79
- unsafe_allow_html=True,
80
- )
81
-
82
- elif st.session_state.selected_page == 'NLP Lifecycle πŸ”„':
83
- st.title('πŸ”„ NLP Lifecycle: From Data to Insight')
84
- lifecycle_step = sidebar.radio(
85
- "Pick a step:",
86
- [
87
- "Overview 🌟",
88
- "Define Problem 🎯",
89
- "Data Collection πŸ“š",
90
- "Preprocessing 🧹",
91
- "Model Training πŸ‹οΈβ€β™‚οΈ",
92
- "Evaluation πŸ…",
93
- "Deployment πŸš€",
94
- ],
95
- )
96
-
97
- if lifecycle_step == "Overview 🌟":
98
- st.write("The NLP Lifecycle transforms raw text into actionable insights in 7 key stages.")
99
- elif lifecycle_step == "Define Problem 🎯":
100
- st.write("Clearly define objectives and goals for text analysis.")
101
- elif lifecycle_step == "Data Collection πŸ“š":
102
- st.write("Source relevant data using APIs, scraping, or repositories.")
103
- elif lifecycle_step == "Preprocessing 🧹":
104
- st.write("Clean and organize text data to ensure model readiness.")
105
- elif lifecycle_step == "Model Training πŸ‹οΈβ€β™‚οΈ":
106
- st.write("Train algorithms using advanced models and techniques.")
107
- elif lifecycle_step == "Evaluation πŸ…":
108
- st.write("Evaluate model performance with precision and recall.")
109
- elif lifecycle_step == "Deployment πŸš€":
110
- st.write("Deploy models into real-world applications like chatbots or translators.")
111
-
112
- elif st.session_state.selected_page == 'NLP Techniques βš™οΈ':
113
- st.title('βš™οΈ NLP Techniques: How it Works')
114
- technique = sidebar.radio(
115
- "Select a technique:",
116
- [
117
- "Tokenization πŸ—‚οΈ",
118
- "Stop Words Removal 🚫",
119
- "Lemmatization βœ‚οΈ",
120
- "Word Embeddings 🧩",
121
- ],
122
- )
123
-
124
- if technique == "Tokenization πŸ—‚οΈ":
125
- st.write("Splitting sentences into manageable units (e.g., words).")
126
- elif technique == "Stop Words Removal 🚫":
127
- st.write("Eliminating common words to focus on the essence.")
128
- elif technique == "Lemmatization βœ‚οΈ":
129
- st.write("Bringing words to their root form (e.g., 'running' β†’ 'run').")
130
- elif technique == "Word Embeddings 🧩":
131
- st.write("Mapping words into meaningful numerical representations.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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:
 
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
+