File size: 2,682 Bytes
de2b822 154771f de2b822 154771f de2b822 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
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.
""")
# ML Example: Logistic Regression
st.write("### Example: Logistic Regression")
st.write("We'll use logistic regression to classify some sample data.")
model = LogisticRegression()
# (Insert a sample dataset and training procedure here)
# Deep Learning Example: Using Pretrained Transformers
st.write("### Example: Transformer Model for Sentiment Analysis")
# Initialize the NLP pipeline for sentiment analysis
nlp_pipeline = pipeline("sentiment-analysis")
def analyze_sentiment(user_sentence):
response = nlp_pipeline(user_sentence)
return response[0]
# Example usage
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']}")
# Deep Learning Example: Using Pretrained Transformers
#st.write("### Example: Transformer Model")
#nlp = pipeline("sentiment-analysis")
#st.write(nlp("I love machine learning!"))
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/)
""")
|