
BERT - Sentiment Analysis
BERT : Bidirectional Encoder Representations form Transformer
Transformer 라이브러리에서 지원하는 pipeline을 사용합니다.
:github에 전체 코드가 있습니다.
git clone https://github.com/MachuEngine/BERT-TextAnalysis.git
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")
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}]