Skip to content

Instantly share code, notes, and snippets.

@kristjan-eljand
Last active April 13, 2021 08:18
Show Gist options
  • Save kristjan-eljand/b1386931fd328273331dd87f9860582c to your computer and use it in GitHub Desktop.
Save kristjan-eljand/b1386931fd328273331dd87f9860582c to your computer and use it in GitHub Desktop.
Sentiment analysis from Estonian to English using Huggingface transformers
# 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