Skip to main content

Havina is a Python library that can generate knowledge graphs triplets from an input text. Its implementation is based on the paper "Language models are open knowledge graphs" with some tweaks to improve performance. Havina can be used to evaluate the language comprehension of AI models or as a tool to extract triplets from text and build knowledge graphs.

Project description

Havina

Havina is a Python library that can generate knowledge graphs triplets from an input text. Its implementation is based on the paper "Language models are open knowledge graphs" with some tweaks to improve performance. Most notably, instead of summing the attention scores of each word in a relation, I am calculating their average.

The reasoning behind this change is that a simple sum of scores favors longer relations even if the extra words do not carry any relevant meaning.

Havina can be used to evaluate the language comprehension of AI models or as a tool to extract triplets from text and build knowledge graphs.

How to use it

Run pip install havina to install the library. Then, after importing the GraphGenerator class from havina, simply call the object with the sentence to evaluate and an optional number of workers. Each worker will span a different process and the algorithm will split the work between them.

from havina import GraphGenerator

text = 'John Lennon is a famous singer.'
generator = GraphGenerator(
    top_k=4,
    contiguous_token=False
)

triplets = generator(text, workers=1)
print(triplets)

The code above will print the following:

[
    HeadTailRelations(
        head=Entity(text='john lennon', wikidata_id=None), 
        tail=Entity(text='a famous singer', wikidata_id=None), 
        relations=['be'])
]

The returned type is a list of HeadTailReations objects, each of which contains the head and tail entities and the possible relations between them. Relations are Python strings.

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

havina-0.1.3.tar.gz (158.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

havina-0.1.3-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file havina-0.1.3.tar.gz.

File metadata

  • Download URL: havina-0.1.3.tar.gz
  • Upload date:
  • Size: 158.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for havina-0.1.3.tar.gz
Algorithm Hash digest
SHA256 590b8d91eee3f1ed69d12b9d4372b3c2d42117b455b46218a250b0a7ab71e7ff
MD5 6f48689368bb850b74e4588e174a3dfa
BLAKE2b-256 8707bf3156b3a9a3d77f23a56c761a626f6b892ae6b47e1c2a499f46c19e6204

See more details on using hashes here.

File details

Details for the file havina-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: havina-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for havina-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 54dfdcec37631a7574658762d9cabbd9a17c9ad9cd96868acb1d9520d5495a51
MD5 8ba209a0834d0ad9a68f113eadce7a17
BLAKE2b-256 9f6ce3bad1dd2e280014c453211f2194c516ea0f5aaccda316f5a6314dfa7ff9

See more details on using hashes here.

Supported by

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