Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
# Title of the app
|
| 4 |
st.title('Natural Language Processing (NLP) Overview')
|
| 5 |
|
|
@@ -23,6 +27,39 @@ Some common NLP tasks include:
|
|
| 23 |
- **Understanding and generating human language**: NLP allows machines to understand the meaning behind words, sentences, and paragraphs, making human-machine interactions more natural.
|
| 24 |
""")
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
# Define the available NLP lifecycle stages
|
| 27 |
lifecycle_stages = ['Data Collection', 'Text Preprocessing', 'Text Representation',
|
| 28 |
'Model Training', 'Evaluation', 'Deployment']
|
|
@@ -30,8 +67,16 @@ lifecycle_stages = ['Data Collection', 'Text Preprocessing', 'Text Representatio
|
|
| 30 |
# Add a selectbox for the user to choose a lifecycle stage
|
| 31 |
selected_lifecycle_stage = st.selectbox('Choose an NLP Lifecycle Stage:', lifecycle_stages)
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
if selected_lifecycle_stage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
st.write("""
|
| 36 |
### Data Collection:
|
| 37 |
The first stage of the NLP lifecycle involves gathering text data from various sources such as:
|
|
@@ -48,7 +93,7 @@ if selected_lifecycle_stage == 'Data Collection':
|
|
| 48 |
- The data can be structured (e.g., databases) or unstructured (e.g., plain text from websites).
|
| 49 |
""")
|
| 50 |
|
| 51 |
-
elif
|
| 52 |
st.write("""
|
| 53 |
### Text Preprocessing:
|
| 54 |
Text preprocessing is essential for preparing raw text data for analysis. The steps involved include:
|
|
@@ -63,7 +108,7 @@ elif selected_lifecycle_stage == 'Text Preprocessing':
|
|
| 63 |
- Preprocessing is crucial for reducing noise in the text, ensuring that the machine learning models focus on the important features.
|
| 64 |
""")
|
| 65 |
|
| 66 |
-
elif
|
| 67 |
st.write("""
|
| 68 |
### Text Representation:
|
| 69 |
After preprocessing, text needs to be converted into a numerical form for machine learning algorithms.
|
|
@@ -76,7 +121,7 @@ elif selected_lifecycle_stage == 'Text Representation':
|
|
| 76 |
- BoW and TF-IDF are more traditional methods, while word embeddings capture semantic relationships and are widely used in modern NLP tasks.
|
| 77 |
""")
|
| 78 |
|
| 79 |
-
elif
|
| 80 |
st.write("""
|
| 81 |
### Model Training:
|
| 82 |
In the model training stage, machine learning algorithms are used to train a model on the preprocessed and represented data.
|
|
@@ -90,7 +135,7 @@ elif selected_lifecycle_stage == 'Model Training':
|
|
| 90 |
- The model learns patterns and relationships in the text data, which it will use to make predictions.
|
| 91 |
""")
|
| 92 |
|
| 93 |
-
elif
|
| 94 |
st.write("""
|
| 95 |
### Evaluation:
|
| 96 |
Once a model is trained, it is evaluated to understand its performance. Common evaluation metrics include:
|
|
@@ -105,7 +150,7 @@ elif selected_lifecycle_stage == 'Evaluation':
|
|
| 105 |
- It ensures that the model will perform well on unseen data (real-world applications).
|
| 106 |
""")
|
| 107 |
|
| 108 |
-
elif
|
| 109 |
st.write("""
|
| 110 |
### Deployment:
|
| 111 |
The final stage is deploying the trained model for real-time use. The model can be integrated into applications like:
|
|
@@ -127,8 +172,15 @@ tasks = ['Text Classification', 'Sentiment Analysis', 'Named Entity Recognition
|
|
| 127 |
# Add a selectbox for the user to choose an NLP task
|
| 128 |
selected_task = st.selectbox('Choose an NLP Task:', tasks)
|
| 129 |
|
| 130 |
-
#
|
| 131 |
-
if selected_task
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
st.write("""
|
| 133 |
### Text Classification:
|
| 134 |
Text Classification is the task of categorizing text into predefined labels.
|
|
@@ -141,7 +193,7 @@ if selected_task == 'Text Classification':
|
|
| 141 |
- Word Embeddings
|
| 142 |
""")
|
| 143 |
|
| 144 |
-
elif
|
| 145 |
st.write("""
|
| 146 |
### Sentiment Analysis:
|
| 147 |
Sentiment Analysis determines the sentiment of a given text, such as whether it is positive, negative, or neutral.
|
|
@@ -152,7 +204,7 @@ elif selected_task == 'Sentiment Analysis':
|
|
| 152 |
- Machine Learning (e.g., Naive Bayes, SVM)
|
| 153 |
""")
|
| 154 |
|
| 155 |
-
elif
|
| 156 |
st.write("""
|
| 157 |
### Named Entity Recognition (NER):
|
| 158 |
NER is the process of identifying named entities in text, such as people, organizations, dates, locations, etc.
|
|
@@ -163,7 +215,7 @@ elif selected_task == 'Named Entity Recognition (NER)':
|
|
| 163 |
- Machine Learning-based NER (e.g., CRF, LSTM)
|
| 164 |
""")
|
| 165 |
|
| 166 |
-
elif
|
| 167 |
st.write("""
|
| 168 |
### Language Translation:
|
| 169 |
Language Translation involves translating text from one language to another.
|
|
@@ -174,7 +226,7 @@ elif selected_task == 'Language Translation':
|
|
| 174 |
- Neural Machine Translation (NMT)
|
| 175 |
""")
|
| 176 |
|
| 177 |
-
elif
|
| 178 |
st.write("""
|
| 179 |
### Text Summarization:
|
| 180 |
Text Summarization involves condensing long pieces of text into a shorter, meaningful version.
|
|
@@ -185,7 +237,7 @@ elif selected_task == 'Text Summarization':
|
|
| 185 |
- Abstractive Summarization
|
| 186 |
""")
|
| 187 |
|
| 188 |
-
elif
|
| 189 |
st.write("""
|
| 190 |
### Part-of-Speech (POS) Tagging:
|
| 191 |
POS Tagging involves identifying the grammatical components of a sentence, such as nouns, verbs, adjectives, etc.
|
|
@@ -196,7 +248,7 @@ elif selected_task == 'Part-of-Speech Tagging':
|
|
| 196 |
- Machine Learning-based POS Tagging (e.g., HMM, CRF)
|
| 197 |
""")
|
| 198 |
|
| 199 |
-
elif
|
| 200 |
st.write("""
|
| 201 |
### Text Generation:
|
| 202 |
Text Generation is the task of generating new, coherent text based on some input.
|
|
@@ -208,7 +260,7 @@ elif selected_task == 'Text Generation':
|
|
| 208 |
- Transformer-based models (e.g., GPT-3)
|
| 209 |
""")
|
| 210 |
|
| 211 |
-
elif
|
| 212 |
st.write("""
|
| 213 |
### Text Similarity:
|
| 214 |
Text Similarity involves measuring the similarity between two pieces of text.
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# Function to redirect to different pages
|
| 4 |
+
def redirect_to_page(page):
|
| 5 |
+
st.experimental_set_query_params(page=page)
|
| 6 |
+
|
| 7 |
# Title of the app
|
| 8 |
st.title('Natural Language Processing (NLP) Overview')
|
| 9 |
|
|
|
|
| 27 |
- **Understanding and generating human language**: NLP allows machines to understand the meaning behind words, sentences, and paragraphs, making human-machine interactions more natural.
|
| 28 |
""")
|
| 29 |
|
| 30 |
+
# NLP Lifecycle
|
| 31 |
+
st.header('NLP Lifecycle')
|
| 32 |
+
st.write("""
|
| 33 |
+
The NLP lifecycle consists of several stages, each contributing to transforming raw text into useful insights or predictions. Here are the stages of the NLP lifecycle:
|
| 34 |
+
|
| 35 |
+
1. **Data Collection**: Collect text data from various sources such as websites, social media, surveys, etc.
|
| 36 |
+
2. **Text Preprocessing**: Clean and preprocess the text data, removing unnecessary information like stopwords, punctuation, etc.
|
| 37 |
+
3. **Text Representation**: Convert the preprocessed text into numerical form using methods like Bag of Words (BoW), TF-IDF, or Word Embeddings.
|
| 38 |
+
4. **Model Training**: Train machine learning models on the text data to solve the NLP problem, such as classification or entity recognition.
|
| 39 |
+
5. **Evaluation**: Assess the model's performance using evaluation metrics like accuracy, precision, recall, and F1-score.
|
| 40 |
+
6. **Deployment**: Deploy the trained model to a real-world application, such as a chatbot or sentiment analysis tool, and continuously monitor and retrain the model as needed.
|
| 41 |
+
|
| 42 |
+
These stages are crucial for building effective NLP applications that provide value to users.
|
| 43 |
+
""")
|
| 44 |
+
|
| 45 |
+
# NLP Techniques
|
| 46 |
+
st.header('NLP Techniques')
|
| 47 |
+
st.write("""
|
| 48 |
+
Some key techniques used in NLP include:
|
| 49 |
+
|
| 50 |
+
- **Tokenization**: The process of breaking down text into smaller units, such as words or sentences.
|
| 51 |
+
- **Stop Word Removal**: The process of removing common words (e.g., "the", "a", "and") that do not contribute significant meaning to the text.
|
| 52 |
+
- **Stemming**: Reducing words to their root form (e.g., "running" → "run").
|
| 53 |
+
- **Lemmatization**: Similar to stemming but more accurate, reducing words to their dictionary form (e.g., "better" → "good").
|
| 54 |
+
- **Named Entity Recognition (NER)**: Identifying entities such as people, organizations, and locations within text.
|
| 55 |
+
- **Part-of-Speech Tagging**: Identifying the grammatical structure of words in a sentence, such as nouns, verbs, adjectives, etc.
|
| 56 |
+
- **Word Embeddings**: A technique that maps words into continuous vector space, capturing semantic relationships between words (e.g., Word2Vec, GloVe).
|
| 57 |
+
- **Text Classification**: Categorizing text into predefined labels or categories (e.g., spam detection, sentiment analysis).
|
| 58 |
+
- **Sentiment Analysis**: Determining the sentiment expressed in a text, such as whether it is positive, negative, or neutral.
|
| 59 |
+
|
| 60 |
+
These techniques are the building blocks for solving various NLP tasks and are essential for developing applications that can understand human language.
|
| 61 |
+
""")
|
| 62 |
+
|
| 63 |
# Define the available NLP lifecycle stages
|
| 64 |
lifecycle_stages = ['Data Collection', 'Text Preprocessing', 'Text Representation',
|
| 65 |
'Model Training', 'Evaluation', 'Deployment']
|
|
|
|
| 67 |
# Add a selectbox for the user to choose a lifecycle stage
|
| 68 |
selected_lifecycle_stage = st.selectbox('Choose an NLP Lifecycle Stage:', lifecycle_stages)
|
| 69 |
|
| 70 |
+
# If lifecycle stage is selected, update query params and display new content
|
| 71 |
+
if selected_lifecycle_stage:
|
| 72 |
+
redirect_to_page(selected_lifecycle_stage)
|
| 73 |
+
|
| 74 |
+
# Get the page from the query params
|
| 75 |
+
params = st.experimental_get_query_params()
|
| 76 |
+
selected_page = params.get("page", [None])[0]
|
| 77 |
+
|
| 78 |
+
# Define content for different lifecycle stages
|
| 79 |
+
if selected_page == 'Data Collection':
|
| 80 |
st.write("""
|
| 81 |
### Data Collection:
|
| 82 |
The first stage of the NLP lifecycle involves gathering text data from various sources such as:
|
|
|
|
| 93 |
- The data can be structured (e.g., databases) or unstructured (e.g., plain text from websites).
|
| 94 |
""")
|
| 95 |
|
| 96 |
+
elif selected_page == 'Text Preprocessing':
|
| 97 |
st.write("""
|
| 98 |
### Text Preprocessing:
|
| 99 |
Text preprocessing is essential for preparing raw text data for analysis. The steps involved include:
|
|
|
|
| 108 |
- Preprocessing is crucial for reducing noise in the text, ensuring that the machine learning models focus on the important features.
|
| 109 |
""")
|
| 110 |
|
| 111 |
+
elif selected_page == 'Text Representation':
|
| 112 |
st.write("""
|
| 113 |
### Text Representation:
|
| 114 |
After preprocessing, text needs to be converted into a numerical form for machine learning algorithms.
|
|
|
|
| 121 |
- BoW and TF-IDF are more traditional methods, while word embeddings capture semantic relationships and are widely used in modern NLP tasks.
|
| 122 |
""")
|
| 123 |
|
| 124 |
+
elif selected_page == 'Model Training':
|
| 125 |
st.write("""
|
| 126 |
### Model Training:
|
| 127 |
In the model training stage, machine learning algorithms are used to train a model on the preprocessed and represented data.
|
|
|
|
| 135 |
- The model learns patterns and relationships in the text data, which it will use to make predictions.
|
| 136 |
""")
|
| 137 |
|
| 138 |
+
elif selected_page == 'Evaluation':
|
| 139 |
st.write("""
|
| 140 |
### Evaluation:
|
| 141 |
Once a model is trained, it is evaluated to understand its performance. Common evaluation metrics include:
|
|
|
|
| 150 |
- It ensures that the model will perform well on unseen data (real-world applications).
|
| 151 |
""")
|
| 152 |
|
| 153 |
+
elif selected_page == 'Deployment':
|
| 154 |
st.write("""
|
| 155 |
### Deployment:
|
| 156 |
The final stage is deploying the trained model for real-time use. The model can be integrated into applications like:
|
|
|
|
| 172 |
# Add a selectbox for the user to choose an NLP task
|
| 173 |
selected_task = st.selectbox('Choose an NLP Task:', tasks)
|
| 174 |
|
| 175 |
+
# If a task is selected, update query params and display new content
|
| 176 |
+
if selected_task:
|
| 177 |
+
redirect_to_page(selected_task)
|
| 178 |
+
|
| 179 |
+
# Get the task from the query params
|
| 180 |
+
selected_task_page = params.get("page", [None])[0]
|
| 181 |
+
|
| 182 |
+
# Define content for different NLP tasks
|
| 183 |
+
if selected_task_page == 'Text Classification':
|
| 184 |
st.write("""
|
| 185 |
### Text Classification:
|
| 186 |
Text Classification is the task of categorizing text into predefined labels.
|
|
|
|
| 193 |
- Word Embeddings
|
| 194 |
""")
|
| 195 |
|
| 196 |
+
elif selected_task_page == 'Sentiment Analysis':
|
| 197 |
st.write("""
|
| 198 |
### Sentiment Analysis:
|
| 199 |
Sentiment Analysis determines the sentiment of a given text, such as whether it is positive, negative, or neutral.
|
|
|
|
| 204 |
- Machine Learning (e.g., Naive Bayes, SVM)
|
| 205 |
""")
|
| 206 |
|
| 207 |
+
elif selected_task_page == 'Named Entity Recognition (NER)':
|
| 208 |
st.write("""
|
| 209 |
### Named Entity Recognition (NER):
|
| 210 |
NER is the process of identifying named entities in text, such as people, organizations, dates, locations, etc.
|
|
|
|
| 215 |
- Machine Learning-based NER (e.g., CRF, LSTM)
|
| 216 |
""")
|
| 217 |
|
| 218 |
+
elif selected_task_page == 'Language Translation':
|
| 219 |
st.write("""
|
| 220 |
### Language Translation:
|
| 221 |
Language Translation involves translating text from one language to another.
|
|
|
|
| 226 |
- Neural Machine Translation (NMT)
|
| 227 |
""")
|
| 228 |
|
| 229 |
+
elif selected_task_page == 'Text Summarization':
|
| 230 |
st.write("""
|
| 231 |
### Text Summarization:
|
| 232 |
Text Summarization involves condensing long pieces of text into a shorter, meaningful version.
|
|
|
|
| 237 |
- Abstractive Summarization
|
| 238 |
""")
|
| 239 |
|
| 240 |
+
elif selected_task_page == 'Part-of-Speech Tagging':
|
| 241 |
st.write("""
|
| 242 |
### Part-of-Speech (POS) Tagging:
|
| 243 |
POS Tagging involves identifying the grammatical components of a sentence, such as nouns, verbs, adjectives, etc.
|
|
|
|
| 248 |
- Machine Learning-based POS Tagging (e.g., HMM, CRF)
|
| 249 |
""")
|
| 250 |
|
| 251 |
+
elif selected_task_page == 'Text Generation':
|
| 252 |
st.write("""
|
| 253 |
### Text Generation:
|
| 254 |
Text Generation is the task of generating new, coherent text based on some input.
|
|
|
|
| 260 |
- Transformer-based models (e.g., GPT-3)
|
| 261 |
""")
|
| 262 |
|
| 263 |
+
elif selected_task_page == 'Text Similarity':
|
| 264 |
st.write("""
|
| 265 |
### Text Similarity:
|
| 266 |
Text Similarity involves measuring the similarity between two pieces of text.
|