Last active
April 13, 2021 08:18
-
-
Save kristjan-eljand/b1386931fd328273331dd87f9860582c to your computer and use it in GitHub Desktop.
Sentiment analysis from Estonian to English using Huggingface transformers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1. Create sentiment classifier with pipeline function | |
# and the name of the task | |
classifier = pipeline('sentiment-analysis') | |
# 2. Translate the text from input language to English | |
input_to_translate = "Tahtsime parimat, aga välja kukkus nagu alati" | |
translated_input = translate(input_to_translate)[0]['translation_text'] | |
# 3. Using the sentiment classifier is oneliner | |
result = classifier(translated_input)[0] | |
print(translated_input) | |
print(f"label: {result['label']}, with score: {round(result['score'], 4)}") | |
# Output: | |
# We wanted the best, but it turned out the way it always did. | |
# label: NEGATIVE, with score: 0.9622 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment