|
import streamlit as st |
|
from sklearn.linear_model import LogisticRegression |
|
import torch |
|
from transformers import pipeline |
|
|
|
|
|
def run(): |
|
st.title("7. Machine Learning, Deep Learning & Transformers") |
|
st.write("## Overview") |
|
st.write("Learn about different machine learning models, deep learning models, and transformers.") |
|
|
|
st.write("## Key Concepts & Explanations") |
|
st.markdown(""" |
|
- **Machine Learning Models**: Supervised, unsupervised, and reinforcement learning. |
|
- **Deep Learning**: Neural networks with many layers, used for complex tasks like image recognition. |
|
- **Transformers**: A powerful model architecture used in natural language processing (NLP) tasks. |
|
""") |
|
|
|
|
|
st.write("### Example: Logistic Regression") |
|
st.write("We'll use logistic regression to classify some sample data.") |
|
model = LogisticRegression() |
|
|
|
|
|
|
|
|
|
st.write("### Example: Transformer Model for Sentiment Analysis") |
|
|
|
|
|
nlp_pipeline = pipeline("sentiment-analysis") |
|
|
|
def analyze_sentiment(user_sentence): |
|
response = nlp_pipeline(user_sentence) |
|
return response[0] |
|
|
|
|
|
user_sentence = st.text_input("Enter a sentence for sentiment analysis:") |
|
if user_sentence: |
|
response = analyze_sentiment(user_sentence) |
|
st.write(f"Sentiment: {response['label']}, Score: {response['score']}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
st.write("## Quiz: Conceptual Questions") |
|
q1 = st.radio("What is a transformer model used for?", ["Text classification", "Image processing", "Time series analysis"]) |
|
if q1 == "Text classification": |
|
st.success("β
Correct!") |
|
else: |
|
st.error("β Incorrect.") |
|
|
|
st.write("## Code-Based Quiz") |
|
code_input = st.text_area("Write code to create a simple neural network using PyTorch", value="import torch\nimport torch.nn as nn\nclass SimpleNN(nn.Module):\n def __init__(self):\n super(SimpleNN, self).__init__()") |
|
if "super(SimpleNN" in code_input: |
|
st.success("β
Correct!") |
|
else: |
|
st.error("β Try again.") |
|
|
|
st.write("## Learning Resources") |
|
st.markdown(""" |
|
- π [Deep Learning with PyTorch](https://pytorch.org/tutorials/) |
|
- π [Transformers Library Documentation](https://huggingface.co/docs/transformers/) |
|
""") |
|
|