pythainlp.el

The pythainlp.el module is an essential component of Thai Entity Linking within the PyThaiNLP library. Entity Linking is a key natural language processing task that associates mentions in text with corresponding entities in a knowledge base.

class pythainlp.el.EntityLinker(model_name: str = 'bela', device: str = 'cuda', tag: str = 'wikidata')[source]

Link entities in Thai text to a knowledge base.

__init__(model_name: str = 'bela', device: str = 'cuda', tag: str = 'wikidata') → None[source]

Initialize the entity linker.

Parameters:
  • model_name (str) – model name (bela)

  • device (str) – device to run the model on

  • tag (str) – entity linking tag (wikidata)

Raises:

NotImplementedError – if the model name or tag is not supported

For more information about the bela model, see MultiEL.

get_el(list_text: list[str] | str) → list[dict[str, Any]] | str[source]

Link entities in Thai text.

Parameters:

list_text (Union[list[str], str]) – Thai text, or list of Thai texts, to be linked

Returns:

list of entity linking results

Return type:

Union[list[dict[str, Any]], str]

Example:
>>>     from pythainlp.el import EntityLinker
>>>     el = EntityLinker(device="cuda")
>>>     print(el.get_el("จ๊อบเคยเป็นซีอีโอบริษัทแอปเปิล"))
    [{'offsets': [11, 23],
    'lengths': [6, 7],
    'entities': ['Q484876', 'Q312'],
    'md_scores': [0.30301809310913086, 0.6399497389793396],
    'el_scores': [0.7142490744590759, 0.8657019734382629]}]

EntityLinker

The EntityLinker class is the core component of the pythainlp.el module, responsible for Thai Entity Linking. Entity Linking, also known as Named Entity Linking (NEL), plays a critical role in various applications, including question answering, information retrieval, and knowledge graph construction.

Example

Here’s a simple example of how to use the EntityLinker class:

::

from pythainlp.el import EntityLinker

text = “กรุงเทพเป็นเมืองหลวงของประเทศไทย” el = EntityLinker() linked_entities = el.get_el(text) print(linked_entities)