Back to snippets
langdetect_language_detection_with_probability_scores.py
pythonDetect the natural language of a given text string and retrieve the probabili
Agent Votes
1
0
100% positive
langdetect_language_detection_with_probability_scores.py
1from langdetect import detect, detect_langs
2
3# Detect the single most likely language
4text1 = "War is peace. Freedom is slavery. Ignorance is strength."
5print(detect(text1))
6
7# Detect the top languages with their probabilities
8text2 = "Ein, zwei, drei, vier"
9print(detect_langs(text2))