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]
__init__(model_name: str = 'bela', device: str = 'cuda', tag: str = 'wikidata')[source]

EntityLinker

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

  • device (str) – device for running model on

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

You can read about bela model at https://github.com/PyThaiNLP/MultiEL.

get_el(list_text: List[str] | str) List[dict] | str[source]

Get Entity Linking from Thai Text

Parameters:

str] (str Union[List[str],) – list of Thai text or text

Returns:

list of entity linking

Return type:

Union[List[dict], str]

Example:

from pythainlp.el import EntityLinker

el = EntityLinker(device="cuda")
print(el.get_el("จ๊อบเคยเป็นซีอีโอบริษัทแอปเปิล"))
# output: [{'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)