Update app.py
Browse files
app.py
CHANGED
|
@@ -1,215 +1,221 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
#
|
| 4 |
-
st.title(
|
| 5 |
-
|
| 6 |
-
#
|
| 7 |
-
st.
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
- Sentiment Analysis
|
| 20 |
-
- Machine Translation
|
| 21 |
-
- Chatbots
|
| 22 |
-
- Speech Recognition
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
elif page == "NLP Life Cycle":
|
| 28 |
-
st.header("NLP Life Cycle")
|
| 29 |
-
|
| 30 |
-
st.subheader("1. Problem Definition")
|
| 31 |
-
st.write("""
|
| 32 |
-
In this phase, the problem you're trying to solve with NLP is defined. Examples include:
|
| 33 |
-
- Sentiment analysis
|
| 34 |
-
- Named entity recognition (NER)
|
| 35 |
-
- Text classification
|
| 36 |
-
- Machine translation
|
| 37 |
-
- Language generation
|
| 38 |
-
""")
|
| 39 |
-
|
| 40 |
-
st.subheader("2. Data Collection")
|
| 41 |
-
st.write("""
|
| 42 |
-
Gather relevant textual data. Sources include:
|
| 43 |
-
- Web scraping (e.g., using BeautifulSoup or Scrapy)
|
| 44 |
-
- APIs (e.g., Twitter API)
|
| 45 |
-
- Pre-existing datasets (e.g., Kaggle, UCI repositories)
|
| 46 |
-
- User-generated content (e.g., reviews, social media)
|
| 47 |
-
""")
|
| 48 |
-
|
| 49 |
-
st.subheader("3. Data Preprocessing")
|
| 50 |
-
st.write("""
|
| 51 |
-
Prepare the data for modeling by performing tasks such as:
|
| 52 |
-
- Text cleaning (removing unnecessary characters, punctuation)
|
| 53 |
-
- Tokenization (splitting text into words/sentences)
|
| 54 |
-
- Stopword removal
|
| 55 |
-
- Stemming or lemmatization
|
| 56 |
-
- Part-of-speech tagging
|
| 57 |
""")
|
| 58 |
|
| 59 |
-
|
| 60 |
st.write("""
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
""")
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
- Unsupervised learning (e.g., K-means clustering)
|
| 73 |
-
- Deep learning (e.g., RNNs, LSTMs, BERT)
|
| 74 |
""")
|
| 75 |
|
| 76 |
-
|
| 77 |
st.write("""
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
""")
|
| 84 |
|
| 85 |
-
|
| 86 |
st.write("""
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
""")
|
| 92 |
|
| 93 |
-
|
| 94 |
st.write("""
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
""")
|
| 100 |
|
| 101 |
-
|
| 102 |
st.write("""
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
""")
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
- Interactive dashboards (e.g., using Streamlit or Dash)
|
| 114 |
-
- Interface design (e.g., web or mobile apps)
|
| 115 |
-
""")
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
|
| 120 |
-
|
|
|
|
| 121 |
st.write("""
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
| 129 |
""")
|
| 130 |
|
| 131 |
-
|
| 132 |
st.write("""
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
""")
|
| 141 |
|
| 142 |
-
|
| 143 |
st.write("""
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
- Stemming: "run"
|
| 152 |
-
- Lemmatization: "run"
|
| 153 |
""")
|
| 154 |
|
| 155 |
-
|
| 156 |
st.write("""
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
""")
|
| 165 |
|
| 166 |
-
|
| 167 |
st.write("""
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
""")
|
| 176 |
|
| 177 |
-
|
| 178 |
st.write("""
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
""")
|
| 187 |
|
| 188 |
-
|
| 189 |
st.write("""
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
Text summarization helps in condensing large documents into key points.
|
| 200 |
""")
|
| 201 |
|
| 202 |
-
|
| 203 |
st.write("""
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
|
|
|
| 211 |
""")
|
| 212 |
-
|
| 213 |
-
# Footer
|
| 214 |
-
st.sidebar.write("---")
|
| 215 |
-
st.sidebar.write("Developed with ❤️ using Streamlit.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# Title of the app
|
| 4 |
+
st.title('Natural Language Processing (NLP) Overview')
|
| 5 |
+
|
| 6 |
+
# Introduction to NLP
|
| 7 |
+
st.header('Introduction to Natural Language Processing (NLP)')
|
| 8 |
+
st.write("""
|
| 9 |
+
Natural Language Processing (NLP) is a branch of artificial intelligence (AI) that enables machines to understand,
|
| 10 |
+
interpret, and generate human language. NLP is used in a wide variety of applications, such as chatbots, search engines,
|
| 11 |
+
translation systems, and voice assistants.
|
| 12 |
+
|
| 13 |
+
Some common NLP tasks include:
|
| 14 |
+
- Text Classification
|
| 15 |
+
- Sentiment Analysis
|
| 16 |
+
- Named Entity Recognition (NER)
|
| 17 |
+
- Language Translation
|
| 18 |
+
- Text Summarization
|
| 19 |
+
- Part-of-Speech Tagging
|
| 20 |
+
|
| 21 |
+
### Importance of NLP:
|
| 22 |
+
- **Automation of manual tasks**: NLP is widely used to automate tasks such as document categorization, content summarization, and sentiment analysis.
|
| 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']
|
| 29 |
+
|
| 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 |
+
# Define the pages for each NLP lifecycle stage
|
| 34 |
+
if selected_lifecycle_stage == 'Data Collection':
|
| 35 |
+
st.write("""
|
| 36 |
+
### Data Collection:
|
| 37 |
+
The first stage of the NLP lifecycle involves gathering text data from various sources such as:
|
| 38 |
+
- Social media posts
|
| 39 |
+
- Websites and blogs
|
| 40 |
+
- News articles
|
| 41 |
+
- Customer reviews
|
| 42 |
+
- Books and papers
|
| 43 |
|
| 44 |
+
**Example**: Collecting customer feedback from surveys or scraping news articles to analyze sentiment.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
**Key Points**:
|
| 47 |
+
- Data must be relevant to the task you are solving (e.g., sentiment analysis, text classification).
|
| 48 |
+
- The data can be structured (e.g., databases) or unstructured (e.g., plain text from websites).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
""")
|
| 50 |
|
| 51 |
+
elif selected_lifecycle_stage == 'Text Preprocessing':
|
| 52 |
st.write("""
|
| 53 |
+
### Text Preprocessing:
|
| 54 |
+
Text preprocessing is essential for preparing raw text data for analysis. The steps involved include:
|
| 55 |
+
- **Tokenization**: Breaking text into smaller units like words or sentences.
|
| 56 |
+
- **Removing Stop Words**: Stop words (e.g., "the", "a", "is") are common words that don't carry much information and are often removed.
|
| 57 |
+
- **Stemming**: Reducing words to their base or root form (e.g., "running" → "run").
|
| 58 |
+
- **Lemmatization**: Similar to stemming but more accurate, it reduces words to their dictionary form (e.g., "better" → "good").
|
| 59 |
+
- **Lowercasing**: Converting all text to lowercase to avoid treating the same word in different cases (e.g., "Hello" vs "hello").
|
| 60 |
+
- **Removing Special Characters**: Eliminating punctuation marks, numbers, and other non-alphabetic characters that may not contribute to the analysis.
|
| 61 |
+
|
| 62 |
+
**Key Points**:
|
| 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 selected_lifecycle_stage == 'Text Representation':
|
| 67 |
st.write("""
|
| 68 |
+
### Text Representation:
|
| 69 |
+
After preprocessing, text needs to be converted into a numerical form for machine learning algorithms.
|
| 70 |
+
The common techniques for text representation include:
|
| 71 |
+
- **Bag of Words (BoW)**: Converts text into a matrix of word frequencies.
|
| 72 |
+
- **TF-IDF (Term Frequency - Inverse Document Frequency)**: A statistical method to evaluate the importance of a word within a document relative to a collection of documents.
|
| 73 |
+
- **Word Embeddings**: Maps words to dense vectors, preserving semantic meaning (e.g., Word2Vec, GloVe, FastText).
|
| 74 |
+
|
| 75 |
+
**Key Points**:
|
| 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 selected_lifecycle_stage == 'Model Training':
|
| 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.
|
| 83 |
+
The choice of model depends on the task at hand. For example:
|
| 84 |
+
- For **text classification**, algorithms like Naive Bayes, SVM, or neural networks are commonly used.
|
| 85 |
+
- For **named entity recognition (NER)**, sequence models such as CRF (Conditional Random Fields) or LSTM (Long Short-Term Memory) can be used.
|
| 86 |
+
- For **sentiment analysis**, simple models like logistic regression or complex models like BERT can be employed.
|
| 87 |
+
|
| 88 |
+
**Key Points**:
|
| 89 |
+
- The choice of model depends on the task (e.g., classification, sequence generation, summarization).
|
| 90 |
+
- The model learns patterns and relationships in the text data, which it will use to make predictions.
|
| 91 |
""")
|
| 92 |
|
| 93 |
+
elif selected_lifecycle_stage == 'Evaluation':
|
| 94 |
st.write("""
|
| 95 |
+
### Evaluation:
|
| 96 |
+
Once a model is trained, it is evaluated to understand its performance. Common evaluation metrics include:
|
| 97 |
+
- **Accuracy**: The proportion of correct predictions.
|
| 98 |
+
- **Precision**: The ratio of correctly predicted positive observations to the total predicted positives.
|
| 99 |
+
- **Recall**: The ratio of correctly predicted positive observations to the total actual positives.
|
| 100 |
+
- **F1-Score**: The weighted average of precision and recall.
|
| 101 |
+
- **ROC and AUC**: Performance measurement for classification problems.
|
| 102 |
+
|
| 103 |
+
**Key Points**:
|
| 104 |
+
- Evaluation helps determine if the model is overfitting (memorizing the training data) or underfitting (not learning the data properly).
|
| 105 |
+
- It ensures that the model will perform well on unseen data (real-world applications).
|
| 106 |
""")
|
| 107 |
|
| 108 |
+
elif selected_lifecycle_stage == 'Deployment':
|
| 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:
|
| 112 |
+
- Chatbots for customer service
|
| 113 |
+
- Sentiment analysis for social media monitoring
|
| 114 |
+
- Language translation systems
|
| 115 |
+
- Search engines for better query results
|
| 116 |
+
|
| 117 |
+
**Key Points**:
|
| 118 |
+
- Continuous monitoring and maintenance are necessary to ensure that the model stays effective over time, especially as new data comes in.
|
| 119 |
+
- Retraining may be required periodically to account for changes in language usage or new trends in the data.
|
| 120 |
""")
|
| 121 |
|
| 122 |
+
# Define the available NLP tasks
|
| 123 |
+
tasks = ['Text Classification', 'Sentiment Analysis', 'Named Entity Recognition (NER)',
|
| 124 |
+
'Language Translation', 'Text Summarization', 'Part-of-Speech Tagging',
|
| 125 |
+
'Text Generation', 'Text Similarity']
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
# Add a selectbox for the user to choose an NLP task
|
| 128 |
+
selected_task = st.selectbox('Choose an NLP Task:', tasks)
|
| 129 |
|
| 130 |
+
# Define the pages for each NLP task
|
| 131 |
+
if selected_task == 'Text Classification':
|
| 132 |
st.write("""
|
| 133 |
+
### Text Classification:
|
| 134 |
+
Text Classification is the task of categorizing text into predefined labels.
|
| 135 |
+
This can be used for spam detection, topic categorization, etc.
|
| 136 |
+
**Example**: Categorizing news articles into topics like 'Sports', 'Politics', etc.
|
| 137 |
+
|
| 138 |
+
**Techniques**:
|
| 139 |
+
- Bag of Words (BoW)
|
| 140 |
+
- TF-IDF
|
| 141 |
+
- Word Embeddings
|
| 142 |
""")
|
| 143 |
|
| 144 |
+
elif selected_task == 'Sentiment Analysis':
|
| 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.
|
| 148 |
+
**Example**: Analyzing product reviews to determine customer satisfaction.
|
| 149 |
+
|
| 150 |
+
**Techniques**:
|
| 151 |
+
- Lexicon-based (e.g., VADER)
|
| 152 |
+
- Machine Learning (e.g., Naive Bayes, SVM)
|
| 153 |
""")
|
| 154 |
|
| 155 |
+
elif selected_task == 'Named Entity Recognition (NER)':
|
| 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.
|
| 159 |
+
**Example**: Extracting names of people and organizations from news articles.
|
| 160 |
+
|
| 161 |
+
**Techniques**:
|
| 162 |
+
- Rule-based NER
|
| 163 |
+
- Machine Learning-based NER (e.g., CRF, LSTM)
|
|
|
|
|
|
|
| 164 |
""")
|
| 165 |
|
| 166 |
+
elif selected_task == 'Language Translation':
|
| 167 |
st.write("""
|
| 168 |
+
### Language Translation:
|
| 169 |
+
Language Translation involves translating text from one language to another.
|
| 170 |
+
**Example**: Translating a sentence from English to Spanish.
|
| 171 |
+
|
| 172 |
+
**Techniques**:
|
| 173 |
+
- Statistical Machine Translation (SMT)
|
| 174 |
+
- Neural Machine Translation (NMT)
|
| 175 |
""")
|
| 176 |
|
| 177 |
+
elif selected_task == 'Text Summarization':
|
| 178 |
st.write("""
|
| 179 |
+
### Text Summarization:
|
| 180 |
+
Text Summarization involves condensing long pieces of text into a shorter, meaningful version.
|
| 181 |
+
**Example**: Generating a summary of a long article.
|
| 182 |
+
|
| 183 |
+
**Techniques**:
|
| 184 |
+
- Extractive Summarization
|
| 185 |
+
- Abstractive Summarization
|
| 186 |
""")
|
| 187 |
|
| 188 |
+
elif selected_task == 'Part-of-Speech Tagging':
|
| 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.
|
| 192 |
+
**Example**: Tagging words in a sentence: 'I am learning NLP' -> [('I', 'PRP'), ('am', 'VBP'), ('learning', 'VBG'), ('NLP', 'NN')]
|
| 193 |
+
|
| 194 |
+
**Techniques**:
|
| 195 |
+
- Rule-based POS Tagging
|
| 196 |
+
- Machine Learning-based POS Tagging (e.g., HMM, CRF)
|
| 197 |
""")
|
| 198 |
|
| 199 |
+
elif selected_task == 'Text Generation':
|
| 200 |
st.write("""
|
| 201 |
+
### Text Generation:
|
| 202 |
+
Text Generation is the task of generating new, coherent text based on some input.
|
| 203 |
+
**Example**: Generating a paragraph based on a given topic or generating captions for images.
|
| 204 |
+
|
| 205 |
+
**Techniques**:
|
| 206 |
+
- RNN (Recurrent Neural Networks)
|
| 207 |
+
- LSTM (Long Short-Term Memory)
|
| 208 |
+
- Transformer-based models (e.g., GPT-3)
|
|
|
|
|
|
|
| 209 |
""")
|
| 210 |
|
| 211 |
+
elif selected_task == 'Text Similarity':
|
| 212 |
st.write("""
|
| 213 |
+
### Text Similarity:
|
| 214 |
+
Text Similarity involves measuring the similarity between two pieces of text.
|
| 215 |
+
**Example**: Comparing two sentences to see if they convey the same meaning.
|
| 216 |
+
|
| 217 |
+
**Techniques**:
|
| 218 |
+
- Cosine Similarity
|
| 219 |
+
- Jaccard Similarity
|
| 220 |
+
- Semantic-based methods (e.g., using embeddings like Word2Vec, BERT)
|
| 221 |
""")
|
|
|
|
|
|
|
|
|
|
|
|