Skip to main content

PyThaiNLP For spaCy

Project description

spaCy-PyThaiNLP

This package wraps the PyThaiNLP library to add support Thai for spaCy.

Support List

  • Word segmentation
  • Part-of-speech
  • Named entity recognition
  • Sentence segmentation
  • Dependency parsing
  • Word vector

Install

pip install spacy-pythainlp

How to use

Example

import spacy
import spacy_pythainlp.core

nlp = spacy.blank("th")
# Segment the Doc into sentences
nlp.add_pipe(
   "pythainlp", 
)

data=nlp("ผมเป็นคนไทย   แต่มะลิอยากไปโรงเรียนส่วนผมจะไปไหน  ผมอยากไปเที่ยว")
print(list(list(data.sents)))
# output: [ผมเป็นคนไทย   แต่มะลิอยากไปโรงเรียนส่วนผมจะไปไหน  , ผมอยากไปเที่ยว]

You can config the setting in the nlp.add_pipe.

nlp.add_pipe(
    "pythainlp", 
    config={
        "pos_engine": "perceptron",
        "pos": True,
        "pos_corpus": "orchid_ud",
        "sent_engine": "crfcut",
        "sent": True,
        "ner_engine": "thainer",
        "ner": True,
        "tokenize_engine": "newmm",
        "tokenize": False,
        "dependency_parsing": False,
        "dependency_parsing_engine": "esupar",
        "dependency_parsing_model": None,
        "word_vector": True,
        "word_vector_model": "thai2fit_wv"
    }
)
  • tokenize: Bool (True or False) to change the word tokenize. (the default spaCy is newmm of PyThaiNLP)
  • tokenize_engine: The tokenize engine. You can read more: Options for engine
  • sent: Bool (True or False) to turn on the sentence tokenizer.
  • sent_engine: The sentence tokenizer engine. You can read more: Options for engine
  • pos: Bool (True or False) to turn on the part-of-speech.
  • pos_engine: The part-of-speech engine. You can read more: Options for engine
  • ner: Bool (True or False) to turn on the NER.
  • ner_engine: The NER engine. You can read more: Options for engine
  • dependency_parsing: Bool (True or False) to turn on the Dependency parsing.
  • dependency_parsing_engine: The Dependency parsing engine. You can read more: Options for engine
  • dependency_parsing_model: The Dependency parsing model. You can read more: Options for model
  • word_vector: Bool (True or False) to turn on the word vector.
  • word_vector_model: The word vector model. You can read more: Options for model

Note: If you turn on Dependency parsing, word segmentation and sentence segmentation are turn off to use word segmentation and sentence segmentation from Dependency parsing.

License

   Copyright 2016-2023 PyThaiNLP Project

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

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-pythainlp-0.1.tar.gz (8.5 kB view hashes)

Uploaded Source

Built Distribution

spacy_pythainlp-0.1-py3-none-any.whl (9.1 kB view hashes)

Uploaded Python 3

Supported by

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