BERT - Sentiment Analysis

Ann Jongmin·2025년 3월 14일

BERT

목록 보기
1/6
post-thumbnail

BERT - Sentiment Analysis

BERT : Bidirectional Encoder Representations form Transformer

Transformer 라이브러리에서 지원하는 pipeline을 사용합니다.


Github

:github에 전체 코드가 있습니다.

git clone https://github.com/MachuEngine/BERT-TextAnalysis.git

BERT 감정 분석

def sentiment_pipeline():
    """
        감정 분석 파이프라인 데모
        - NLPTown/bert-base-multilingual-uncased-sentiment 모델 사용
    """
    sentiment_analyzer = pipeline(
        "sentiment-analysis",
        model="nlptown/bert-base-multilingual-uncased-sentiment"
    )
    examples = [
        "This movie was really fun!",
        "It was worse than I expected. Waste of money.",
        "Wow... It was amazing. I'd like to watch it twice."
    ]
    for text in examples:
        result = sentiment_analyzer(text)
        print(f"Text: {text}")
        print(f"Result: {result}\n")

분류 결과

  • 위에서 3개의 영화 리뷰 글에 대해 부정(label: 1), 긍정(label: 5)인지 분석
Result: [{'label': '5 stars', 'score': 0.645542323589325}]

Text: It was worse than I expected. Waste of money.
Result: [{'label': '1 star', 'score': 0.7579275369644165}]

Text: Wow... It was amazing. I'd like to watch it twice.
Result: [{'label': '5 stars', 'score': 0.8495228886604309}]
profile
AI Study

0개의 댓글