์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 |
- Absolute
- AGI
- ai
- AI agents
- AI engineer
- AI researcher
- ajax
- algorithm
- Algorithms
- aliases
- Array ๊ฐ์ฒด
- ASI
- bayes' theorem
- Bit
- Blur
- BOM
- bootstrap
- canva
- challenges
- ChatGPT
- Today
- In Total
A Joyful AI Research Journey๐ณ๐
[8] 241108 Team Project Results: Stock Headline Sentiment Analysis [Goorm All-In-One Pass! AI Project Master - 4th Session, Day 8] ๋ณธ๋ฌธ
[8] 241108 Team Project Results: Stock Headline Sentiment Analysis [Goorm All-In-One Pass! AI Project Master - 4th Session, Day 8]
yjyuwisely 2024. 11. 8. 10:27241108 Fri 8th class
๋ ธ์ ๋ฐํ ์๋ฃ ๋ง๋ค์๋ค!

https://acoustic-hexagon-e6d.notion.site/Streamlit-1361e9b916c3808c8d37e3bf079ea6df
์ฃผ์ ์ ๋ณด ์ ๊ณต ๋ฐ ์๊ฐํ๋ฅผ ์ํ Streamlit ํ์ฉ | Notion
Joyeux (์ฃผ์์ , ํ๋์ค์ด: ์ ์พํ, ํต์พํ) ํ ํ๋ก์ ํธ (๋ฐํ: 2024.11.08)
acoustic-hexagon-e6d.notion.site
์์ง URL, ์คํฌ๋ฆฐ์ท์ ์๋ค.
๊ฐ์ฑ ๋ถ์ Streamlit ๋ฒ์ ์ ๋ง๋ค์๋ค
๋ด์ค ๊ฐ์ ๋ถ์ ๋ฐ ์ด๋ฒคํธ ์ํฅ ํ์
- ๋ด์ค ํค๋๋ผ์ธ ๊ฐ์ ๋ถ์: ์ต๊ทผ ์ฃผ์๊ณผ ๊ด๋ จ๋ ๋ด์ค ๊ธฐ์ฌ๋ ์์ ๋ฏธ๋์ด ๋ฐ์ดํฐ๋ฅผ ์์งํ์ฌ, ๊ฐ์ ๋ถ์์ ํตํด ๊ธ์ ์ , ๋ถ์ ์ , ์ค๋ฆฝ์ ์ธ ์๊ฒฌ์ ๋ถ๋ฅํ ์ ์์ด์. ์ด๋ฅผ ํตํด ์ฌ์ฉ์์๊ฒ ์ต๊ทผ ๋ด์ค๊ฐ ์ฃผ์์ ์ด๋ค ์ํฅ์ ๋ฏธ์น๋์ง ๋ณด์ฌ์ค ์ ์์ต๋๋ค.
๋ฐฐํฌํ ์น์ฌ์ดํธ
https://stock-sentiment-app.streamlit.app/
์ฝ๋)
app.py
import streamlit as st import requests from bs4 import BeautifulSoup from transformers import pipeline import time def get_stock_buy_recommendation(stock_name): """ Fetch news headlines and provide stock buy recommendations """ # Add a spinner while processing with st.spinner(f'๋ถ์ ์ค... {stock_name}์ ๋ํ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋ ์ค์
๋๋ค.'): url = f'https://search.naver.com/search.naver?ie=utf8&sm=nws_hty&query={stock_name}' response = requests.get(url) soup = BeautifulSoup(response.content, 'html.parser') # Extract headlines headlines = [headline.get_text() for headline in soup.find_all('a', class_='news_tit')[:10]] # Initialize sentiment analyzer sentiment_analyzer = pipeline('sentiment-analysis') # Analyze sentiments results = [] positive_count = 0 negative_count = 0 for headline in headlines: sentiment = sentiment_analyzer(headline)[0]['label'] if sentiment == 'POSITIVE': sentiment_emoji = '๐' positive_count += 1 elif sentiment == 'NEGATIVE': sentiment_emoji = '๐ฐ' negative_count += 1 else: sentiment_emoji = '๐' results.append((headline, sentiment_emoji)) # Determine recommendation if positive_count > negative_count: buy_recommendation = f'{stock_name}์(๋ฅผ) ๋งค์ํ์ธ์ ๐' elif positive_count < negative_count: buy_recommendation = f'{stock_name}์(๋ฅผ) ๋งค์ํ์ง ๋ง์ธ์ ๐ฐ' else: buy_recommendation = f'{stock_name}์ ๋ํด ์ค๋ฆฝ์ ์ธ ์
์ฅ์
๋๋ค ๐' return results, buy_recommendation # Set up the Streamlit page st.set_page_config(page_title="์ฃผ์ ํฌ์ ์๊ฒฌ ๋ถ์๊ธฐ", page_icon="๐") # Add title and description st.title("๐ ์ฃผ์ ํฌ์ ์๊ฒฌ ๋ถ์๊ธฐ") st.markdown(""" ์ด ์ฑ์ ๋ค์ด๋ฒ ๋ด์ค ํค๋๋ผ์ธ์ ๋ถ์ํ์ฌ ์ฃผ์ ํฌ์ ์๊ฒฌ์ ์ ๊ณตํฉ๋๋ค. """) # Create input field stock_name = st.text_input("์ข
๋ชฉ๋ช
์ ์
๋ ฅํ์ธ์:", placeholder="์: ์ผ์ฑ์ ์") # Create analyze button if st.button("ํฌ์์๊ฒฌ ๋ถ์"): if stock_name: try: # Get recommendation headline_results, buy_recommendation = get_stock_buy_recommendation(stock_name) # Display results st.subheader(f"{stock_name}์ ๋ํ ๋ถ์ ๊ฒฐ๊ณผ") # Display buy recommendation in a highlighted box st.info(buy_recommendation) # Display headlines in an expandable section with st.expander("๋ด์ค ํค๋๋ผ์ธ ์์ธ ๋ถ์ ๋ณด๊ธฐ"): for headline, emoji in headline_results: st.write(f"{emoji} {headline}") except Exception as e: st.error(f"์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}") else: st.warning("์ข
๋ชฉ๋ช
์ ์
๋ ฅํด์ฃผ์ธ์.") # Add footer st.markdown("---") st.markdown("Made with โค๏ธ using Streamlit")
requirement.txt
streamlit requests beautifulsoup4 transformers torch
cd stock_analyzer pip install -r requirements.txt streamlit run app.py You can now view your Streamlit app in your browser. Local URL: http://localhost:8501
๊ฒฐ๊ณผ)


- ๊ฐ์ฑ ๋ถ์
- ์ฌ์ฉํ ๋ชจ๋ธ: DistilBERT ๊ธฐ๋ฐ ๊ฐ์ ๋ถ์ ๋ชจ๋ธ
- DistilBERT๋ BERT์ ๊ฒฝ๋ํ ๋ฒ์ ์ผ๋ก, ์ฝ 60% ๋ ์๊ณ 2๋ฐฐ ๋น ๋ฅธ ์ฒ๋ฆฌ ์๋๋ฅผ ์๋ํ๋ฉฐ, ์ฑ๋ฅ์ ์๋ BERT์ 97% ์์ค์ ์ ์งํฉ๋๋ค.
- SST-2 ๋ฐ์ดํฐ์ (Stanford Sentiment Treebank 2)์ผ๋ก ๋ฏธ์ธ ์กฐ์ ๋ ๊ฐ์ ๋ถ์ ๋ชจ๋ธ๋ก, **๊ธ์ (positive)**๊ณผ ๋ถ์ (negative) ๊ฐ์ ๋ถ๋ฅ๊ฐ ๊ฐ๋ฅํฉ๋๋ค.
- "base-uncased":
- base: BERT์ ๊ธฐ๋ณธ ํฌ๊ธฐ์ด๋ฉฐ, 12๊ฐ์ Transformer ๋ ์ด์ด์ 110M๊ฐ์ ํ๋ผ๋ฏธํฐ๋ฅผ ๊ฐ์ง๊ณ ์์.
- uncased: ์ ๋ ฅ ํ ์คํธ์์ ๋์๋ฌธ์๋ฅผ ๊ตฌ๋ถํ์ง ์์.
- ์ฃผ์ ํน์ง:
- ์ํ ๋ฆฌ๋ทฐ, ์์ ๋ฏธ๋์ด ๊ฒ์๋ฌผ ๋ฑ์์ ๋น ๋ฅด๊ณ ํจ์จ์ ์ธ ๊ฐ์ ๋ถ์์ ์ํํ ์ ์์.
- ์ง์ ์ฆ๋ฅ(Knowledge Distillation) ๊ธฐ๋ฒ์ ํตํด ๋ชจ๋ธ ํฌ๊ธฐ๋ฅผ ์ค์ด๋ฉด์๋ ์ฑ๋ฅ์ ์ ์งํ์ฌ, ๋ชจ๋ฐ์ผ ๋ฐ ์น ์๋น์ค์ ๊ฐ์ ์ปดํจํ ์์์ด ์ ํ๋ ํ๊ฒฝ์์๋ ํ์ฉ ๊ฐ๋ฅ.
- ๋ชจ๋ธ ์ด๋ฆ: distilbert-base-uncased-finetuned-sst-2-english
- ํ๊ณ: ํ๊ตญ์ด ๋ชจ๋ธ(snunlp/KR-FinBert)์ ์ฌ์ฉํ์ ๋ ๋ชจ๋ ๊ฒฐ๊ณผ๊ฐ ์ค๋ฆฝ(Neutral)์ผ๋ก ๋์์ผ๋ฉฐ, ์์ด ๋ชจ๋ธ๋ณด๋ค ์ฑ๋ฅ์ด ๋จ์ด์ ธ์ DistilBERT ๊ธฐ๋ฐ ๊ฐ์ ๋ถ์ ๋ชจ๋ธ ์ฌ์ฉ**.**
- ์ฌ์ฉํ ๋ชจ๋ธ: DistilBERT ๊ธฐ๋ฐ ๊ฐ์ ๋ถ์ ๋ชจ๋ธ