Skip to main content

spaCy pipeline component for guessing the language of Doc and Span objects.

Project description

# spaCy-CLD: Bringing simple language detection to spaCy

## Installation

`pip install spacy_cld`

## Usage

Adding the spaCy-CLD component to the processing pipeline is relatively simple:

```
import spacy
from spacy_cld import LanguageDetector

nlp = spacy.load('en')
language_detector = LanguageDetector()
nlp.add_pipe(language_detector)
doc = nlp('This is some English text.')

doc._.languages # ['en']
doc._.language_scores['en'] # 0.96
```

spaCy-CLD operates on `Doc` and `Span` spaCy objects. When called on a `Doc` or `Span`, the object is given two attributes: `languages` (a list of up to 3 language codes) and `language_scores` (a dictionary mapping language codes to confidence scores between 0 and 1).

## Under the hood

spacy-cld is a little extension that wraps the [PYCLD2](https://github.com/aboSamoor/pycld2) Python library, which in turn wraps the [Compact Language Detector 2](https://github.com/CLD2Owners/cld2) C library originally built at Google for the Chromium project. CLD2 uses character n-grams as features and a Naive Bayes classifier to identify 80+ languages from Unicode text strings (or XML/HTML). It can detect up to 3 different languages in a given document, and reports a confidence score (reported in with each language.

For additional details, see the linked project pages for PYCLD2 and CLD2.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spacy_cld-0.0.3.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file spacy_cld-0.0.3.tar.gz.

File metadata

  • Download URL: spacy_cld-0.0.3.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for spacy_cld-0.0.3.tar.gz
Algorithm Hash digest
SHA256 0f12d97d943d92095b64835ef51a0f9dd97dd018887b2ebd53330c0febaca7bf
MD5 7f73bc2aa015cb8b2d249b5932818f77
BLAKE2b-256 af7b6304085333b4c9a15ee9c0a6c8ad58e184feefb9cb5fa8dda4e3c48b1cde

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page