๐ Llama3-news-analysis
This repository contains a model that analyzes given news texts and performs the following tasks: summarization, sentiment analysis, stock code identification, and advertisement detection.
๐ Quick Start
This model analyzes the given news text and performs the following tasks:
- Summarization: Summarize the main content of the news article into 1 - 3 lines.
- Sentiment Analysis: Evaluate the sentiment of the article as positive, negative, or neutral.
- Stock Code Identification: Extract the relevant stock codes based on the mentioned company names.
- Advertisement Detection: Determine whether the text is an advertisement.
โจ Features
The model is trained based on Llama - 3.2 - 3B from meta - llama and uses the transformers
library from Hugging Face.
- Model:
irene93/Llama3-news-analysis
- Tokenizer:
AutoTokenizer
- Model Architecture:
AutoModelForCausalLM
๐ฆ Installation
First, set up the environment:
pip install torch transformers
๐ป Usage Examples
Basic Usage
The following is an example code for analyzing a news article using the model:
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('irene93/Llama3-news-analysis')
model = AutoModelForCausalLM.from_pretrained('irene93/Llama3-news-analysis')
model = torch.nn.DataParallel(model).cuda()
device = "cuda:0"
user_content = """ํํ์์ด๋ก์คํ์ด์ค๊ฐ โ๋ฐ๋ ๋ก๋ณดํฑ์คโ์ ์ธ๊ณ ์ต๊ณ ์ ๋ฌด์ธ์ฐจ๋ ๊ฐ๋ฐ์ ๋์ ๋ค.
ํํ์์ด๋ก์คํ์ด์ค๋ 19์ผ ์ ๋ฝ ์ต๋์ ๋ฌด์ธ์ฐจ๋(UGV) ๊ธฐ์
์ธ ๋ฐ๋ ๋ก๋ณดํฑ์ค์ โIDEX 2025โ์์ ์ต์ ๊ถค๋ํ UGV์ธ T - RCV(Tracked - Robotic Combat Vehicle)์ ๊ณต๋๊ฐ๋ฐ ๋ฐ ๊ธ๋ก๋ฒ์์ฅ ๊ณต๋ต์ ์ํ ์ ๋ต์ ํํธ๋์ญ์ ํ๋ํ๋ค๋ ๋ด์ฉ์ ์ํด๊ฐ์๋ฅผ ์ฒด๊ฒฐํ๋ค๊ณ ๋ฐํ๋ค.
์์คํ ๋์์ โ๋ฐ๋ ๋ก๋ณดํฑ์คโ๋ ๋ฏธ๊ตญ, ์๊ตญ, ํ๋์ค ๋ฑ ๋ถ๋์์์กฐ์ฝ๊ธฐ๊ตฌ(NATO) 8๊ฐ๊ตญ์ ํฌํจํ ์ด 16๊ฐ๊ตญ์ ๊ถค๋ํ UGV๋ฅผ ๊ณต๊ธํ๋ ๋ฑ ๊ธ๋ก๋ฒ UGV์ ํ์คํ๋ฅผ ์ฃผ๋ํ๋ ์ธ๊ณ ์ต๊ณ ์์ค์ ๊ธฐ์ ์ ๋ณด์ ํ๊ณ ์๋ค.
ํํ์์ด๋ก์คํ์ด์ค๋ ์ฐจ๋ฅํ UGV โ์๋ฆฌ์จ์ค๋ฉงโ์ ํตํด ๋ฏธ๊ตฐ์ใ
ํด์ธ๋น๊ต์ฑ๋ฅ์ํ(FCT)์ ์ฑ๊ณต์ ์ผ๋ก ์ํํ๊ณ , ์ฐจ์ธ๋ UGV์ธ โ๊ทธ๋ฐํธ(GRUNT)โ๋ฅผ ์์ฒด ๊ฐ๋ฐํ๋ ๋ฑ ๊ธ๋ก๋ฒ ์์ฅ์์ ๊ธฐ์ ๋ ฅ์ ์ธ์ ๋ฐ์ผ๋ฉด์ ์ฌํด ํ๊ตญ ์ก๊ตฐ์ ๋ค๋ชฉ์ ๋ฌด์ธ์ฐจ๋ ๊ตฌ๋งค์ฌ์
์ ์ ์ ์ ์๋๊ณ ์๋ค.
ํํ์์ด๋ก์คํ์ด์ค ์ธก์ โ์์ฌ ํ๋ ฅ์ ๋ฐํ์ผ๋ก ๊ตญ๋ด์ธ ๊ณ ๊ฐ๋ค์๊ฒ ๋น ๋ฅด๊ฒ ๋ณํํ๋ ํ๋ ์ ํฌ ํ๊ฒฝ์ ๋์ํ ์๋ก์ด ๋์์ ์ ์ํ๊ฒ ๋คโ๊ณ ํ๋ค.
๋ฐ๋ ๋ก๋ณดํฑ์ค ์ธก๋ โ์์ฌ์ ํ์ ์ ์ธ ๊ธฐ์ ๊ณผ ํ๋ถํ ๊ธ๋ก๋ฒ ์์ฅ ๊ฒฝํ์ ๋ฐํ์ผ๋ก ์ต์ฒจ๋จ ๋ฌด์ธํ ์๋ฃจ์
๊ฐ๋ฐ์ ์ต์ ์ ๋คํ๊ฒ ๋คโ๊ณ ๋งํ๋ค."""
messages = [
{"role": "system", "content": "๋น์ ์ ์ฃผ์ด์ง ๋ด์ค๋ฅผ ๋ถ์ํ๋ ์ฑ๋ด์
๋๋ค. **์ง์์ฌํญ**:- ์ฃผ์ด์ง ๋ด์ค์ ๋ํ์ฌ summary, advr, stk_code, sent_score ๋ถ์ํ๊ณ json ํํ๋ก ์ถ๋ ฅํ์ธ์. - summary๋ 1~3์ค ์ฌ์ด๋ก ์์ฑํฉ๋๋ค.- advr๋ ํด๋น ๋ณธ๋ฌธ์ด ๊ด๊ณ ๋ฉด 1 ๊ด๊ณ ๊ฐ ์๋๊ฒฝ์ฐ์ 0 ์ผ๋ก ์ ์ 1๊ฐ์ ๊ฐ์ผ๋ก ์ถ๋ ฅํ์ธ์.- stk_code๋ ํด๋น ๋ณธ๋ฌธ์์ ์ธ๊ธ๋ ์ข
๋ชฉ๋ช
์ ์ฐพ๊ณ , ๊ทธ ์ข
๋ชฉ๋ช
์ ์ข
๋ชฉ ์ฝ๋๋ฅผ ์ฐพ์ ํ์ด์ฌ ๋ฆฌ์คํธ ํํ๋ก ์์ฑํ์ธ์. - sent_score๋ ํด๋น ๋ณธ๋ฌธ์ด ๊ธ์ ์ ์ผ๊ฒฝ์ฐ 1 ๋ถ์ ์ ์ผ๊ฒฝ์ฐ -1 , ๊ธ์ ์ ์ด์ง๋ ๋ถ์ :์ ์ด์ง๋ ์์๊ฒฝ์ฐ 0 ์ผ๋ก ์ ์ 1๊ฐ์ ๊ฐ์ ์ถ๋ ฅํ์ธ์ - ๋ณธ๋ฌธ: ์ด ์ฃผ์ด์ง๋ฉด ๊ฒฐ๊ณผ: ๋ค์์ json ํํ๋ก ์์ฑํ์ธ์"},
{"role": "user", "content": user_content}
]
input_ids = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt"
).to(device)
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>")
]
outputs = model.module.generate(
input_ids,
max_new_tokens=2048,
eos_token_id=terminators,
do_sample=False,
)
response = outputs[0][input_ids.shape[-1]:]
print(tokenizer.decode(response, skip_special_tokens=True))
Example Output
{
'summary': 'ํํ์์ด๋ก์คํ์ด์ค๊ฐ ๋ฐ๋ ๋ก๋ณดํฑ์ค์ ํ๋ ฅํด ๋ฌด์ธ์ฐจ๋ ๊ฐ๋ฐ์ ๋์ฐ์ต๋๋ค.',
'advr_tp': '0',
'stk_code': ['012450'],
'sent_score': 1
}
๐ Documentation
Requirements
๐ License
This project is under the MIT License.