Skip to content

Instantly share code, notes, and snippets.

@khuyentran1401
Last active September 20, 2020 13:10
Show Gist options
  • Select an option

  • Save khuyentran1401/c458dc52450625783f46134641c00b23 to your computer and use it in GitHub Desktop.

Select an option

Save khuyentran1401/c458dc52450625783f46134641c00b23 to your computer and use it in GitHub Desktop.
Detect whether a text is English
import spacy
from spacy_langdetect import LanguageDetector
def is_english(text: str) -> bool:
'''Detect whether a text is English
Return True of the text is in English'''
nlp = spacy.load('en')
nlp.add_pipe(LanguageDetector(), name='language_detector', last=True)
return nlp(text)._.language['language'] == 'en'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment